Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

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>
  <h1 class="header">Screen Reader Friendly CSS Tabs to Accordion</h1>
  <p>These are CSS radio button tabs. They will turn into an accordion at lower screen width via media queries. Tabs can be focused on with the tab key. Keyboard navigation between tabs is done through arrow keys. Up and left arrows to move back a tab, down/right arrows will move forward. Tab again to focus off of the tabs. Multiple instances per page is doable as well. <br/><br/><a href="">Focus Test</a></p>
  
  
<div class="tab-container">
  
  <input name="tabset1" type="radio" id="tabset1-1" checked="checked" />
  <label for="tabset1-1">Tabset1 - Tab 1 Label</label>
  <div class="panel">
    <h1>Tabset1 - Tab 1 header</h1>
    <p>Tabset1 - Tab 1 paragraph</p>
  </div>

  <input name="tabset1" type="radio" id="tabset1-2" />
  <label for="tabset1-2">Tabset1 - Tab 2 Label</label>
  <div class="panel">
    <h1>Tabset1 - Tab 2 header</h1>
    <p>Tabset1 - Tab 2 paragraph</p>
  </div>

  <input name="tabset1" type="radio" id="tabset1-3" />
  <label for="tabset1-3">Tabset1 - Tab 3 Label</label>
  <div class="panel">
    <h1>Tabset1 - Tab 3 header</h1>
    <p>Tabset1 - Tab 3 paragraph</p>
  </div>
  
</div>

<p>And a second set of vertical tabs - note how the names and ids in the HTML are different.</p>
  
<div id="vertical" class="tab-container">
  
  <input name="vertical" type="radio" id="vertical-1" checked="checked" />
  <label for="vertical-1">Vertical 1 Label</label>
  <div class="panel">
    <h1>Vertical - Tab 1 header</h1>
    <p>Vertical - Tab 1 paragraph</p>
  </div>

  <input name="vertical" type="radio" id="vertical-2" />
  <label for="vertical-2">Vertical 2 Label</label>
  <div class="panel">
    <h1>Vertical Tab 2 header</h1>
    <p>Vertical Tab 2 paragraph</p>
  </div>

  <input name="vertical" type="radio" id="vertical-3" />
  <label for="vertical-3">Vertical 3 Label</label>
  <div class="panel">
    <h1>Vertical Tab 3 header</h1>
    <p>Vertical Tab 3 paragraph</p>
  </div>
  
</div>
  
</main>
              
            
!

CSS

              
                /* Some basic styling */
:root {
    --bg-color: #111;
    --txt-color: #eee;
    --link-color: #374c5d;
    --link2-color: #fff;
    --darktxt-color: #a0a0a0;
    --accent1-color: #232323;
    --accent2-color: #252D34;
}

*, html {font-size: 16px; line-height: 150%; box-sizing: border-box;}
body {background: var(--bg-color); color: var(--txt-color); font-family: arial, sans-serif; font-size: 1rem;}

a:link, a:visited, a:active {
  color: var(--link-color);
}
a:hover {
  color: var(--link2-color);
}

h1, h2, h3, h4, h5, h6 {
    display: block;
    font-size: inherit;
    font-weight: inherit;
    padding: 0;
    margin: 5px 0;
}
p {
    font-size: 1rem;
    margin: 5px 0;
    padding: 0;
    text-indent: 30px;
}

.header {
    background: var(--accent1-color);
    border-bottom: 10px solid var(--accent2-color);
    color: var(--darktxt-color);
    font-family: georgia, serif;
    font-size: 1.5rem;
    font-weight: bold;
    letter-spacing: 2px;
    margin-top:20px;
    padding: 8px 2px;
    text-align: center;
}

main {
    border:2px solid var(--link-color);
    padding: 15px;
}

/* This wraps around the tabs, keeping them all in one area */
.tab-container {
  display: flex;
	flex-wrap: wrap;
  width: 50%;
  margin: 10px auto;
  padding: 5px;
  border: 2px solid var(--accent1-color);
}

/* Hide the checkbox, do not use display:none as it prevents keyboard users navigating through the tabs */
.tab-container input[type="radio"] {
  width: 0;
  height: 0;
  margin: 0;
  opacity: 0;
  padding: 0;
  border: none;
  -moz-appearance: none;
  -webkit-appearance: none;
  appearance: none;
}

/* The label of the input, this is what you see and click on instead of an ugly radio button */
.tab-container label {
  order: 1;
  cursor: pointer;
  border-bottom: 2px solid var(--link2-color);
  color: var(--link2-color);
  padding: 5px 15px;
  transition: all ease-out 0.2s 0.1s;
}

/* The label "tab" when clicked */
.tab-container input[type="radio"]:checked + label {
	border-bottom: 2px solid var(--link-color);
  color: var(--link-color);
  cursor: default;
}

/* How the label appears to keyboard users when it is focused on  */
.tab-container input[type="radio"]:focus + label {
  outline: 1px solid var(--link2-color);
}

/* Panel styles */
.panel {
  order: 99;
  flex-grow: 0;
  flex-basis: 0;
  width: 0;
  height: 0;
  position: fixed;
  top: 0;
  left: 0;
  z-index: -1;
  opacity: 0;
  visibility: hidden;
}

/* Show panel when corresponding label is clicked
* This is where your tab panel styles like height, padding, backgrounds and fonts go */
.tab-container input[type="radio"]:checked + label + .panel {
  position: relative;
  visibility: visible;
  z-index: 1;
  opacity: 1;
  transition: opacity ease-out 0.2s 0.1s;
  flex-basis: 100%;
  height: 150px;
  padding: 10px;
  border: 2px solid var(--accent2-color);
  overflow: auto;
}


/* Vertical ID tabs will be vertical instead */
#vertical.tab-container {flex-direction: column; height: 375px;}
#vertical.tab-container label {width: 20%; flex-basis: unset; flex-grow: 0;}
#vertical.tab-container input[type="radio"]:checked + label + .panel {width: 80%; height:100%; top: 0; overflow: auto;}

@media (max-width: 1000px) {
  .tab-container {
    width: 100%;
  }
  .tab-container .panel,
  .tab-container label {
    order: initial;
  }
  .tab-container label {
    width: 100%!important;
    margin-right: 0;
    margin-top: 0.2rem;
  }
  .tab-container input[type="radio"]:checked + label + .panel {
    height: unset;
  }
  
  #vertical.tab-container {width: 100%; height: unset; flex-direction: row;}
  #vertical.tab-container label {width: 100%;flex-basis: 100%;}
  #vertical.tab-container input[type="radio"]:checked + label + .panel {width: 100%;}
}
              
            
!

JS

              
                
              
            
!
999px

Console