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

              
                <header>
  <h1>Demo of Scroll-Snapping</h1>
  <nav>
    <a href="#type">type</a>
    <a href="#align">align</a>
    <a href="#padding">padding</a>
    <a href="#margin">margin</a>
    <a href="#stop">stop</a>
  </nav>
</header>
<section>
<article id="type">
  <h2>Scroll Snap Type</h2>
  <p>Apply to the <strong>scrolling container</strong></p>
  <ul>
    <li>
      creates a scroll-snapping <strong>context</strong>
    </li>
    <li>
      required <strong>axis</strong>: [ 
      <code>x</code> | 
      <code>y</code> | 
      <code class="logical">block</code> | 
      <code class="logical">inline</code> | 
      <code>both</code> 
      ]
    </li>
    <li>
      optional <strong>strictness</strong>:
      [ 
      <code>*proximity</code> | 
      <code>mandatory</code> 
      ]
    </li>
    <li>
      Use on <code>html</code> for viewport scrolling
    </li>
  </ul>
</article>
<article id="align">
  <h2>Scroll Snap Align</h2>
  <p>Apply to any <strong>scrolled elements</strong></p>
  <ul>
    <li>
      creates a scroll-snapping <strong>target</strong>
    </li>
    <li>
      keywords: [ 
      <code>none</code> | 
      <code>start</code> | 
      <code>end</code> | 
      <code>center</code> 
      ]{1,2}
    </li>
  </ul>
</article>
<article id="padding">
  <h2>Scroll Padding</h2>
  <p>Apply to the <strong>scrolling container</strong></p>
  <ul>
    <li>
      narrows the available <strong>scroll-window</strong>
    </li>
    <li>
      same syntax as <code>padding</code>
    </li>
    <li>
      works for all scroll-to actions, not just snapping
    </li>
  </ul>
</article>
<article id="margin">
  <h2>Scroll Margin</h2>
  <p>Apply to any <strong>scrolled elements</strong></p>
  <ul>
    <li>
      <strong>offset target</strong> from available scroll-window
    </li>
    <li>
      same syntax as <code>margin</code>
    </li>
    <li>
      works for all scroll-to actions, not just snapping
    </li>
  </ul>
</article>
<article id="stop">
  <h2>Scroll Snap Stop</h2>
  <p>Apply to any <strong>scrolled elements</strong></p>
  <ul>
    <li>
      optionally <strong>stop inertial</strong> scrolling
    </li>
    <li>
      keywords: [ 
      <code class="stop">normal</code> | 
      <code class="stop">always</code> 
      ]
    </li>
    <li>
      works for all scroll-to actions, not just snapping
    </li>
  </ul>
</article>  
<article>
  <h2>page 6</h2>  
</article>
<article>
  <h2>page 7</h2>  
</article>
<article>
  <h2>page 8</h2>  
</article>
<article>
  <h2>page 9</h2>  
</article>
<article>
  <h2>page 10</h2>  
</article>
<article class="large">
  <h2>page 11</h2>  
</article>
<article>
  <h2>page 12</h2>  
</article>
</section>

              
            
!

CSS

              
                html {
  scroll-snap-type: block mandatory;
  scroll-padding: 4.25em;
}

header { 
  position: sticky;
  top: 0;
}

article {
  scroll-snap-align: start;
  scroll-margin-top: 1em;
}

.large {
  height: 200vh;
}

/* 
html {
  scroll-snap-type: both mandatory;
}

article {
  scroll-snap-align: center;
}

section {
  grid: auto-flow / repeat(3, 80vw);
}
 */
@layer setup {
  * { box-sizing: border-box; }

  html {
    background: snow;
    font-family: sans-serif;
    font-size: calc(1.2em + 0.25vw);
    height: 100%;
  }
  
  body {
    margin: 0;
    min-height: 100%;
    display: grid;
    grid-template: auto minmax(0, 1fr) / 1fr;
  }

  @media not (prefers-reduced-motion:reduce) {
    main { scroll-behavior: smooth; }
  }

  section {
    display: grid;
    grid-auto-rows: minmax(50vh, max-content);
    grid-gap: 1em;
    padding: 1em;
  }

  header {
    background: lightgray;
    scroll-snap-align: start;
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    grid-area: 1 / 1 / span 1 / -1;
    justify-content: space-between;
    padding: 1em;
  }

  nav {
    display: flex;
    justify-content: space-evenly;
  }

  nav a {
    display: inline-block;
    padding: 0.25em 0.5em;
  }

  article {
    background: white;
    border: 2px solid gray;
    display: grid;
    align-content: center;
    justify-content: center;
    padding: 1em 2em;
  }

  h1, h2 {
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }

  ul {
    margin: 0.5em 0;
    padding: 0.25em 0;
  }

  ul ul {
    padding-left: 1em;
  }

  li {
    padding: 0.25em 0;
  }

  .bug {
    background: pink;
  }

  code {
    display: inline-block;
    background: #eee;
    padding: 0.125em 0.25em;
  }
}

              
            
!

JS

              
                
              
            
!
999px

Console