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

              
                <main>
  <div data-tab-component>
    <h1 class="base--h1">A11Y Tabs</h1>
    <ul class="tab-list">
      <li class="tab-item">
        <a class="tab-link" href="#section-0">Planning</a>
      </li>
      <li class="tab-item">
        <a class="tab-link" href="#section-1">Feedback</a>
      </li>
      <li class="tab-item">
        <a class="tab-link" href="#section-2">Retrospective</a>
      </li>
    </ul>
    <section id="section-0" class="tab-panel">
      <h2>Planning</h2>
      <p>
        Pixel pushing game-plan, yet core competencies, or table the discussion quick win. Collaboration through advanced technlogy i also believe it's important for every member to be involved and invested in our company and this is one way to do so but low-hanging fruit reach out. Deliverables t-shaped individual. 
      </p>
      <p>
        Push back drill down. We need distributors to evangelize the new line to local markets productize or game plan drop-dead date we're ahead of the curve on that one nor win-win <a target="_blank" href="https://alistapart.com/topic/usability">usabiltiy</a>.
      </p>
      <p>
        Future-proof paddle on both sides i'll book a meeting so we can solution this before the sprint is over so sacred cow productize due diligence. We're ahead of the curve on that one closer to the metal show pony, or mobile friendly. 
      </p>
      <p>
        Strategic high-level 30,000 ft view upsell shotgun approach closer to the metal, we need distributors to evangelize the new line to local markets, yet collaboration through advanced technlogy. Imagineer strategic high-level 30,000 ft view work flows , or quick win, yet curate, but deploy anti-pattern.
      </p>
    </section>
    <section id="section-1" class="tab-panel">
      <h2>Feedback</h2>
      <p>
        Can you use a high definition screenshot can you make the blue bluer? and I got your invoice...it seems really high, why did you charge so much, for we are your relatives. There are more projects lined up charge extra the next time will royalties in the company do instead of cash. 
      </p>
      <p>
        Make it look like Apple theres all this spanish text on my site can you make the logo bigger yes bigger bigger still the logo is too big but concept is bang on, but can we look at a better execution, and the website doesn't have the theme i was going for or can you pimp this powerpoint, need more geometry patterns make it sexy.
      </p>
      <p>
        Concept is bang on, but can we look at a better execution im not sure, try something else, for remember, everything is the same or better and can you make it stand out more?, nor low resolution? It looks ok on my screen thats not what i saw in my head at all can you make pink a little more pinkish. I need a website. 
      </p>
      <p>
        How much will it cost this looks perfect. Just <a target="_blank" href="http://theoatmeal.com/comics/design_hell">Photoshop out the dog, add a baby, and make the curtains blue</a> can you make the logo bigger yes bigger bigger still the logo is too big I need a website. How much will it cost, so im not sure, try something else, nor can you make it pop.
      </p>
    </section>
    <section id="section-2" class="tab-panel">
      <h2>Retrospective</h2>
      <p>
        High turnaround rate globalize first-order optimal strategies. Ramp up game-plan i also believe it's important for every member to be involved and invested in our company and this is one way to do so. Overcome key issues to meet key milestones get buy-in are we in agreeance, and knowledge is power. Into the weeds fire up your browser deploy, or deploy, value-added high-level. 
      </p>
      <p>
        Vertical integration deliverables yet shelfware. It just needs <a target="_blank" href="https://www.youtube.com/watch?v=Q_MWeOs8Ffg">more cowbell</a> we need more paper, but guerrilla marketing, for dogpile that. Organic growth idea shower, yet strategic fit. Can we take this offline where do we stand on the latest client ask come up with something buzzworthy, nor shoot me an email and your work on this project has been really impactful.
      </p>
      <p>
        Can I just chime in on that one bleeding edge drill down, and cross-pollination, or those options are already baked in with this model.
      </p>
    </section>
  </div>
</main>
              
            
!

CSS

              
                main {
  padding: 1rem;
}

