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

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

              
                <main>
  <div class="container">
    <hgroup>
      <h1>Tabs Example</h1>
      <h2>Works without the Javascript – it only sets an active class</h2>
    </hgroup>
    <nav role="tab-control">
      <ul>
        <li><label for="tab1">Tab 1</label></li>
        <li><label for="tab2">Tab 2</label></li>
        <li><label for="tab3">Tab 3</label></li>
      </ul>
    </nav>
    <div role="tabs">
      <section>
        <input hidden="hidden" type="radio" name="tabs" id="tab1" checked="checked" />
        <figure>
          <blockquote>
            "When you're new to something, you bring an ignorance that can
            be highly innovative."
            <footer>
              <cite>– Rick Rubin</cite>
            </footer>
          </blockquote>
        </figure>

        <input hidden="hidden" type="radio" name="tabs" id="tab2" />

        <figure>
          <blockquote>
            "Nothing beats a simple worldview. When we know who is the bad
            guy, the day has structure."
            <footer>
              <cite>– Volker Pispers</cite>
            </footer>
          </blockquote>
        </figure>

        <input hidden="hidden" type="radio" name="tabs" id="tab3" />

        <figure>
          <blockquote>
            "Ignorance is not bliss. Ignorance is poverty. Ignorance is devastation.
            Ignorance is tragedy. And ignorance is illness. It all stems from ignorance."
            <footer>
              <cite>– Jim Rohn</cite>
            </footer>
          </blockquote>
        </figure>
      </section>
    </div>
  </div>
</main>
              
            
!

CSS

              
                [role="tabs"] {
  display: flex;
}

[role="tabs"] section {
  display: flex;
  flex-wrap: wrap;
  width: 100%;
}

[role="tabs"] figure {
  flex-grow: 1;
  width: 100%;
  height: 100%;
  display: none;
}

[role="tabs"] [type="radio"]:checked + figure {
  display: block;
}

nav[role="tab-control"] label.active {
  color: var(--primary);
  cursor: pointer;
}

              
            
!

JS

              
                const nodeList = document.querySelectorAll('nav[role="tab-control"] label');
const eventListenerCallback = setActiveState.bind(null, nodeList);

nodeList[0].classList.add('active'); /** add active class to first node  */

nodeList.forEach((node) => {
  node.addEventListener("click", eventListenerCallback); /** add click event listener to all nodes */
});

/** the click handler */
function setActiveState(nodeList, event) {
  nodeList.forEach((node) => {
    node.classList.remove("active"); /** remove active class from all nodes */
  });
  event.target.classList.add("active"); /* set active class on current node */
}

              
            
!
999px

Console