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.


                <html lang="en">

  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="preconnect" href="">
  <link rel="preconnect" href="" crossorigin>
  <link href=";700&display=swap" rel="stylesheet">

  <title>JavaScript Tabs</title>

  <div class="tabs">
    <div role="tablist">
      <button id="tab-1" aria-selected="true" aria-controls="tab-panel-1" role="tab" type="button" tabindex="0">
        Tab 1
      <button id="tab-2" aria-selected="false" aria-controls="tab-panel-2" role="tab" type="button" tabindex="-1">
        Tab 2
      <button id="tab-3" aria-selected="false" aria-controls="tab-panel-3" role="tab" type="button" tabindex="-1">
        Tab 3
    <div id="tab-panel-1" aria-labelledby="tab-1" role="tabpanel" tabindex="0">
      Tab 1 content
    <div id="tab-panel-2" aria-labelledby="tab-2" role="tabpanel" tabindex="-1" hidden>
      Tab 2 content
    <div id="tab-panel-3" aria-labelledby="tab-3" role="tabpanel" tabindex="-1" hidden>
      Tab 3 content



                body {
  font-family: "Poppins", sans-serif;

.tabs {
  max-width: 500px;
  min-height: 300px;
  border: 1px solid #ececec;
  border-radius: 0.5rem;
  box-shadow: rgba(0, 0, 0, 0.1) 0px 4px 6px -1px,
    rgba(0, 0, 0, 0.06) 0px 2px 4px -1px;

div[role="tablist"] {
  display: flex;
  gap: 0.25rem;
  background-color: #d1d1d170;
  margin-bottom: 0.5rem;
  padding: 0.5rem;
  border-top-left-radius: 0.5rem;
  border-top-right-radius: 0.5rem;

button[role="tab"] {
  color: #67769e;
  background: none;
  border: none;
  border-radius: 0.25rem;
  padding: 0.75rem 1.25rem;
  cursor: pointer;
  font-weight: 700;

button[role="tab"][aria-selected="true"] {
  background-color: #ffffff;
  color: #07409f;

button[role="tab"][aria-selected="false"]:hover {
  color: #000000;

div[role="tabpanel"] {
  padding: 1rem;



                const tabElements = document.querySelectorAll('button[role="tab"]');
const panelElements = document.querySelectorAll('[role="tabpanel"]');
let activeIndex = 0;

// Listen to clicks and key presses on tabs
tabElements.forEach(function (tab, index) {
  tab.addEventListener("click", function (event) {

  tab.addEventListener("keydown", function (event) {
    const lastIndex = tabElements.length - 1;

    if (event.code === "ArrowLeft" || event.code === "ArrowUp") {
      if (activeIndex === 0) {
        // First element, jump to end
      } else {
        // Move left
        setActiveTab(activeIndex - 1);
    } else if (event.code === "ArrowRight" || event.code === "ArrowDown") {
      if (activeIndex === lastIndex) {
        // Last element, jump to beginning
      } else {
        // Move right
        setActiveTab(activeIndex + 1);
    } else if (event.code === "Home") {
      // Move to beginning
    } else if (event.code === "End") {
      // Move to end

function setActiveTab(index) {
  // Make currently active tab inactive
  tabElements[activeIndex].setAttribute("aria-selected", "false");
  tabElements[activeIndex].tabIndex = -1;

  // Set the new tab as active
  tabElements[index].setAttribute("aria-selected", "true");
  tabElements[index].tabIndex = 0;

  activeIndex = index;

function setActivePanel(index) {
  // Hide currently active panel
  panelElements[activeIndex].setAttribute("hidden", "");
  panelElements[activeIndex].tabIndex = -1;

  // Show the new active panel
  panelElements[index].tabIndex = 0;