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 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

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

              
                
<tab-element>
    <nav>
        <tab-nav-item class="active" target="First tab">
            <h3>First</h3>
            <p>example tab</p>
        </tab-nav-item>
        <tab-nav-item target="Second tab">
            <h3>Second</h3>
            <p>example tab</p>
        </tab-nav-item>
        <tab-nav-item target="Third tab">
            <h3>Third</h3>
            <p>example tab</p>
        </tab-nav-item>
    </nav>

    <tab-content-item class='active' target="First tab">
        <div>
           <p> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Accusamus distinctio dolor magnam nisi perspiciatis quas reiciendis soluta.</p>
           <p>Cumque neque numquam placeat provident soluta suscipit! Accusamus autem ex in repellat. Vero!</p>
        </div>
    </tab-content-item>
    <tab-content-item target="Second tab">
        <div>
            <p> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Accusamus distinctio dolor magnam nisi perspiciatis quas reiciendis soluta.</p>
            <p>Cumque neque numquam placeat provident soluta suscipit! Accusamus autem ex in repellat. Vero!</p>
            <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. </p>
            <p>A amet, beatae consequuntur corporis cumque eveniet impedit molestias natus nihil nostrum officia quaerat, qui quidem, reiciendis unde vitae voluptas voluptatem. Quae.</p>
        </div>
    </tab-content-item>
    <tab-content-item target="Third tab">
        <div>
            <p> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Accusamus distinctio dolor magnam nisi perspiciatis quas reiciendis soluta.</p>
            <p>Cumque neque numquam placeat provident soluta suscipit! Accusamus autem ex in repellat. Vero!</p>
            <p>A amet, beatae consequuntur corporis cumque eveniet impedit molestias natus nihil nostrum officia quaerat, qui quidem, reiciendis unde vitae voluptas voluptatem. Quae.</p>
        </div>
    </tab-content-item>
</tab-element>

<!--templates-->
<template id="tab-nav">
    <style>
        :host{
            padding: 10px;
            background-color: rgb(81,180,186);
            transition: background-color 1s;
            text-align: center;
        }
        :host-context(.active) {
            background-color: rgb(93, 209, 216);
        }
        a{
            text-decoration: none;
            color: rgb(3,32,40);
        }
    </style>
    <a href="#${this._target}"><slot></slot></a>
</template>

<template id="tab-content">
    <style>
        :host {
            display: none;
            padding: 20px;
            width: 100%;
            background-color: rgb(255,212,201);
            transition: all 1s;
        }
        :host-context(.active){
            display: block;
        }
    </style>
    <div><slot></slot></div>
</template>
              
            
!

CSS

              
                *:not(:defined) {
    display: none;
}

nav {
    display: flex;
}
              
            
!

JS

              
                class TabElement extends HTMLElement {

  connectedCallback() {
    this.listener = this.showTab.bind(this);
    this.init();
  }

  disconnectedCallback() {
    this.navs.forEach(nav => nav.removeEventListener('click', this.listener));
  }

  showTab(e) {
    e.preventDefault();
    e.stopImmediatePropagation();
    const target = e.target.closest('tab-nav-item')._target;
    [...this.tabs, ...this.navs].forEach(el => {
      if (el._target === target) el.classList.add('active');
      else el.classList.remove('active');
    });
  }

  init() {
    this.navs = this.querySelectorAll('tab-nav-item');
    this.tabs = this.querySelectorAll('tab-content-item');
    this.navs.forEach(nav => nav.addEventListener('click', this.listener));
  }
}

class TabNavigationItem extends HTMLElement {
  constructor() {
    super();
    this._target = null;
    this.attachShadow({mode: 'open'});
    this.template = document.getElementById('tab-nav');
  }

  connectedCallback() {
    this.render();
  }

  static get observedAttributes() {
    return ['target'];
  }

  attributeChangedCallback(attr, prev, next) {
    if (prev !== next) {
      this[`_${attr}`] = next;
      this.render();
    }
  }

  render() {
    if (!this.ownerDocument.defaultView) return;
    let content = this.template.content.cloneNode(true);
    this.shadowRoot.appendChild(content);
  }
}

class TabContentItem extends HTMLElement {
  constructor() {
    super();
    this._target = null;
    this.attachShadow({ mode: 'open' });
    this.template = document.getElementById('tab-content');
  }

  connectedCallback() {
    this.render();
  }

  static get observedAttributes() {
    return ['target', 'content'];
  }

  attributeChangedCallback(attr, prev, next) {
    if (prev !== next) {
      this[`_${attr}`] = next;
      this.render();
    }
  }

  render() {
    if (!this.ownerDocument.defaultView) return;
    const content = this.template.content.cloneNode(true);
    this.shadowRoot.appendChild(content);
  }
}

customElements.define('tab-element', TabElement);
customElements.define('tab-nav-item', TabNavigationItem);
customElements.define('tab-content-item', TabContentItem);
              
            
!
999px

Console