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

              
                <!-- https://creativecommons.org/licenses/by-sa/4.0/ -->

<header>

    <h2>Header</h2>

    <nav>
        <ul>
            <li><a href="#">Nav 1</a></li>
            <li><a href="#">Nav 2</a></li>
            <li><a href="#">Nav 3</a></li>
            <li><a href="#">Nav 4</a></li>
            <li><a href="#">Nav 5</a></li>
            <li><a href="#">Nav 6</a></li>
            <li><a href="#">Nav 7</a></li>
            <li><a href="#">Nav 8</a></li>
            <li><a href="#">Nav 9</a></li>
            <li><a href="#">Nav 10</a></li>
        </ul>
    </nav>

</header>
<main>

    <h1>Scroll-Margin Prototype (not fully supported)</h1>

    <p>To see the scroll-margin in action: TAB down to the bottom of the page, and then start to SHIFT+TAB back up again. When keyboard focus reaches the bottom of the header, the scroll position of focused elements is constrained to the bottom of the header (where supported).</p>

    <ul>
        <li><a href="#">Link 1</a></li>
        <li><a href="#">Link 2</a></li>
        <li><a href="#">Link 3</a></li>
        <li><a href="#">Link 4</a></li>
        <li><a href="#">Link 5</a></li>
        <li><a href="#">Link 6</a></li>
        <li><a href="#">Link 7</a></li>
        <li><a href="#">Link 8</a></li>
        <li><a href="#">Link 9</a></li>
        <li><a href="#">Link 10</a></li>
        <li><a href="#">Link 11</a></li>
        <li><a href="#">Link 12</a></li>
        <li><a href="#">Link 13</a></li>
        <li><a href="#">Link 14</a></li>
        <li><a href="#">Link 15</a></li>
        <li><a href="#">Link 16</a></li>
        <li><a href="#">Link 17</a></li>
        <li><a href="#">Link 18</a></li>
        <li><a href="#">Link 19</a></li>
        <li><a href="#">Link 20</a></li>
        <li><a href="#">Link 21</a></li>
        <li><a href="#">Link 22</a></li>
        <li><a href="#">Link 23</a></li>
        <li><a href="#">Link 24</a></li>
        <li><a href="#">Link 25</a></li>
        <li><a href="#">Link 26</a></li>
        <li><a href="#">Link 27</a></li>
        <li><a href="#">Link 28</a></li>
        <li><a href="#">Link 29</a></li>
        <li><a href="#">Link 30</a></li>
    </ul>

</main>

              
            
!

CSS

              
                :root {
    font-family: sans-serif;
    font-size: 1.2em;
}
html, body {
    background: #fff;
    margin: 0;
    color: #444;
}
ul, li {
    list-style: none;
    margin: 0;
    padding: 0;
}
a:focus {
    outline: 2px solid #05f;
    outline-offset: 2px;
}

header {
    background: #fec;
    border: 2px solid #f60;
    box-sizing: border-box;
    left: 0;
    padding: 1rem;
    position: sticky;
    top: 0;
    width: 100%;
}
header h2 {
    font-weight: normal;
    margin: 0 0 1rem 0;
}
header nav,
header nav ul,
header nav li {
    display: flex;
    flex-wrap: wrap;
}
header nav a {
    background: #fff;
    border: 2px solid #f60;
    color: #05f;
    display: block;
    margin: 0 2px 2px 0;
    padding: 0.4rem 0.7rem;
    position: relative;
    z-index: 0;
}
header nav a:focus {
    z-index: 1;
}

main {
    padding: 2rem;
}
main h1 {
    font-weight: normal;
    margin: 0 0 1rem 0;
}
main p {
    line-height: 1.5;
    margin: 0 0 1rem 0;
}
main a {
    background: #eee;
    border: 2px solid #666;
    color: #05f;
    display: inline-block;
    margin: 0 0 6px 0;
    min-width: 4rem;
    padding: 0.4rem 0.7rem;
}

              
            
!

JS

              
                window.addEventListener('DOMContentLoaded', () => {

    if(!!!('ResizeObserver' in window)) { return; }

    const header = document.querySelector('header');
    const style = document.head.appendChild(document.createElement('style'));
    const stylesheet = style.sheet;

    const applyScrollMargin = () => {

        while(stylesheet.cssRules.length) {
            stylesheet.deleteRule(0);
        }

        let height = header.offsetHeight + 6;
        stylesheet.insertRule(`main *:focus { scroll-margin-top:${height}px }`);

        //this catches changes in header height while an element is already focused
        let focused = document.activeElement || document.body;
        if(focused !== document.body && !header.contains(focused)) {
            if(focused.getBoundingClientRect().top < height) {
                focused.scrollIntoView();
            }
        }
    };

    (new ResizeObserver(applyScrollMargin)).observe(header);

});

              
            
!
999px

Console