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

              
                <h1>The most simple tablist (I could come up with) that does not use JavaScript</h1>

<p>This tablist is based on flexbox and the :has selector.</p>

<div>
  <label>
    Focus this text field and then press the tab key on your keyboard to jump into the active tab. It´s then possible to change the active tab with the arrow keys of the keyboard.
    <input type="text" style="display:block; border: 1px solid currentColor; font-size: 1em;">
  </label>

  <p>You can as well select any tab by clicking on it with the mouse pointer.</p>
</div>

<!-- Below comes the tablist

- Roles are used for accessibility. The tablist role is used as the CSS selector for the tablist.
- The name of the input radioboxes has to be adjusted when there are multiple tablists on one page. For each new tablist it needs to be the same for all radio inputs inside of the tablist, but different to the other tablists of the page.

-->

<div role="tablist">
  <!-- tab 1 -->
  <label role="tab">
    <input type="radio" name="tab" checked>Tab 1
  </label>
  <div role="tabpanel">Tab 1 content</div>

  <!-- tab 2 -->
  <label role="tab">
    <input type="radio" name="tab">Tab 2
  </label>
  <div role="tabpanel">Tab 2 content</div>

  <!-- tab 3 -->
  <label role="tab">
    <input type="radio" name="tab">Tab 3
  </label>
  <div role="tabpanel">Tab 3 content</div>
</div>
              
            
!

CSS

              
                [role="tablist"] {
  --outline: auto Highlight;
  --tab-label-padding: 0.5em;
  --tab-label-radius: 0.15em;
  --tab-label-min-width: 4em;
  --tab-label-active-background: white;
  --tab-content-x-padding: 0;
  --tab-content-y-padding: 1em;
  --tab-border-color: currentColor;
  --tab-border-width: 1px;

  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
}

/* hide everything, except the tab labels */
[role="tablist"] > *:not(label[role="tab"]) {
  display: none;
}

/* keep the inputs on the page, but make them invisible to allow for keyboard focus */
[role="tablist"] > label[role="tab"] > input[type="radio"] {
  opacity: 0;
  width: 0;
  height: 0;
  margin: 0;
}

/* when using the tab key on the keyboard to focus into the tablist, indicate the default outline */
[role="tablist"] > label[role="tab"]:has(:focus-visible) {
  outline: var(--outline);
  outline-offset: calc(-1 * var(--tab-label-padding));
}

/* tab label */
[role="tablist"] > label[role="tab"] {
  padding: var(--tab-label-padding) var(--tab-label-padding);
  min-width: var(--tab-label-min-width);
  margin-bottom: calc(-1 * var(--tab-border-width));
  border-left: var(--tab-border-width) solid transparent;
  border-top: var(--tab-border-width) solid transparent;
  border-right: var(--tab-border-width) solid transparent;
  cursor: pointer;
}

/* selected tab label */
[role="tablist"] > label[role="tab"]:has(input[type="radio"]:checked) {
  border-left: var(--tab-border-width) solid var(--tab-border-color);
  border-top: var(--tab-border-width) solid var(--tab-border-color);
  border-right: var(--tab-border-width) solid var(--tab-border-color);
  border-radius: var(--tab-label-radius) var(--tab-label-radius) 0 0;
  background: var(--tab-label-active-background);
}

/* tab content */
[role="tablist"] > label[role="tab"]:has(input:checked) + [role="tabpanel"] {
  border-top: var(--tab-border-width) solid var(--tab-border-color);
  order: 99;
  display: block;
  width: 100%;
  position: relative;
  z-index: -1;
  padding: var(--tab-content-y-padding) var(--tab-content-x-padding);
}

              
            
!

JS

              
                
              
            
!
999px

Console