Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource


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


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.


Auto Save

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.


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


                html {
  background: #ccc;
  font: normal 100%/1.4 system-ui, sans-serif;

h1 {
  line-height: 1;

.app {
  background: #fff;
  overflow: hidden;
  padding: 20px;

.c-modal {
  height: 100vh;
  left: 0;
  position: absolute;
  top: 0;
  width: 100vw;
  z-index: 2;

  &__veil {
    background: rgba(black, 0.4);
    height: 100%;
    width: 100%;
    z-index: 0;

  &__box {
    background: #fff;
    box-shadow: 0 0 10px rgba(black, 0.4);
    left: 50%;
    padding: 20px;
    position: absolute;
    text-align: center;
    transform: translate3d(-50%, -50%, 0);
    top: 50%;
    width: 250px;
    z-index: 1;

  &__close {
    background: nonel;
    border: 0;
    position: absolute;
    right: 20px;
    top: 20px;



                // These two containers are siblings in the DOM
const appEl = document.getElementById('app');
const modalEl = document.getElementById('modal');

class Modal extends React.Component {
  constructor(props) {
    this.el = document.createElement('div');

  componentDidMount() {
    // Append the element into the DOM on mount.

  componentWillUnmount() {
  render() {
    const { children, handleClose } = this.props;
    return ReactDOM.createPortal(
      <div className="c-modal">
        <div className="c-modal__veil" onClick={handleClose} />
          <button className="c-modal__close" onClick={handleClose}>X</button>

class App extends React.Component {
  constructor(props) {
    this.state = {
      counter: 0,
      showModal: false

  handleShow() {
    this.setState({showModal: true});
  handleHide() {
    this.setState({showModal: false});
  increment(e) {
    if ( === 'BUTTON') {
      this.setState(prevState => ({
        counter: prevState.counter + 1

  render() {
    const { counter } = this.state;
    const { members } = this.props;
    const modal = this.state.showModal ? (
      <Modal handleClose={() => this.handleHide()}>
          <h1>Thanks for clicking!</h1>
          <p>This is being rendered inside the #modal div for {counter} {members}.</p>
    ) : null;

    return (
      <div className="app">
        <h1>My website</h1>
        <p>Welcome to my website {counter} {members}!</p>
        <button onClick={() => this.handleShow()}>Show modal</button>
        <div onClick={(e) => this.increment(e)}>

ReactDOM.render(<App members="Lifeworkers" />, appEl);