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

              
                
<div class="app">
  <div class="window">
    <div class="tab-bar"></div>
    <div class="control-bar">
      <div class="tab-counter">
        0
      </div>
      <input class="text-input" placeholder="Start typing here"/>
      <button class="button button-auto-generate">
        <svg width="24" height="24" fill="none" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M16.749 2h4.554l.1.014.099.028.06.026c.08.034.153.085.219.15l.04.044.044.057.054.09.039.09.019.064.014.064.009.095v4.532a.75.75 0 0 1-1.493.102l-.007-.102V4.559l-6.44 6.44a.75.75 0 0 1-.976.073L13 11 9.97 8.09l-5.69 5.689a.75.75 0 0 1-1.133-.977l.073-.084 6.22-6.22a.75.75 0 0 1 .976-.072l.084.072 3.03 2.91L19.438 3.5h-2.69a.75.75 0 0 1-.742-.648l-.007-.102a.75.75 0 0 1 .648-.743L16.75 2ZM3.75 17a.75.75 0 0 1 .75.75v3.5a.75.75 0 0 1-1.5 0v-3.5a.75.75 0 0 1 .75-.75Zm5.75-3.25a.75.75 0 0 0-1.5 0v7.5a.75.75 0 0 0 1.5 0v-7.5ZM13.75 15a.75.75 0 0 1 .75.75v5.5a.75.75 0 0 1-1.5 0v-5.5a.75.75 0 0 1 .75-.75Zm5.75-4.25a.75.75 0 0 0-1.5 0v10.5a.75.75 0 0 0 1.5 0v-10.5Z"/></svg>
        <span class="label">
          More Tabs
        </span>
      </button>
      <button class="button button-close-all">
        <svg width="24" height="24" fill="none" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 1.75a3.25 3.25 0 0 1 3.245 3.066L15.25 5h5.25a.75.75 0 0 1 .102 1.493L20.5 6.5h-.796l-1.28 13.02a2.75 2.75 0 0 1-2.561 2.474l-.176.006H8.313a2.75 2.75 0 0 1-2.714-2.307l-.023-.174L4.295 6.5H3.5a.75.75 0 0 1-.743-.648L2.75 5.75a.75.75 0 0 1 .648-.743L3.5 5h5.25A3.25 3.25 0 0 1 12 1.75Zm6.197 4.75H5.802l1.267 12.872a1.25 1.25 0 0 0 1.117 1.122l.127.006h7.374c.6 0 1.109-.425 1.225-1.002l.02-.126L18.196 6.5ZM13.75 9.25a.75.75 0 0 1 .743.648L14.5 10v7a.75.75 0 0 1-1.493.102L13 17v-7a.75.75 0 0 1 .75-.75Zm-3.5 0a.75.75 0 0 1 .743.648L11 10v7a.75.75 0 0 1-1.493.102L9.5 17v-7a.75.75 0 0 1 .75-.75Zm1.75-6a1.75 1.75 0 0 0-1.744 1.606L10.25 5h3.5A1.75 1.75 0 0 0 12 3.25Z" /></svg>
        <span class="label">
          Close All
        </span>
      </button>
    </div>
  </div>
  <div class="page-content">
    <h1 class="app-name">
      <span class="char">T</span><span class="char">a</span><span class="char">b</span>&nbsp;<span class="char">S</span><span class="char">i</span><span class="char">m</span><span class="char">u</span><span class="char">l</span><span class="char">a</span><span class="char">t</span><span class="char">o</span><span class="char">r</span>
    </h1>
    <div class="app-summary">
    <div class="toast">
        Zero tabs. No more tabs.
    </div>
      Close some tabs. It'll be alright ❤️
    </div>
  </div>
</div>
              
            
!

CSS

              
                *{
  box-sizing:border-box;
}

:root{
  --control-bar-height:80px;
  --page-content-height:164px;
  --tab-height: 40px;
  --color-text-input: #EDF2FA;
  --color-tab-hover: #A8C7FA;
  --color-text-dark: #474747;
  --tab-max-width:50%;
  --button-label-display:none;
  --color-blue:#4285F4;
  --color-red:#EA4336;
  --color-yellow:#FABD05;
  --color-green:#34A853;  
  --color-green-light:#63FF8C;  
  --color-green-dark:#26843F;
}

@media screen and (min-width: 500px){
  :root{
    --tab-max-width:33%;
  }
}

@media screen and (min-width: 800px){
  :root{
    --button-label-display:block;
  }
}

.app{
  font-family: "Inter", sans-serif;
  display:flex;
  height:100dvh;
  flex-direction:column;
  color:var(--color-text-dark);
}

