Pen Settings

HTML

CSS

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

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

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.

HTML

              
                <div class="layout-three-quarter">
  <side-bar data-expanded="false">
    <div class="menu">
      <ul>
        <li>Projects</li>
        <li>People</li>
        <li>Settings</li>
      </ul>
    </div>
    <button class="expander" title="Show menu" data-expander="1">
      =
      =
      =
    </button>
  </side-bar>
  <section class="content">
    application content goes here
  </section>
</div>
              
            
!

CSS

              
                :root {
  /* I really like using CSS custom properties for layout configration.
     It replaces all the magic numbers and you can use calc() to make
     perfect grids
  */
  --sidebar-width: 250px;
  --space: 8px;

  /* Separate our palette from use cases. 
     Makes restyling simpler in the future, and helps build design language on your team.
     Having variables for colors also makes adding alternate palettes and themes very easy
     as you can redefine the variables with more specific selectors to retheme almost everything.
  */
  --color-gray-100: #f0ecea;
  --color-bg-low: var(--color-gray-100);
}

.layout-three-quarter {
  height: 100%;
  padding-left: var(--sidebar-width);
}

side-bar,
.content {
  /* Math in CSS replaces a bunch of scenarios I would use sass for */
  padding-bottom: calc(var(--space) * 5);
}

side-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 100%;
  width: var(--sidebar-width);

  padding-top: calc(var(--space) * 3);
  background: var(--color-bg-low);
  transition: left 0.26s ease-in-out;
}
.content {
  padding-top: calc(var(--space) * 5);
  padding-right: calc(var(--space) * 5);
  padding-left: calc(var(--space) * 5);
}
.menu {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: calc(var(--space) * 3);
  padding-left: calc(var(--space) * 5);

  height: 100%;
  overflow-y: auto;
}
.expander {
  display: none;
}

:root {
  --z-active-ui: 100;
  --color-darken: #333;
}
@media (max-width: 600px) {
  .layout-three-quarter {
    padding-left: 10px;
  }

  .content {
    padding-top: calc(var(--space) * 3);
    padding-left: calc(var(--space) * 4);
    padding-right: calc(var(--space) * 2);
  }

  side-bar {
    transition: transform 0.25s ease-in;
    transform: translateX(calc(var(--sidebar-width) * -1 + 10px));
    z-index: var(--z-active-ui);
  }

  .expander {
    cursor: pointer;
    display: block;
    justify-content: center;
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 10px;
    height: 100%;

    background: var(--color-bg-low);
    padding: 0;
    border: none;
    border-radius: 0;
  }

  .expander:focus,
  .expander:hover {
    box-shadow: none;
    background: color-mix(
      in srgb,
      var(--color-bg-low),
      var(--color-darken) 20%
    );
  }
  side-bar[data-expanded="true"] {
    transform: translateX(0px);
  }
}

              
            
!

JS

              
                class SideBar extends HTMLElement {
  connectedCallback() {
    const button = this.querySelector("[data-expander]");
    if (!button) {
      console.error("Could not find expander for side-bar");
      return;
    }
    const sidebar = this;
    button.addEventListener("click", function (evt) {
      evt.preventDefault();
      const current = sidebar.dataset.expanded;
      sidebar.dataset.expanded = current === "false" ? "true" : "false";
    });
  }
}

customElements.define("side-bar", SideBar);

              
            
!
999px

Console