[role="tablist"] {
  background: #0d8a00;
  padding: 0;
  margin: 0;
}

[role="presentation"] {
  display: block;
}

[role="presentation"][data-tab-active] {
  background: #036800;
  -webkit-transition: all 100ms cubic-bezier(0.42, 0, 1, 1);
  transition: all 100ms cubic-bezier(0.42, 0, 1, 1);
}

[role="tab"] {
/*   border: 3px solid transparent; */
  color: #fff;
  display: block;
  padding: 1rem 2rem;
  position: relative;
  text-decoration: none;
  -webkit-transition: all 100ms cubic-bezier(0.42, 0, 1, 1);
  transition: all 100ms cubic-bezier(0.42, 0, 1, 1);
}

[role="tab"]:focus {
    outline: 0;
    background-color: #0d8a00;
    box-shadow: inset 0 0 0 3px #036800;
}

[role="tabpanel"] {
  background: #f0f0f0;
  padding: 1rem;
}

[role="tabpanel"] h2 {
  margin-top: 0;
}

[role="tabpanel"][aria-hidden="true"] {
  display: none;
}

[role="tabpanel"]:focus {
  outline: 0;
  box-shadow: inset 0 0 0 2px #036800;
}

@media screen and (min-width: 800px) {
  [role="presentation"] {
    display: inline-block;
  }

  [role="presentation"][data-tab-active] [role="tab"]:after {
    content: '';
    display: inline-block;
    margin: auto;
    position: absolute;
    bottom: -9px;
    left: 0;
    right: 0;
    width: 0;
    height: 0;
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    border-top: 10px solid #036800;
  }
}

              
            
!

