cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

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.

Quick-add: + add another resource

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.

Quick-add: + add another resource

Code Indentation

     

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.

            
              <h1>Simple Accessible Tabs</h1>

<div class="tab-widget js-tab-widget">
  <span id="tab-widget-description" class="visuallyhidden">Use left and right arrows to navigate between tabs.</span>
  
  <ul class="tab-widget__list">
    <li class="tab-widget__item">
      <a href="#tab-panel-1" class="tab-widget__link">Tab 1</a>
    </li>
    <li class="tab-widget__item">
      <a href="#tab-panel-2" class="tab-widget__link">Tab 2</a>
    </li>
    <li class="tab-widget__item">
      <a href="#tab-panel-3" class="tab-widget__link">Tab 3</a>
    </li>
  </ul>

  <div class="tab-widget__tabs">
    
    <div class="tab-widget__tab-content">
      <h2 id="tab-panel-1" tabindex="-1">Tab Panel 1</h2>
      <p>Lorem ipsum dolor sit amet, <a href="#">consectetur adipiscing elit</a>. Nullam et euismod elit. Nulla a elementum urna. Suspendisse viverra vehicula nulla.</p>          
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam et euismod elit. Nulla a elementum urna. <a href="#">Suspendisse</a> viverra vehicula nulla.</p>         
    </div>
    
    <div class="tab-widget__tab-content">
      <h2 id="tab-panel-2" tabindex="-1">Tab Panel 2</h2>
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam et euismod elit. Nulla a elementum urna. Suspendisse viverra vehicula nulla.</p>          
    </div>
    
    <div class="tab-widget__tab-content">
      <h2 id="tab-panel-3" tabindex="-1">Tab Panel 3</h2>
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam et euismod elit. Nulla a elementum urna. Suspendisse viverra vehicula nulla.</p>             
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam et euismod elit. <A href="#">Nulla a elementum urna</a>. Suspendisse viverra vehicula nulla.</p>         
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam et euismod elit. Nulla a elementum urna. Suspendisse viverra vehicula nulla.</p>         
    </div>
    
  </div>
</div>
            
          
!
            
              .tab-widget {}

.tab-widget__list {
    list-style-type: none;
    margin: 0;
    padding: 0;
}

.tab-widget__item {
    display: inline;
    margin-right: 5px;
}

.tab-widget__link {    
    background-color: FireBrick;
    border-radius: 5px 5px 0 0;
    color: White;
    font-weight: bold;
    line-height: 2.1;
    padding: .5em 1.5em;
    text-decoration: none;
}

.tab-widget__link:focus,
.tab-widget__link:hover {
    color: White;
}

.tab-widget__link--active {
    background-color: Crimson;
    color: white;
}

.tab-widget__tabs {
    background-color: WhiteSmoke;
    border: solid Firebrick 1px;    
    border-radius: 0 5px 5px 5px;
    padding: 1em;
}

.tab-widget__tab-content {    
    display: none;
}

.tab-widget__tab-content--active,
.no-js .tab-widget__tab-content {
    display: block;
}
            
          
!
            
              (function (document, window, $, undefined) {
    'use strict';

    var $tabWidget = $('.js-tab-widget');

    var setupTabs = function($tab, $allTabs, $tabPanels, $tabListItems, i) {
        $tab
            .attr({
                'id': 'tab-link-' + i,
                'tabindex': '-1',
                'role': 'tab',
                'aria-selected': 'false',
                'aria-controls': 'tab-panel-' + i
            });

        if (i === 0) {
            $tab
                .attr({
                    'tabindex': '0',
                    'aria-selected': 'true',
                    'aria-describedby': 'tab-widget-description'
                })
                .addClass('tab-widget__link--active');
        }

        $tab.on('click', function(e) {
            e.preventDefault();

            tabClick($(this),  $allTabs, $tabPanels, i);
        });
      
        $tab.on('focus', function(e) {
            tabClick($(this),  $allTabs, $tabPanels, i);
        });

        $tab.on('keydown', function (e) {
            tabKeydown($(this), $allTabs, $tabPanels, $tabListItems, i, e);
        });
    };

    var setupTabPanels = function(tabPanel, i) {
        tabPanel
            .attr({
                'id': 'tab-panel-' + i,
                'role': 'tabpanel',
                'aria-hidden': 'true',
                'aria-labelledby': 'tab-link-' + i
            });

        if (i === 0) {
            tabPanel
                .attr('aria-hidden', 'false')
                .addClass('tab-widget__tab-content--active');
        }
    };

    var tabClick = function($thisTab, $allTabs, $tabPanels, i) {
        $allTabs
            .attr({
                'tabindex': -1,
                'aria-selected': 'false'
            })
            .removeAttr('aria-describedby')
            .removeClass('tab-widget__link--active');

        $thisTab
            .attr({
                'tabindex': 0,
                'aria-selected': 'true',
                'aria-describedby': 'tab-widget-description'
            })
            .addClass('tab-widget__link--active');

        $tabPanels
            .attr('aria-hidden', 'true')
            .removeClass('tab-widget__tab-content--active');

        $tabPanels.eq(i)
            .attr('aria-hidden', 'false')
            .addClass('tab-widget__tab-content--active');
    };

    var tabKeydown = function($thisTab, $allTabs, $tabPanels, $tabListItems, i, e) {
        var keyCode = e.which,
            $nextTab = $thisTab.parent().next().is('li') ? $thisTab.parent().next().find('a') : false,
            $previousTab = $thisTab.parent().prev().is('li') ? $thisTab.parent().prev().find('a') : false,
            $firstTab = $thisTab.parent().parent().find('li:first').find('a'),
            $lastTab = $thisTab.parent().parent().find('li:last').find('a');

        switch(keyCode) {
            // Left/Up
            case 37:
            case 38:
                e.preventDefault();
                e.stopPropagation();

                if (!$previousTab) {
                    $lastTab.focus();
                } else {
                    $previousTab.focus();
                }

                break;

            // Right/Down
            case 39:
            case 40:
                e.preventDefault();
                e.stopPropagation();

                if (!$nextTab) {
                    $firstTab.focus();
                } else {
                    $nextTab.focus();
                }

                break;

            // Home
            case 36:
                e.preventDefault();
                e.stopPropagation();

                $firstTab.focus();

                break;

            // End
            case 35:
                e.preventDefault();
                e.stopPropagation();

                $lastTab.focus();

                break;

            // Enter/Space
            case 13:
            case 32:
                e.preventDefault();
                e.stopPropagation();

                break;
        }
    };

    $tabWidget.each(function () {
        var $this = $(this),
            $tabList = $this.find('> ul'),
            $tabListItems = $tabList.find('li'),
            $allTabs = $tabListItems.find('a'),
            $tabPanels = $this.find('> div > div');

        $tabList.attr('role', 'tablist');
        $tabListItems.attr('role', 'presentation');

        $allTabs.each(function (i) {
            setupTabs($(this), $allTabs, $tabPanels, $tabListItems, i);
        });

        $tabPanels.each(function (i) {
            setupTabPanels($(this), i);
        });
    });

  $('html').addClass('js').removeClass('no-js');

})(document, window, jQuery);

            
          
!
999px
Loading ..................

Console