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="container" id="container-overlay">
  <div></div>
</div>
<header>
  <div class="container">
    <div class="branding">
      <h1>⚡ High voltage snap ⚡</h1>
    </div>
    <nav>
      <ul>
        <li><a href="#" class="active" aria-current="page">Home</a></li>
        <li><a href="#">Oh snap</a></li>
        <li><a href="#">About us</a></li>
        <li><a href="#">Contact</a></li>
      </ul>
    </nav>
  </div>
</header>
<main>
  <div class="overlay-toggle">
    <label>
      <input type="checkbox" id="toggle" /> Toggle overlay
    </label>
  </div>
  <section class="slider">
    <div>
      <img src="https://images.unsplash.com/photo-1583459094467-e0db130c0dea?crop=entropy&cs=srgb&fm=jpg&ixid=M3wzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2OTYzMjE4Njh8&ixlib=rb-4.0.3&q=85" alt="">
    </div>
    <div>
      <img src="https://images.unsplash.com/photo-1529354106868-9d7821ecaac2?crop=entropy&cs=srgb&fm=jpg&ixid=M3wzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2OTYzMjE4Njh8&ixlib=rb-4.0.3&q=85" alt="">
    </div>
    <div>
      <img src="https://images.unsplash.com/photo-1483206048520-2321c1a5fb36?crop=entropy&cs=srgb&fm=jpg&ixid=M3wzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2OTYzMjE4Njh8&ixlib=rb-4.0.3&q=85" alt="">
    </div>
    <div>
      <img src="https://images.unsplash.com/photo-1538169204832-1b461add30a5?crop=entropy&cs=srgb&fm=jpg&ixid=M3wzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2OTYzMjE4Njh8&ixlib=rb-4.0.3&q=85" alt="">
    </div>
    <div>
      <img src="https://images.unsplash.com/photo-1627691747324-fbd7d97b9159?crop=entropy&cs=srgb&fm=jpg&ixid=M3wzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2OTYzMjE4Njh8&ixlib=rb-4.0.3&q=85" alt="">
    </div>
    <div>
      <img src="https://images.unsplash.com/photo-1537036017783-64573b29adb9?crop=entropy&cs=srgb&fm=jpg&ixid=M3wzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2OTYzMjE4Njh8&ixlib=rb-4.0.3&q=85" alt="">
    </div>
    <div>
      <img src="https://images.unsplash.com/photo-1604509458861-9b9d513707b8?crop=entropy&cs=srgb&fm=jpg&ixid=M3wzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2OTYzMjE4Njh8&ixlib=rb-4.0.3&q=85" alt="">
    </div>
    <div>
      <img src="https://images.unsplash.com/photo-1502668298624-d88d773bf034?crop=entropy&cs=srgb&fm=jpg&ixid=M3wzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2OTYzMjE4Njh8&ixlib=rb-4.0.3&q=85" alt="">
    </div>
    <div>
      <img src="https://images.unsplash.com/photo-1559571773-6271bd8fe553?crop=entropy&cs=srgb&fm=jpg&ixid=M3wzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2OTYzMjE4Njh8&ixlib=rb-4.0.3&q=85" alt="">
    </div>
    <div>
      <img src="https://images.unsplash.com/photo-1570379510114-eeb67b4e50e1?crop=entropy&cs=srgb&fm=jpg&ixid=M3wzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2OTYzMjE4Njh8&ixlib=rb-4.0.3&q=85" alt="">
    </div>
  </section>
  <section class="body-text">
    <div class="container">
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras convallis sodales erat vel accumsan. Nam eget massa nec sem vulputate ullamcorper vel quis justo. Duis rhoncus tempor tempus. Nulla facilisi. Maecenas nulla ante, lacinia ac consectetur non, aliquet sollicitudin libero. Quisque congue odio sodales dui fermentum ac laoreet mauris eleifend. Nulla facilisi. Phasellus vel erat a ante pharetra pharetra.</p>
    </div>
  </section>
</main>
<footer>
  <div class="container">
    &copy; Contained snap slider demo by <a href="https://utilitybend.com" target="_blank">utilitybend</a>
  </div>
</footer>
              
            
!

CSS

              
                @layer base, presentation, overlay, layout, components;
@import url("https://fonts.googleapis.com/css2?family=Electrolize&family=Lato:wght@400;700&display=swap");

/* Actual demo styles */

@layer base {
  :root {
    --c-max-width: 100%;
    --c-padding: 10px;
    @media screen and (min-width: 768px) {
      --c-max-width: 800px;
      --c-padding: 12px;
    }
    @media screen and (min-width: 1000px) {
      --c-max-width: 940px;
      --c-padding: 24px;
    }
    @media screen and (min-width: 1200px) {
      --c-max-width: 1200px;
      --c-padding: 40px;
    }
  }
}