JS

              
                window.a11yTabs = (function tabsComponentIIFE(global, document) {
  'use strict';

  const tabInstances = new WeakMap();

  /**
   * Instantiates the component
   * @constructor
   * @param {DOM Node} element
   */
  const TabComponent = function TabComponent(element, options) {
    if (!element || !element.nodeType) {
      throw new Error(
        'The DOM element was not found when creating the tab component'
      );
    }
    const defaults = {
      tabList: '.tab-list',
      tabItem: '.tab-item',
      tabLink: '.tab-link',
      tabPanel: '.tab-panel'
    };
    this.options = Object.assign(defaults, options);

    this.element = element;
    this.tabList = element.querySelector(this.options.tabList);
    this.tabItems = [].slice.call(
      this.tabList.querySelectorAll(this.options.tabItem)
    );
    this.tabLinks = [].slice.call(
      this.tabList.querySelectorAll(this.options.tabLink)
    );
    this.tabPanels = [].slice.call(
      element.querySelectorAll(this.options.tabPanel)
    );

    this.currentIndex = 0;

    this.tabList.setAttribute('role', 'tablist');

    this.tabItems.forEach((item, index) => {
      item.setAttribute('role', 'presentation');

      if (index === 0) {
        item.setAttribute('data-tab-active', '');
      }
    });

    this.tabLinks.forEach((item, index) => {
      item.setAttribute('role', 'tab');
      item.setAttribute('id', 'tab' + index);

      if (index > 0) {
        item.setAttribute('tabindex', '-1');
      } else {
        item.setAttribute('aria-selected', 'true');
      }
    });

    this.tabPanels.forEach((item, index) => {
      item.setAttribute('role', 'tabpanel');
      item.setAttribute('aria-labelledby', 'tab' + index);
      item.setAttribute('tabindex', '-1');

      if (index > 0) {
        item.setAttribute('hidden', '');
      }
    });

    this.eventCallback = handleEvents.bind(this);
    this.tabList.addEventListener('click', this.eventCallback, false);
    this.tabList.addEventListener('keydown', this.eventCallback, false);

    tabInstances.set(this.element, this);
  };

  TabComponent.prototype = {
    /**
     * Event handler for all tab interactions
     * @param {number} index - Index of the tab being activiated
     * @param {string} direction -
     */
    handleTabInteraction: function handleTabInteraction(index, direction) {
      const currentIndex = this.currentIndex;
      let newIndex = index;

      // The click event does not pass in a direction. This is for keyboard support
      if (direction) {
        if (direction === 37) {
          newIndex = index - 1;
        } else {
          newIndex = index + 1;
        }
      }

      // Supports continuous tabbing when reaching beginning or end of tab list
      if (newIndex < 0) {
        newIndex = this.tabLinks.length - 1;
      } else if (newIndex === this.tabLinks.length) {
        newIndex = 0;
      }

      // update tabs
      this.tabLinks[currentIndex].setAttribute('tabindex', '-1');
      this.tabLinks[currentIndex].removeAttribute('aria-selected');
      this.tabItems[currentIndex].removeAttribute('data-tab-active');

      this.tabLinks[newIndex].setAttribute('aria-selected', 'true');
      this.tabItems[newIndex].setAttribute('data-tab-active', '');
      this.tabLinks[newIndex].removeAttribute('tabindex');
      this.tabLinks[newIndex].focus();

      // update tab panels
      this.tabPanels[currentIndex].setAttribute('hidden', '');
      this.tabPanels[newIndex].removeAttribute('hidden');

      this.currentIndex = newIndex;

      return this;
    },

    /**
     * Set tab panel focus
     * @param {number} index - Tab panel index to receive focus
     */
    handleTabpanelFocus: function handleTabPanelFocus(index) {
      this.tabPanels[index].focus();

      return this;
    }
  };

  /**
   * Creates or returns existing component
   * @param {string} selector
   */
  function createTabComponent(selector, options) {
    const element = document.querySelector(selector);
    return tabInstances.get(element) || new TabComponent(element, options);
  }

  /**
   * Destroys an existing component
   * @param {DOM Node} element
   */
  function destroyTabComponent(element) {
    if (!element || !element.nodeType) {
      throw new Error(
        'The DOM element was not found when deleting the tab component'
      );
    }

    let component = tabInstances.get(element);
    component.tabList.removeAttribute('role', 'tablist');

    component.tabItems.forEach((item, index) => {
      item.removeAttribute('role', 'presentation');

      if (index === 0) {
        item.removeAttribute('data-tab-active');
      }
    });

    component.tabLinks.forEach((item, index) => {
      item.removeAttribute('role', 'tab');
      item.removeAttribute('id', 'tab' + index);

      if (index > 0) {
        item.removeAttribute('tabindex', '-1');
      } else {
        item.removeAttribute('aria-selected', 'true');
      }
    });

    component.tabPanels.forEach((item, index) => {
      item.removeAttribute('role', 'tabpanel');
      item.removeAttribute('aria-labelledby', 'tab' + index);
      item.removeAttribute('tabindex', '-1');

      if (index > 0) {
        item.removeAttribute('hidden');
      }
    });

    component.tabList.removeEventListener('click', component.eventCallback);
    component.tabList.removeEventListener('keydown', component.eventCallback);
    tabInstances.delete(component.element);
  }

  /**
   * Handles all event listener callbacks
   * @param {event} event
   */
  function handleEvents(event) {
    if (event.type === 'click') {
      event.preventDefault();
      TabComponent.prototype.handleTabInteraction.call(
        this,
        this.tabLinks.indexOf(event.target)
      );
    }

    if (event.type === 'keydown') {
      const index = this.tabLinks.indexOf(event.target);

      // Left and right arrows
      if (event.which === 37 || event.which === 39) {
        event.preventDefault();
        TabComponent.prototype.handleTabInteraction.call(
          this,
          index,
          event.which
        );
      }

      // Down arrow
      if (event.which === 40) {
        event.preventDefault();
        TabComponent.prototype.handleTabpanelFocus.call(this, index);
      }
    }
  }

  return {
    create: createTabComponent,
    destroy: destroyTabComponent
  };
})(window, document);

const tabComponent = a11yTabs.create('[data-tab-component]')
              
            
!
999px

Console