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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <h1>Pure CSS3 Tabs using :target</h1>

<div id="tabs">
    <span id="tab-1" class="tab-switch"></span>
    <a href="#tab-1" class="tab-link">Tab 1</a>
    <div class="tab-content">
        <h2>Lorem ipsum</h2>
        <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Alias amet commodi cupiditate molestias laboriosam sit! Delectus magni esse magnam libero laboriosam aspernatur voluptates, natus aliquid sed doloremque architecto provident, impedit saepe. Mollitia eum qui, quae laboriosam, magni aut similique asperiores error dicta totam ad, deserunt nemo repudiandae maxime, expedita. Id, numquam, laboriosam. Voluptatibus, saepe! Eligendi assumenda ullam modi explicabo voluptas qui veniam repellat ipsam similique dolore, mollitia quam dolores quae cumque neque officia. Laudantium, ratione sint quo molestiae sapiente dolores, doloremque modi illo quia tempora asperiores ullam perspiciatis fuga quasi maxime nesciunt ab suscipit harum quam. Eligendi dicta suscipit dolorum.</p>
    </div>

    <span id="tab-2" class="tab-switch"></span>
    <a href="#tab-2" class="tab-link">Tab 2</a>
    <div class="tab-content">
        <h2>Lorem list</h2>
        <ul>
           <li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li>
           <li>Aliquam tincidunt mauris eu risus.</li>
           <li>Vestibulum auctor dapibus neque.</li>
        </ul>
    </div>

    <span id="tab-3" class="tab-switch"></span>
    <a href="#tab-3" class="tab-link">Tab 3</a>
    <div class="tab-content">
        <h2>Yolo</h2>
        <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p>
    </div>
</div>

<footer>Supported since IE9. Enjoy!</footer>
              
            
!

CSS

              
                /* MAGIC ... IMPORTANT! */
#tabs::after {
    display: block;
    content: "";
    clear: both;
}

.tab-switch {
    // prevents scrolling to #target
    position: fixed;

    &:target {
        + .tab-link {
            + .tab-content {
                display: block;
            }
        }
    }
}

.tab-link {
    display: inline-block;
}

.tab-content {  
    box-sizing: border-box;

    float: right;

    display: none;
    width: 100%;
}



/* FANCY STYLES */
body {
    font-family: sans-serif;

    padding: 10px 100px;
}

h1 {
    text-align: center;
}

footer {
    margin-top: 20px;

    text-align: center;
}

#tabs {
    background-color: #1caa5d;
    border: 1px solid #1caa5d;

    font-size: 0;
}

.tab-link {
    margin-left: 20px;
    margin-top: 10px;
    padding: 20px;

    text-decoration: none;
    font-size: 18px;

    color: white;

    &:hover {
        background-color: white;
        color: black;
    }

    ~ .tab-link {
        margin-left: 0;
    }
}

.tab-switch {
    &:target {
        + .tab-link {
            background-color: white;
            color: black;
        }
    }
}

.tab-content {
    background-color: white;

    padding: 35px;

    font-size: 13px;

    p {
        line-height: 1.65;
    }

    ul, ol {
        padding: 0 0 0 15px;
        margin: 0;

        line-height: 1.25;

        > li {
            margin: 5px 0;
        }
    }
}

              
            
!

JS

              
                /*

NO JS REQUIRED!!!

... well, you could need JS for selecting first tab

... or include its hash in the URL



here ... simple JS to select 1.tab if there is nothing in the URL ... include it before </body> 
*/
(function() {
    if (!!location.hash) return;

    var link = document.querySelector('#tabs > .tab-link');
    if (link) link.click();
})();
              
            
!
999px

Console