@layer layout {
  .container {
    max-width: var(--c-max-width);
    padding-inline: var(--c-padding);
    margin-inline: auto;
  }
}

@layer components {
  .slider {
    --gap: var(--c-padding);
    --flex-width: 300px;
    --offset-width: calc(
      ((100% - (min(var(--c-max-width), 100%) + (var(--c-padding) * 2))) / 2) +
        (var(--c-padding) * 2)
    );

    display: flex;
    gap: var(--gap);
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    padding-inline: var(--offset-width);
    scroll-padding-inline-start: var(--offset-width);
    background: var(--bg-slider);
    > * {
      flex: 0 0 var(--flex-width);
      scroll-snap-align: start;
    }
    & img {
      aspect-ratio: 3 / 4;
      object-fit: cover;
    }
  }
}

/*
  Demo presentation styles
*/

@layer overlay {
  .overlay-toggle {
    background: var(--bg-slider);
    text-align: center;
    padding-block: 8px;
    border-bottom: 1px dashed #666;
    accent-color: var(--color-verdigris);
  }

  #container-overlay {
    display: none;
    position: fixed;
    width: 100%;
    inset-block: 0;
    inset-inline: 0;
    outline: 3px dashed hotpink;
    pointer-events: none;
    &.active {
      display: block;
    }
    > div {
      width: 100%;
      height: 100%;
      outline: 3px dashed deeppink;
    }
  }
}

@layer presentation {
  *,
  *::before,
  *::after {
    box-sizing: border-box;
  }

  body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    color: #fff;
    font-family: "Lato", sans-serif;
    font-size: 1.1rem;
    margin: 0;
    padding: 0;
    line-height: 1.6;
  }

  h1 {
    margin: 0;
  }

  header {
    padding-block: 24px;
    background: #0081a7;
    box-shadow: rgba(0, 0, 0, 0.2) 0px 12px 28px 0px,
      rgba(0, 0, 0, 0.1) 0px 2px 4px 0px,
      rgba(255, 255, 255, 0.05) 0px 0px 0px 1px inset;
    .container {
      display: flex;
      flex-direction: column;
      align-items: center;
      @media screen and (min-width: 768px) {
        flex-direction: row;
        justify-content: space-between;
        gap: 50px;
      }
    }
  }

  .branding {
    font-family: "Electrolize", sans-serif;
    display: flex;
    align-items: center;
    gap: 20px;
    color: var(--color-orange);
    & h1 {
      margin: 0;
      font-size: 1.6rem;
      @media screen and (min-width: 500px) {
        font-size: 2rem;
      }
    }
  }

  nav ul {
    display: flex;
    gap: 15px;
    margin-block: 15px 0;
    margin-inline: 0;
    padding: 0;
    list-style: none;
    font-size: 1rem;
    @media screen and (min-width: 1000px) {
      margin-block-start: 0;
      font-size: 1.4rem;
    }
  }

  a {
    color: var(--color-orange);
    text-decoration: none;
    transition: color 0.24s;
    &:is(:hover, :focus) {
      color: var(--color-lightest);
    }
    &.active {
      color: var(--color-lightest);
      text-decoration: underline;
    }
  }

  p {
    margin-block-start: 0;
  }

  section {
    padding-block: 60px 40px;
  }

  img {
    display: block;
    width: 100%;
    max-width: 100%;
  }

  main {
    flex: 1;
    background: #3c3c3b;
  }

  footer {
    background: var(--color-verdigris);
    padding: 20px 0;
    text-align: center;
    color: #333;
  }

  .body-text {
    padding-block: 60px 40px;
  }
  .slider {
    &::-webkit-scrollbar {
      height: 8px;
    }

    &::-webkit-scrollbar-track {
      background: #5d4e6d;
    }

    &::-webkit-scrollbar-thumb {
      background: var(--color-orange);
    }

    &::-webkit-scrollbar-thumb:hover {
      background: var(--color-yellow);
    }
  }
}

@layer base {
  :root {
    --color-orange: #fed9b7;
    --color-yellow: #fdfcdc;
    --color-verdigris: #00afb9;
    --color-cerulean: #0081a7;
    --color-lightest: #fff;
    --bg-slider: #161032;
  }
}

              
            
!

JS

              
                const container = document.getElementById("container-overlay");
const toggleCheckbox = document.getElementById("toggle");

toggleCheckbox.addEventListener("click", () => {
  container.classList.toggle("active");
});

              
            
!
999px

Console