.button{
  background:none;
  font-size:inherit;
  font-family:inherit;
  color:inherit;
  border:none;
  text-wrap:nowrap;
  display:inline-flex;
  align-items:center;
  padding:0 1rem;
  height:3rem;
  border-radius:1.5rem;
  cursor:pointer;
  gap:.5rem;

  &:disabled{
    opacity:.25;
    pointer-events:none;
  }

  &:hover{
    background: var(--color-text-input);
  }

  .label{
    display: var(--button-label-display);
  }

  svg{
    fill:currentColor;
    display:block;
  }
}

.window{
  font-family: sans-serif;
  letter-spacing:.01em;
  color: var(--color-text-dark);
}

.control-bar{
  height: var(--control-bar-height);
  background:#fff;
  padding:1rem;
  border-bottom: 1px solid var(--color-tab-hover);
  display:flex;
  align-items:center;
  gap:1rem;
}

.tab-counter{
  border: 2px solid var(--color-text-dark);
  border-radius:6px;
  width:2rem;
  height:2rem;
  display:flex;
  align-items:center;
  justify-content:center;
  flex:none;

  &[data-count="0"]{
    animation: counter-zero 500ms ease;
  }
}

.text-input{
  background: var(--color-text-input);
  color: inherit;
  border-radius:2rem;
  border:none;
  height:3rem;
  display:flex;
  align-items:center;
  padding:0 1rem;
  text-wrap:none;
  overflow:hidden;
  text-overflow:ellipsis;
  font-size:1.25rem;
  width:100%;
  font-family:inherit;

  &:disabled{
    opacity:.25;
    transition:all 250ms ease;
  }

  &::placeholder{

  }
}

.tab-bar{
  width:100%;
  display:flex;
  flex-wrap:wrap;
  position:relative;
  background:repeat-y top center / 100% var(--tab-height) linear-gradient( to bottom, transparent, rgba(0,0,50,.05)), #D3E2FD;
  background-attachment: local; 
  max-height: calc(100dvh - var(--control-bar-height) - var(--page-content-height) );
  overflow: hidden auto;
  overscroll-behavior-y: none;  
}

.tab{
  --favicon-content: "A";
  --favicon-hue: 0;
  border:none;
  height:var(--tab-height);
  padding:0 4px;
  display:flex;
  align-items:center;
  justify-content:center;
  background:none;
  overflow:hidden;
  max-width:200px;
  animation: show-tab 200ms ease;
  flex:1 0 auto;
  max-width: var(--tab-max-width);
  color: var(--color-text-dark);

  &:last-child{
    background:#fff;
    border-radius: 10px 10px 0 0;
    z-index:1;
    position:sticky;
    bottom:0;
  }

  &:not(:first-child, :last-child):before{
    content:'';
    width:1px;
    height: 32px;
    background: var(--color-tab-hover);
    position:absolute;
    left:0;
    border-radius:1px;
  }


}
.tab:not(:last-child):has(:focus,:hover) .tab-content{
  background: var(--color-tab-hover);
}

.tab-content{
  display:flex;
  align-items:center;
  justify-content:center;
  padding:6px 8px;
  border-radius:6px;
  width:100%;

  //favicon
  &:before{
    content: var(--favicon-content);
    width:16px;
    height:16px;
    background: linear-gradient(to bottom right, hsl( calc( var(--favicon-hue) + 30) 50% 70%), hsl( var(--favicon-hue) 50% 50%) );
    display:inline-block;
    margin-right:8px;
    border-radius:3px;
    display:inline-flex;
    align-items:center;
    justify-content:center;
    color:hsl( var(--favicon-hue) 50% 85%);
    font-size:10px;
    font-weight:600;
    line-height:10px;
    flex:none;
    text-transform:uppercase;
  }

  .tab-text{
    overflow:hidden;
    text-wrap:nowrap;
    text-overflow:ellipsis;
    font-size:14px;
    height:16px;
    line-height:1;
  }

  .button-close{
    margin-left:8px;
    border-radius:100%;
    width:20px;
    height:20px;
    border:none;
    background:none;
    flex:none;
    margin-left:auto;
    background-position: center center;
    background-repeat: no-repeat;
    background-image: url("data:image/svg+xml,%3Csvg width='12' height='12' viewBox='0 0 12 12' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M9.5 3.205L8.795 2.5L6 5.295L3.205 2.5L2.5 3.205L5.295 6L2.5 8.795L3.205 9.5L6 6.705L8.795 9.5L9.5 8.795L6.705 6L9.5 3.205Z' fill='black'/%3E%3C/svg%3E%0A");    
  }

  .button-close:hover{
    background-color: rgba(0,0,0,.1);
  }
}

