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

              
                <h1 class="main-heading">Tabs</h1>
    <div class="wrap">
        <ul class="tab-list__list">
            <li class="tab-list__item"><a href="#tab-1" class="tab-list__link tab-list__link--is-active">Phones</a></li>
            <li class="tab-list__item"><a href="#tab-2" class="tab-list__link">Indoors</a></li>
            <li class="tab-list__item"><a href="#tab-3" class="tab-list__link">Outdoors</a></li>
        </ul>
        <div class="tab">
            <ul id="tab-1" class="tab__box tab__box--1 tab__box--is-visible">
                <li class="tab__item">
                   <h2 class="tab__heading">Galaxy</h2>
                   <i class="tab__icon fa fa-android"></i> 
                   <p class="tab__para">$499</p>
                   <button class="tab__btn">buy now</button>
                </li>
                <li class="tab__item">
                   <h2 class="tab__heading">iPhone</h2>
                   <i class="tab__icon fa fa-apple"></i> 
                   <p class="tab__para">$800</p>
                   <button class="tab__btn">buy now</button>
                </li>
                <li class="tab__item">
                   <h2 class="tab__heading">Pixel</h2>
                   <i class="tab__icon fa fa-google"></i> 
                   <p class="tab__para">$600</p>
                   <button class="tab__btn">buy now</button>
                </li>
                <li class="tab__item">
                   <h2 class="tab__heading">Standard</h2>
                   <i class="tab__icon fa fa-phone"></i> 
                   <p class="tab__para">$50</p>
                   <button class="tab__btn">buy now</button>
                </li>
            </ul>
            <ul id="tab-2" class="tab__box tab__box--1">
                <li class="tab__item">
                   <h2 class="tab__heading">Pencil</h2>
                   <i class="tab__icon fa fa-pencil"></i> 
                   <p class="tab__para">$.19</p>
                   <button class="tab__btn">buy now</button>
                </li>
                <li class="tab__item">
                   <h2 class="tab__heading">Lock</h2>
                   <i class="tab__icon fa fa-lock"></i> 
                   <p class="tab__para">$8</p>
                   <button class="tab__btn">buy now</button>
                </li>
                <li class="tab__item">
                   <h2 class="tab__heading">Microphone</h2>
                   <i class="tab__icon fa fa-microphone"></i> 
                   <p class="tab__para">$59</p>
                   <button class="tab__btn">buy now</button>
                </li>
                <li class="tab__item">
                   <h2 class="tab__heading">Floppy Disk</h2>
                   <i class="tab__icon fa fa-save"></i> 
                   <p class="tab__para">$1.99</p>
                   <button class="tab__btn">buy now</button>
                </li>
            </ul>
            <ul id="tab-3" class="tab__box tab__box--1">
                <li class="tab__item">
                   <h2 class="tab__heading">Bicycle</h2>
                   <i class="tab__icon fa fa-bicycle"></i> 
                   <p class="tab__para">$300</p>
                   <button class="tab__btn">buy now</button>
                </li>
                <li class="tab__item">
                   <h2 class="tab__heading">Binoculars</h2>
                   <i class="tab__icon fa fa-binoculars"></i> 
                   <p class="tab__para">$72</p>
                   <button class="tab__btn">buy now</button>
                </li>
                <li class="tab__item">
                   <h2 class="tab__heading">Basketball</h2>
                   <i class="tab__icon fa fa-dribbble"></i> 
                   <p class="tab__para">$39</p>
                   <button class="tab__btn">buy now</button>
                </li>
                <li class="tab__item">
                   <h2 class="tab__heading">Fighter Jet</h2>
                   <i class="tab__icon fa fa-fighter-jet"></i> 
                   <p class="tab__para">call us</p>
                   <button class="tab__btn">buy now</button>
                </li>
            </ul>
        </div>    
    </div>
    
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Montserrat:300,300i,400,700,700i');

:root {
    box-sizing: border-box;
}

*,
::before,
::after {
    box-sizing: inherit;
    text-decoration: none;
    list-style-type: none;
    margin: 0;
    padding: 0;
}

body {
    margin: 0 auto;
    font-family: 'Montserrat', sans-serif;
    font-size: 100%;
    padding: 3em;
    width: 80%;
    max-width: 75em;
    background: linear-gradient(to right, rgb(96, 108, 136), rgb(63, 76, 107)); 
}

