title: Accessible CSS-only tab view
body: <p>I'm working on a site that needs to (a) work without JavaScript and (b) be keyboard-accessible.</p>
  
  <p>I have used the label target trick to build a tab view (<a href="https://css-tricks.com/functional-css-tabs-revisited/" rel="nofollow noreferrer">https://css-tricks.com/functional-css-tabs-revisited/</a>), but I've noticed that it relies on the label being clicked. I can't figure out how to make it work with the keyboard. Is this possible?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-css lang-css prettyprint-override"><code>.tabs {
    background-color: #eee;
    min-height: 400px;
  }
  
  .tabs__list {
    border-bottom: 1px solid black;
    display: flex;
    flex-direction: row;
    list-style: none;
    margin: 0;
    padding: 0;
    position: relative;
  }
  
  .tabs__tab {
    padding: 0.5rem;
  }
  
  .tabs__content {
    display: none;
    left: 0;
    padding: 0.5rem;
    position: absolute;
    top: 100%;
  }
  
  .tabs__input {
    display: none;
  }
  
  .tabs__input+label {
    cursor: pointer;
  }
  
  .tabs__input:focus,
  .tabs__input:hover {
    color: red;
  }
  
  .tabs__input:checked+label {
    color: red;
  }
  
  .tabs__input:checked~.tabs__content {
    display: block;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="tabs"&gt;
    &lt;ul class="tabs__list"&gt;
      &lt;li class="tabs__tab"&gt;
        &lt;input class="tabs__input" type="radio" id="tab-0" name="tab-group" checked&gt;
        &lt;label for="tab-0" class="tabs__label" tabindex="0" role="button"&gt;Tab 0&lt;/label&gt;
        &lt;div class="tabs__content"&gt;
          Tab 0 content
        &lt;/div&gt;
      &lt;/li&gt;
      &lt;li class="tabs__tab"&gt;
        &lt;input class="tabs__input" type="radio" id="tab-1" name="tab-group"&gt;
        &lt;label for="tab-1" class="tabs__label" tabindex="0" role="button"&gt;Tab 1&lt;/label&gt;
        &lt;div class="tabs__content"&gt;
          Tab 1 content
        &lt;/div&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>