.page-content{
  height:var(--page-content-height);
  font-size:clamp(2.5rem, 6vw, 6rem);
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  flex:1 1 auto;
  position:relative;
}

.app-name{
  display:block;
  font-weight:700;
  margin-bottom:.125em;

  .char:nth-child(1n){
    color:var(--color-blue);
  }
  .char:nth-child(2n){
    color:var(--color-red);
  }  
  .char:nth-child(3n){
    color:var(--color-yellow);
  }    
  .char:nth-child(4n){
    color:var(--color-green);
  }
  .char:nth-child(5n){
    color:var(--color-red);
  }    
}

.app-summary{
  font-size:.375em;
  font-weight:300;
  opacity:.75
}

.toast{
  position:absolute;
  top:1rem;
  border:2px solid var(--color-green);
  background:var(--color-green-light);
  padding:1rem;
  border-radius:6px;
  color:var(--color-green-dark);
  width:auto;
  max-width:75%;
  left:50%;
  text-align:center;
  box-shadow: 2px 3px 8px rgba(0,0,0,.15);
  display:none;

  &.show-toast{
    display:block;
    animation: show-toast 500ms ease;
    animation-fill-mode:forwards;
  }

}

//aniamtions

@keyframes show-tab {
  0%{
    opacity:0;
  }
  100%{
    opacity:1;
  }  
}

@keyframes counter-zero{
  50%{
    scale:1.25;
  }

  100%{
    rotate:-360deg;
  }
}

@keyframes show-toast{
  0%{
    opacity:0;
    scale:.9;
    translate: -50% -50%;
    // rotate:3deg;
  }
  70%{
    translate: -50% 20%;
    scale:1.25 1.125;
  }

  100%{
    opacity:1;
    translate: -50% 0;
    scale:1;
  }  
}
              
            
!

JS

              
                const textInput = document.querySelector('.text-input');
const generateButton = document.querySelector('.button-auto-generate');
const closeAllButton = document.querySelector('.button-close-all');
const tabCounter = document.querySelector('.tab-counter');
const tabBar = document.querySelector('.tab-bar');
const toast = document.querySelector('.toast');
const maxCharLength = 10;
const toastMessages = [
  "Tab zero achieved",
  "That's better",
  "All gone",
  "Goodbye, tabs"
];
const businessTabs = [
  "Synergy",
  "Paradigm Shift",
  "Think Outside the Box",
  "Leveraging Innovation",
  "Holistic Solutions",
  "Value-Added Services",
  "Core Competencies",
  "Seamless Integration",
  "Disruptive Technology",
  "Ecosystem Approach",
  "Digital Transformation",
  "Agile Frameworks",
  "Scalable Solutions",
  "ROI-Driven Strategies",
  "End-to-End Services",
  "360-Degree Solutions",
  "Streamlined Processes",
  "Cutting-Edge Technology",
  "Best-in-Class Services",
  "Future-Forward Thinking",
  "Results-Oriented Approach",
  "Customer-Centric Solutions",
  "Blue Sky Thinking",
  "Operational Excellence",
  "Global Reach",
  "Game-Changing Strategies",
  "Growth Hacking",
  "Industry-Leading Innovation",
  "Visionary Leadership",
  "Collaborative Ecosystem",
  "Mission-Critical Services",
  "Data-Driven Decisions",
  "Disruptive Innovation",
  "Business Intelligence",
  "Next-Gen Technology",
  "Thought Leadership",
  "Tailored Solutions",
  "High-Impact Deliverables",
  "Outcome-Oriented Results",
  "Performance Optimization",
  "Business Agility",
  "Strategic Partnerships",
  "Enhanced Productivity",
  "Proven Track Record",
  "Transformational Growth",
  "Operational Agility",
  "Big Picture Thinking",
  "Smart Solutions",
  "Experience-Driven Design",
  "Breakthrough Insights",
  "Cross-Functional Expertise",
  "Simplified Complexities",
  "Rapid Deployment",
  "Unified Communications",
  "Enterprise Solutions",
  "Frictionless Experiences",
  "On-the-Ground Expertise",
  "Maximizing Potential",
  "Quality-Driven Outcomes",
  "Customized Approaches",
  "Innovative Roadmaps",
  "Business Empowerment",
  "Seamless Collaboration",
  "Measurable Impact",
  "Turning Vision into Reality",
  "Continuous Improvement",
  "Unlocking Possibilities",
  "Data-Powered Insights",
  "Optimized Resources",
  "Visionary Execution",
  "Agile Mindsets",
  "Sustainability-Driven",
  "Resilient Strategies",
  "Proven Solutions",
  "The Digital Frontier",
  "Customer-First Approach",
  "Real-Time Insights",
  "Dynamic Ecosystems",
  "Transformative Experiences",
  "Strategic Visioning",
  "Robust Architecture",
  "Driving Innovation",
  "Empowered Teams",
  "Fast-Track Growth",
  "Reimagining the Future",
  "Integrated Experiences",
  "Business Reinvention",
  "Turning Challenges into Opportunities",
  "Precision Execution",
  "Disruption-Ready Models",
  "Future-Ready Infrastructure",
  "Intelligent Design",
  "Efficiency Maximization",
  "Experience-Led Solutions",
  "Converging Technologies",
  "Powering Possibilities",
  "Digital Acceleration",
  "Competitive Differentiation",
  "Beyond Expectations",
  "Scaling Success"
];

