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 CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

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>Accessible tab component in React</h1>
<div id="mount"></div>
  font-family Menlo, Monaco, Arial, sans-serif
  font-size 1.5em
  font-size 1.1em
  list-style-type none
  padding 0
  border-bottom 1px solid #ccc
    display inline
  display inline-block
  padding 0.25em 0.75em
  margin 0 0.25em -1px 0.25em
  text-decoration none
  border 1px solid #ccc
  border-radius 3px 3px 0 0
  color #000
    border-bottom-color #fff
  padding 0 0.5em
    display none
              const Tab = ({children, index, isSelected}) => (
  <div id={`tabpanel_${index}`}

class Tabs extends React.Component {
  constructor(props) {
    this.tabs = props.children
    this.state = {selected: this.tabs.find(tab => tab.props.selected) || this.tabs[0]}
    this.selectTab = this.selectTab.bind(this)
    this.previousTab = this.previousTab.bind(this)
    this.nextTab = this.nextTab.bind(this)
    this.handleClick = this.handleClick.bind(this)
    this.handleKeyup = this.handleKeyup.bind(this)
  componentDidUpdate() {
  selectTab (tab) {
    this.setState({selected: tab})
  previousTab (tab) {
    const index = this.tabs.indexOf(tab)
    if (index > 0) this.selectTab(this.tabs[index - 1])
  nextTab (tab) {
    const index = this.tabs.indexOf(tab)
    if (index < this.tabs.length - 1) this.selectTab(this.tabs[index + 1])
  handleClick (e, tab) {
  handleKeyup (e, tab) {
    if (e.which === 13) this.selectTab(tab)
    else if (e.which === 37) this.previousTab(tab)
    else if (e.which === 39) this.nextTab(tab)
  render () {
    return (<div>
      <ul role="tablist">
        {this.tabs.map((tab, i) => (
          <li role="presentation">
            <a id={`tab_${i}`}
               aria-selected={tab === this.state.selected}
               tabIndex={tab === this.state.selected ? 0 : -1}
               onClick={e => this.handleClick(e, tab)}
               onKeyUp={e => this.handleKeyup(e, tab)}
               ref={link => { if (tab === this.state.selected) this.activeLink = link}}
        {this.tabs.map((tab, i) => (
          React.cloneElement(tab, {
            index: i,
            isSelected: () => tab === this.state.selected

const App = () => (
    <Tab title="React">
      <p>Declarative views make your code more predictable and easier to debug.</p>
      <p>Build encapsulated components that manage their own state, then compose them to make complex UIs.</p>
      <h2>Learn Once, Write Anywhere</h2>
      <p>We don't make assumptions about the rest of your technology stack, so you can develop new features in React without rewriting existing code.</p>
    <Tab title="Vue">
      <p>Already know HTML, CSS and JavaScript? Read the guide and start building things in no time!</p>

      <p>Simple, minimal core with an incrementally adoptable stack that can handle apps of any scale.</p>

      <p>16kb min+gzip Runtime<br/>
         Blazing Fast Virtual DOM<br/>
         Minimal Optimization Efforts</p>
    <Tab title="Mithril">
      <p>Only 7.8 kB gzipped, no dependencies<br/>
        Small API, small learning curve</p>

      <p>Safe-by-default templates<br/>
        Hierarchical MVC via components</p>
      <p>Virtual DOM diffing and compilable templates<br/>
        Intelligent auto-redrawing system</p>

Loading ..................