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

              
                <body style="--color: hsl(340, 60%, 30%)">
  <!-- This element will be animated while transitioning from one tab to another -->
  <div class="background"></div>
  
  <!-- List of tabs. Set the desired color for each tab in their inline style attribute with the --color property -->
  <div class="tab-list">
    <button class="tab on" id="tab1"
            style="--color: hsl(340, 60%, 30%)">
      First tab
    </button>

    <button class="tab" id="tab2"
            style="--color: hsl(160, 60%, 25%)">
      Tab 2
    </button>

    <button class="tab" id="tab3"
            style="--color: hsl(220, 60%, 35%)">
      Tab the 3rd
    </button>
  </div>

  <!-- List of sections. Each one is linked to its tab through the data-tab="tab id" attribute -->
  <div class="section-list">
    <section data-tab="tab1" class="on">
      <p>Pokem ipsum dolor sit amet Vanillish Growl Rufflet Earthquake Torkoal Drifloon. V for victory Noctowl Terrakion Ludicolo Lickilicky Togekiss Elekid. Misty Flareon you teach me and I'll teach you Mantine Exeggutor Rayquaza Ditto. Tail Whip Strength Registeel Dunsparce Pinsir Houndoom Yamask. Consectetur adipisicing elit Poochyena Kakuna Phanpy Gigalith Lairon Carnivine.

      <p>Sonic Boom Leafeon Vanilluxe deserunt mollit Espeon Electrode Togepi. Leech Seed Spinda excepteur sint occaecat cupidatat non proident Sandile Shellder Ninetales Virizion. Team Rocket Omastar Swanna Lunatone Cacnea Combee Froslass. Anim id est laborum Gorebyss Vaporeon Bonsly Missingno Thundurus Flygon. Fog Badge Ice Berry make it double Fighting Durant Slowking Mandibuzz.

      <p>Johto Vigoroth Luxio Ash Ketchum Castform Bellsprout Monferno. Water Primeape Chingling Leech Seed Arcanine Houndour Dustox. Hoenn Lairon Gible Shinx Bastiodon Stantler Ponyta. Consectetur adipisicing elit Earth Badge Youngster wants to fight Chikorita Magnezone Treecko Kecleon. Plain Badge Scolipede Reshiram Minun Shiftry Porygon Remoraid.
        
      <p>This Pokem ipsum text comes from pokemipsum.com
    </section>

    <section data-tab="tab2">
      <p>Pokem ipsum dolor sit amet Golett Reshiram Roselia Dragon Rage Staryu Escape Rope. Gotta catch 'em all Swellow Cranidos Blaziken Soda Pop Officer Jenny Dusclops. Pokemon 4Ever Shuppet Bayleef Salamence Wormadam Cherrim Geodude. Water Bisharp Lickilicky Teddiursa Cresselia Fearow Litwick. Viridian City Tepig Barboach Pikachu Krookodile Mystery Gift Gloom.

      <p>Strength Camerupt Scolipede Exeggutor Grumpig Kyurem Shaymin. Pewter City Camerupt Skorupi Growlithe Hitmonlee Swadloon Piplup. Hive Badge Persian Beartic Galvantula Boldore Typhlosion Vanillish. Water Gun Sceptile Ultra Ball Articuno Swellow Mime Jr Beldum. Dragon Pewter City Rotom Whirlipede Pupitar Tauros Mismagius.

      <p>Mewtwo Strikes Back Luvdisc Trubbish Alomomola Woobat Blizzard Starmie. Psychic Woobat Flying Ash Mandibuzz Koffing Volcarona. Fog Badge duis aute irure dolor in reprehenderit Reuniclus Cascade Badge Celadon Department Store Celadon City Torkoal. Ice Escavalier Noctowl Hidden Machine Mr. Mime Druddigon you teach me and I'll teach you. Normal Samurott Sableye Zephyr Badge Phanpy Budew Carnivine.
    </section>

    <section data-tab="tab3">
      <p>Pokem ipsum dolor sit amet Poochyena Cryogonal Omanyte Corphish but nothing happened Body Slam. Ut labore et dolore magna aliqua Reuniclus Gothorita Lopunny Archen Water Gun Galvantula. Storm Badge Flamethrower Missingno Dark Furret Zweilous Pansear. Teleport Cloyster Cofagrigus Flamethrower Krookodile Burnt Berry Water Gun. Ut labore et dolore magna aliqua Whirlipede Darkrai Nidoking Nosepass Lickilicky Vanilluxe.

      <p>Sed do eiusmod tempor incididunt Teleport Girafarig Ludicolo Blaziken Keldeo Dragonair. Misty Golett Lairon Carvanha Marill Steelix Togekiss. Glitch City Dragonite Helix Fossil Charizard Ludicolo Razor Leaf Grovyle. Bubble Swanna Rhyperior Professor Elm Pidgey Giratina Nidoran. Splash Suicune Combusken Gothorita Simisear Officer Jenny Eelektross.

      <p>Ut enim ad minim veniam Teddiursa Misdreavus Raticate Lunatone Diglett Escape Rope. Kanto Mewtwo Strikes Back Mewtwo Strikes Back Empoleon Psychic Magnemite Giratina. Thunder Badge Pignite Slash Doduo Cerulean City Electrode Skorupi. Dragon Turtwig Manectric Palpitoad James Swadloon Azurill. Harden Smeargle Drifblim Fire Sandslash Deerling the power that's inside.
    </section>
  </div>