/*********** MAIN HEADING **********/
.main-heading {
    font-size: 2.2em;
    color: rgb(221, 221, 221);
    text-transform: uppercase;
    font-weight: 400;
    letter-spacing: 1px;
    text-align: center;
    margin: 2em 0;
    display: flex;
    align-items: center;
    white-space: nowrap;
}

.main-heading::before, .main-heading::after {
    content: "";
    height: .2em;
    width: 100%;
    background-image: linear-gradient(to left, rgb(255, 140, 0), transparent);
    margin-right: 1em;
}

.main-heading::after {
   background-image: linear-gradient(to right, rgb(255, 140, 0), transparent);
   margin-left: 1em;
}

/*********** LINKS **********/
.tab-list__list {
    display: flex;
    width: max-content;
}

.tab-list__link {
    color: #fff;
    font-size: .9em;
    text-transform: uppercase;
    background-color: rgb(128, 118, 104);
    display: block;
    padding: .8em 1.5em;
    border-radius: 5px 5px 0 0;
    transition: all 150ms ease-out;
}

.tab-list__link--is-active {
    color: rgb(63, 76, 107);
    background-color: rgb(242, 231, 207);
    background-color: #fff;
    transform: scaleY(1.1);
    transform-origin: center bottom;
}

/*********** TAB CONTAINERS **********/
.tab {
    background-color: rgb(242, 231, 207);
    background-color: #fff;
    border-radius: 0 3px 3px 3px;
    padding: 1.5em;
}

.tab__box {
    display: none;
}

.tab__box--is-visible {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(12em, 1fr));
    grid-gap: 1.5em;
    justify-content: space-around;
}

.tab__item {
    padding: 1.5em;
    text-align: center;
    display: flex;
    flex-direction: column;
}

.tab__heading {
    font-size: 1.6em;
    color: rgb(41, 128, 185);
    margin-bottom: auto;
}

.tab__icon {
    font-size: 3em !important;
    margin: .7em 0;
    color: rgb(255, 140, 0);
}

.tab__para {
    font-weight: bold;
    color: rgb(63, 76, 107);
    margin-bottom: 1.5em;
}

.tab__btn {
    font-size: inherit;
    font-weight: 700;
    text-transform: uppercase;
    font-family: inherit;
    padding: .8em 1.5em; 
    border-radius: 2px;
    border: 0;
    background-image: linear-gradient(to bottom, rgb(52, 152, 219), rgb(41, 128, 185));
    box-shadow: 2px 2px 2px rgba(0,0,0,.6);
    cursor: pointer;
    max-width: 18em;
    margin: 0 auto;
}

.tab__btn:hover {
    background-image: linear-gradient(to bottom, rgb(60, 176, 253), rgb(52, 152, 219));
}

.tab__btn:active {
    transform: translate(1px, 2px);
    box-shadow: 1px 1px 2px rgba(0,0,0,.7);
}

@media (max-width: 42em) {
    body {
        font-size: 90%;
    }
    
    .wrap {
        display: grid;
        grid-template-columns: 1fr 5fr;
    }
    
    .tab-list__list {
        flex-direction: column;
        background-color: rgb(128, 118, 104);
        border-radius: 3px 0 0 3px;
    }
    
    .tab-list__link {
        font-size: .8em;
        padding: .8em 1em;
        border-radius: 5px 0 0 5px;
    }
    
    .tab-list__link--is-active {
        transform: scaleX(1.05);
        transform-origin: right center;
    }
    
    .tab {
        border-radius: 0 3px 3px 0;
        padding: 1em;
    }
    
    
    
}


              
            
!

JS

              
                
let ul = document.querySelector('.tab-list__list');
let links = document.querySelectorAll('.tab-list__link');
let tabs = document.querySelectorAll('.tab__box');

ul.addEventListener('click', (e) => {
    //only apply js if tab isn't already the active one
    if (e.target.classList.contains('tab-list__link') && !e.target.classList.contains('tab-list__link--is-active')) {
        e.preventDefault();
        //loop through all links and divs and remove the active/visible classes
        links.forEach((el, idx) => {
            el.classList.remove('tab-list__link--is-active');
            tabs[idx].classList.remove('tab__box--is-visible');
            //add the active class to the clicked link
            e.target.classList.add('tab-list__link--is-active');
            //if the active link's href attribute matches the div's id attribute (slicing out the #) apply the visible class to that div
            if (e.target.getAttribute('href').slice(1) === tabs[idx].getAttribute('id')) {
                tabs[idx].classList.add('tab__box--is-visible');
            }
        });
    }
});
              
            
!
999px

Console