//utilities
function getRandomInt(max) {
  return Math.floor(Math.random() * max);
}

//toast stuff
function showToast() {
  const message = toastMessages[getRandomInt(toastMessages.length)];
  toast.innerHTML = message;
  toast.classList.add('show-toast');
  setTimeout(hideToast, 3000);
}

function hideToast() {
  toast.classList.remove('show-toast');
}

//manage control states to dom collisions

function setControlsDisabledAttr(bool){
  textInput.disabled = bool;
  closeAllButton.disabled = bool;
  generateButton.disabled = bool;
}

//tab stuff

function updateTabCounter(number) {
  tabCounter.setAttribute('data-count', number)
  if(number == 0){
    tabCounter.innerHTML = ":)";
    showToast();
  }
  else{
    tabCounter.innerHTML = number;
  }
}

function closeTab(tab) {
  tab.parentElement.removeChild(tab);
  updateTabCounter(tabBar.childElementCount);
}


function createTab(text) {

  if (text) {
    // create a browser tab element
    const tab = document.createElement('button');
    tab.className = "tab"
    tab.style.setProperty("--favicon-content", `'${text.slice(0,1)}'` );
    tab.style.setProperty("--favicon-hue", getRandomInt(360) );        
    tab.addEventListener('click', () => closeTab(tab), true);

    const tabContent = document.createElement('div');
    tabContent.className = "tab-content"

    const tabText = document.createElement('div');
    tabText.className = "tab-text"
    tabText.textContent = text;

    const closeButton = document.createElement('div');
    closeButton.className = "button-close";

    tabContent.appendChild(tabText);          
    tabContent.appendChild(closeButton);
    tab.appendChild(tabContent);
    tabBar.appendChild(tab);
  }

  // scroll the container to the bottom in case it broke lines
  tabBar.scrollTop = tabBar.scrollHeight;

  // update counter
  updateTabCounter(tabBar.childElementCount);
}

function closeAllTabs(){
  setControlsDisabledAttr(true);
  const allTabs = tabBar.querySelectorAll('.tab');

  //do interval stuff
  let curTabIndex = allTabs.length;
  function handleInterval(){
    --curTabIndex;
    if (curTabIndex >= 0) {
      closeTab(allTabs[curTabIndex]);      
    }
    else{
      clearInterval(deletionInterval);
      setControlsDisabledAttr(false);
    }
  }

  let deletionInterval = setInterval(handleInterval, 100);  
}

function createTabsFromArray(array){
  setControlsDisabledAttr(true);

  //shuffle the array
  const shuffledTabs = array.sort(() => 0.5 - Math.random());

  //get a subset of the array
  let selectedTabs = shuffledTabs.slice(0, 6);

  //do interval stuff
  let curTabIndex = -1;
  function handleInterval(){
    ++curTabIndex;
    if (curTabIndex <= selectedTabs.length) {
      createTab(selectedTabs[curTabIndex]);
    }
    else{
      clearInterval(creationInterval);
      setControlsDisabledAttr(false);
    }
  }

  let creationInterval = setInterval(handleInterval, 200);
}

//init a bunch of listeners

textInput.addEventListener('keypress', (e) => {
  const text = textInput.value.trim();

  //handle enter 
  if (e.key === 'Enter') {  
    createTab(text);
    e.preventDefault();
    textInput.value = '';    
  }

  //handle space
  if (e.key === ' ' && text.length >= maxCharLength) {
    createTab(text);
    e.preventDefault();
    textInput.value = '';    
  }
});

generateButton.addEventListener('click', () => {
  createTabsFromArray(businessTabs);
  hideToast();
});

closeAllButton.addEventListener('click', closeAllTabs, false);

//start with some default tabs
createTabsFromArray(businessTabs);
              
            
!
999px

Console