Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="app"></div>
              
            
!

CSS

              
                .modal-overlay {
  height: 100vh;
  width: 100vw;
  position: fixed;
  overflow: hidden;
  z-index: 99998;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0,0,0,0.8);
}

.modal {
  height: 200px;
  width: 400px;
  position: absolute;
  z-index: 99999;
  top: 50%;
  left: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  transform: translate(-50%, -50%);
  border: 1px solid black;
  background-color: #fffff0;
}

              
            
!

JS

              
                class Modal extends React.Component {
  onClose = e => {
    this.props.onClose && this.props.onClose(e);
  };
    render() {
        //if show is set to false, don't render
        if (!this.props.show) {
            return null;
        }
        return (
          <div class="modal-overlay">
             <div class="modal">
                <h3>{this.props.title}</h3>
                <div>{this.props.children}</div>
            <button onClick={this.onClose}>
            close
          </button>
            </div>
            </div>
        );
    }
}
//create trigger
class Toggle extends React.Component {
    //set state 
    state = {
        show: false
    };
    //define toggle function
    toggleModal = e => {
        //when ran, this will just change the value to the opposite.
        this.setState({
            show: !this.state.show
        })
    }
    render() {
        return (
            <div>
                <a href="#" onClick={this.toggleModal}>Click Me!</a>
                <Modal onClose={this.toggleModal} show={this.state.show} title="Dynamic Modal">
                  <p>This is the body text for the modal</p>
                </Modal>
            </div>
        )
    }
}
//render trigger on webpage
ReactDOM.render(
  <Toggle />,
  document.getElementById('app')
);
              
            
!
999px

Console