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>
  <ul role="tablist">
    <li role="presentation">
      <a href="#section1" role="tab" id="tab1" aria-selected="true">Section 1</a>
    </li>
    <li role="presentation">
      <a href="#section2" role="tab" id="tab2" tabindex="-1">Section 2</a>
    </li>
    <li role="presentation">
      <a href="#section3" role="tab" id="tab3" tabindex="-1">Section 3</a>
    </li>
  </ul>
  <section id="section1" role="tabpanel" aria-labelledby="tab1" aria-hidden="false" tabindex="-1">
    <h2>Section 1</h2>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas dui nibh, fermentum ac gravida quis, <a href="#">tempus sit</a> amet nulla. Fusce dignissim dolor sit amet sapien auctor, eu vehicula elit placerat. Aliquam vehicula luctus enim, at ullamcorper risus. Aliquam ut tincidunt ipsum. Vivamus dui mi, suscipit vitae libero id, interdum aliquet metus.</p>
  </section>
  <section id="section2" role="tabpanel" aria-labelledby="tab2" aria-hidden="true" tabindex="-1" hidden>
    <h2>Section 2</h2>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas dui nibh, fermentum ac gravida quis, <a href="#">tempus sit</a> amet nulla. Fusce dignissim dolor sit amet sapien auctor, eu vehicula elit placerat. Aliquam vehicula luctus enim, at ullamcorper risus. Aliquam ut tincidunt ipsum. Vivamus dui mi, suscipit vitae libero id, interdum aliquet metus.</p>
  </section>
  <section id="section3" role="tabpanel" aria-labelledby="tab3" aria-hidden="true" tabindex="-1" hidden>
    <h2>Section 3</h2>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas dui nibh, fermentum ac gravida quis, <a href="#">tempus sit</a> amet nulla. Fusce dignissim dolor sit amet sapien auctor, eu vehicula elit placerat. Aliquam vehicula luctus enim, at ullamcorper risus. Aliquam ut tincidunt ipsum. Vivamus dui mi, suscipit vitae libero id, interdum aliquet metus.</p>
  </section>
</main>
              
            
!

CSS

              
                body {
  font-family: Roboto,"Helvetica Neue",Arial,sans-serif;
}
main {
  max-width: 35rem;
  margin: 1rem auto;
}
[role="tablist"] {
  padding: 0;
  margin: 0;
}
[role="tablist"] li, [role="tablist"] a {
  display: inline-block;
}
[role="tablist"] a {
  padding: 0.5rem;
  text-decoration: none;
}
[role="tablist"] [aria-selected] {
  border: 2px solid black;
}
[role="tabpanel"] {
    border: 2px solid;
    padding: 1.5rem;
}
              
            
!

JS

              
                const tablist = document.querySelector("ul[role='tablist']");
const tabs = Array.from(tablist.querySelectorAll("a"));
const panels = document.querySelectorAll("section[role='tabpanel']");

const LEFT_ARROW = 37;
const RIGHT_ARROW = 39;
const DOWN_ARROW = 40;

tabs.forEach(function (tab, i) {
  tab.addEventListener("click", (e) => {
    e.preventDefault();
    let currentTab = tablist.querySelector("[aria-selected]");
    if (e.currentTarget !== currentTab) {
      switchTab(currentTab, e.currentTarget);
    }
  });

  tab.addEventListener("keydown", (e) => {
    const index = tabs.indexOf(e.currentTarget);

    if (e.keyCode === DOWN_ARROW) {
      e.preventDefault();
      panels[i].focus();
    }

    if (e.keyCode === LEFT_ARROW) {
      e.preventDefault();
      if (tabs[index - 1]) {
        switchTab(e.currentTarget, tabs[index - 1]);
      }
    }

    if (e.keyCode === RIGHT_ARROW) {
      e.preventDefault();
      if (tabs[index + 1]) {
        switchTab(e.currentTarget, tabs[index + 1]);
      }
    }
  });
});

const switchTab = (oldTab, newTab) => {
  newTab.focus();
  newTab.removeAttribute("tabindex");
  newTab.setAttribute("aria-selected", "true");

  oldTab.removeAttribute("aria-selected");
  oldTab.setAttribute("tabindex", "-1");

  panels[tabs.indexOf(oldTab)].hidden = true;
  panels[tabs.indexOf(newTab)].hidden = false;
};

              
            
!
999px

Console