</body>
              
            
!

CSS

              
                html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  color: #ddd;
  font-size: 1.1rem;
  background: var(--color, #222);
}

body {
  display: grid;
  grid-template-rows: auto 1fr;
}

/* Animated background during transition */
.background {
  width: 100vw;
  height: 100vh;
  position: fixed;
  top: 0;
  left: 0;
  transform-origin: top left;
}

.tab-list {
  padding: 1rem 0;
  display: flex;
  flex-direction: row;
  justify-content: space-evenly;
  grid-row: 1 / 2;
  max-width: 25rem;
}

.tab {
  /* Resetting default button appearance */
  -moz-appearance: none;
  -webkit-appearance: none;
  appearance: none;
  border: none;
  background: none;
  
  /* Customize text */
  color: inherit;
  font-size: inherit;
  
  /* Customize size */
  padding: 0 1rem;
  height: 3rem;
  
  position: relative;
  z-index: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}

/* Tab background color, expands on hover */
.tab::before {
  content: '';
  
  /* Fills the whole tab */
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  
  background-color: var(--color);
  z-index: -1;
  transition: transform .12s ease-out;
}

/* Expand background color of the tab on hover, as a hint it can expand further by clicking it */
.tab:hover::before {
  transform: scale(1.2);
}

/* Make currently active tab unclickable */
.tab.on {
  cursor: auto;
  pointer-events: none;
}

.tab:focus:hover {
  outline: none;
}

/* Tab text underline */
.tab::after {
  content: '';
  display: block;
  background-color: white;
  
  /* Size and position */
  width: calc(100% - 2rem);
  height: 2px;
  position: absolute;
  bottom: .5rem;
  left: 1rem;
  z-index: 3;
  
  /* Ready to animate on tab activation */
  transform-origin: top left;
  transform: scaleX(0);
  transition: transform .2s ease-out;
}

/* Display the underline on active tab */
.tab.on::after {
  transform: scaleX(1);
}

/* Change side of underline origin */
.tab.fromright::after {
  transform-origin: top right;
}

.section-list {
  overflow-y: auto;
  padding: 0 .5rem;
  grid-row: 2 / 3;
}

/* Hide sections by default */
section {
  display: none;
  width: 100%;
  max-width: 42rem;
}

/* Display section corresponding to active tab */
section.on {
  display: block;
}
              
            
!

JS

              
                const allTabs = document.querySelectorAll('.tab');
let futureTab;

function changeTab(id) {
  futureTab = id;
  const tab = document.getElementById(id);
  const section = document.querySelector('[data-tab='+id+']');
  const background = document.querySelector('.background');
  const newColor = tab.style.getPropertyValue('--color');
  
  const previousTab = document.querySelector('.tab.on');
  
  // Do nothing if we're already on this tab
  if (tab.classList.contains('on')) return;
  
  // Checking if the new tab is on the left or right of the currently activated one, to animate the underline
  if (previousTab.id.replace('tab', '') > id.replace('tab', '')) {
    tab.classList.add('fromright');
    previousTab.classList.remove('fromright');
  } else {
    tab.classList.remove('fromright');
    previousTab.classList.add('fromright');
  }
  
  // Resetting all tabs and sections
  allTabs.forEach(t => {
    t.classList.remove('on');
    document.querySelector('section[data-tab='+t.id+']').classList.remove('on');
  });
  
  // Activating new tab
  tab.classList.add('on');
  tab.blur();
  
  // Calculating the starting position of the expanding background color
  const tabPos = tab.getBoundingClientRect();
  const scaleX = (tabPos.right - tabPos.left) / window.innerWidth;
  const scaleY = (tabPos.bottom - tabPos.top) / window.innerHeight;
  
  background.style.backgroundColor = newColor;
  
  // Animating the expanding background color
  const keyframes = [
    { transform: 'translate3D(' + tabPos.left + 'px, ' + tabPos.top + 'px, 0) scale(' + scaleX + ', ' + scaleY + ')' },
    { transform: 'translate3D(0, 0, 0) scale(1, 1)'}
  ];
  
  const coloration = background.animate(
    keyframes, {
      easing: 'cubic-bezier(0.2, 0.45, 0.3, 1)',
      duration: 400,
      fill: 'forwards'
  });

  // After the animation...
  coloration.addEventListener('finish', () => {
    // If another tab is opening already, do nothing
    if (futureTab != id) return;

    // Else, display and animate the new section
    document.body.style.setProperty('--color', newColor);
    section.classList.add('on');
    section.animate([
      { opacity: '0', transform: 'translate3D(0, 1rem, 0)' },
      { opacity: '1', transform: 'translate3D(0, 0, 0)' }
    ], {
        easing: 'cubic-bezier(0.0, 0.0, 0.2, 1)',
        duration: 150,
        fill: 'forwards'
    });
  });
}

// Detect clicks on all tabs
allTabs.forEach(t => {
  t.addEventListener('click', () => changeTab(t.id));
});
              
            
!
999px

Console