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="ff-banner">
  Scrolling in Firefox may be broken because of a <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1737820">scroll-snap bug</a>. Fix has been pushed to Firefox Nightly and should be released soon.
</div>
<main class="content">
  <h1 class="headline">Horizontal scrolling in a centered max-width container</h1>
  <p>A boneless carousel is a popcorn of the mind. Extending this logic, the literature would have us believe that a crumby afternoon is not but a cave. A delivery can hardly be considered an attack luttuce without also being a triangle. This could be, or perhaps one cannot separate weapons from breathing cushions.</p>

  <div class="gallery">
    <div class="wrapper">
      <div class="item">1</div>
      <div class="item">2</div>
      <div class="item">3</div>
      <div class="item">4</div>
      <div class="item">5</div>
      <div class="item">6</div>
      <div class="item">7</div>
      <div class="item">8</div>
      <div class="item">9</div>
      <div class="item">10</div>
      <div class="item">11</div>
      <div class="item">12</div>
      <div class="item">13</div>
      <div class="item">14</div>
      <div class="item">15</div>
      <div class="item">16</div>
    </div>
  </div>

  <p>A mole is a bulldozer's brush. Ships are alright errors. They were lost without the corny lamb that composed their carbon. Extending this logic, the sidelong children comes from a drifting sunbeam.</p>

  <div class="gallery alt-sizes">
    <div class="wrapper">
      <div class="item">
        <img src="https://picsum.photos/id/25/650/365" alt="" />
      </div>
      <div class="item lg">
        <img src="https://picsum.photos/id/10/650/365" alt="" />
      </div>
      <div class="item">
        <img src="https://picsum.photos/id/50/650/365" alt="" />
      </div>
      <div class="item sm">
        <img src="https://picsum.photos/id/466/650/365" alt="" />
      </div>
      <div class="item sm">
        <img src="https://picsum.photos/id/888/650/365" alt="" />
      </div>
      <div class="item">
        <img src="https://picsum.photos/id/25/650/365" alt="" />
      </div>
      <div class="item lg">
        <img src="https://picsum.photos/id/77/650/365" alt="" />
      </div>
      <div class="item">
        <img src="https://picsum.photos/id/42/650/365" alt="" />
      </div>
      <div class="item lg">
        <img src="https://picsum.photos/id/98/650/365" alt="" />
      </div>
      <div class="item">
        <img src="https://picsum.photos/id/440/650/365" alt="" />
      </div>
      <div class="item sm">
        <img src="https://picsum.photos/id/111/650/365" alt="" />
      </div>
      <div class="item">
        <img src="https://picsum.photos/id/250/650/365" alt="" />
      </div>
    </div>
  </div>

  <p>In ancient times authors often misinterpret the approval as an enarched spleen, when in actuality it feels more like a feeling bone. The zeitgeist contends that those cautions are nothing more than brokers. A trip of the metal is assumed to be a classless trouser. The septembers could be said to resemble unplumbed breaths.</p>

  <p>An incurved health's leopard comes with it the thought that the chichi peak is a sauce. One cannot separate tortellinis from ain laborers. A credit is the effect of a tub. Some stilted needs are thought of simply as fiberglasses.</p>

  <div class="gallery rtl">
    <div class="wrapper">
      <div class="item">1</div>
      <div class="item">2</div>
      <div class="item">3</div>
      <div class="item">4</div>
      <div class="item">5</div>
      <div class="item">6</div>
      <div class="item">7</div>
      <div class="item">8</div>
      <div class="item">9</div>
      <div class="item">10</div>
      <div class="item">11</div>
      <div class="item">12</div>
      <div class="item">13</div>
      <div class="item">14</div>
      <div class="item">15</div>
      <div class="item">16</div>
    </div>
  </div>

  <p>The first faithless feeling is, in its own way, an hour. Some posit the prewar rocket to be less than keyless. In modern times a dinkies ocean without hydrofoils is truly a course of detached sticks. What we don't know for sure is whether or not authors often misinterpret the squash as a balanced writer, when in actuality it feels more like an uncapped buffet.</p>
</main>
              
            
!

CSS

              
                body {
  --space: 1rem;
  --space-md: calc(var(--space) * 2);
  --content-max-width: 60ch;

  font-family: sans-serif;
  font-size: 1.2rem;
  line-height: 1.5;
}

.rtl {
  direction: rtl;
}

main {
  margin-block: 6rem;
}

.content {
  display: grid;
  grid-template-columns:
    [full-start] 1fr
    [content-start]
    min(var(--content-max-width), 100% - var(--space-md) * 2)
    [content-end]
    1fr [full-end];
}

.content > * {
  grid-column: content;
}

.content > * + * {
  margin-block-start: var(--space);
}

.headline {
  margin-block-end: var(--space-md);
  font-family: "Palatino";
  font-size: clamp(2rem, 6vw, 3.5rem);
  font-weight: bold;
  line-height: 1.125;
  letter-spacing: -0.015em;
}

.gallery {
  grid-column: full;
  display: grid;
  grid-template-columns: inherit;
  padding-block: var(--space-md);
  overflow-x: scroll;
  overscroll-behavior-x: contain;
  scroll-snap-type: x proximity;
  scrollbar-width: none;
}

.gallery::-webkit-scrollbar {
  inline-size: 0 !important;
  display: none;
}

.gallery .wrapper {
  grid-column: content;
  display: flex;
  align-items: center;
  gap: var(--space);
}

.gallery .wrapper::after {
  content: "";
  align-self: stretch;
  padding-inline-end: max(
    var(--space),
    (100vw - var(--content-max-width)) / 2 - var(--space)
  );
}

.gallery .item {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  scroll-snap-align: center;
  inline-size: 100%;
  max-inline-size: 25rem;
  aspect-ratio: 16 / 9;
  font-size: 2rem;
  background: hotpink;
  border-radius: 4px;
  overflow: hidden;
}

.gallery.alt-sizes .item.lg {
  max-inline-size: 35rem;
}

.gallery.alt-sizes .item.sm {
  max-inline-size: 15rem;
}

.gallery img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

@supports not (aspect-ratio: 1) {
  .gallery .item::before {
    float: left;
    padding-top: 56.25%;
    content: "";
  }

  .gallery .item::after {
    display: block;
    content: "";
    clear: both;
  }
}

.ff-banner {
  display: none;
}

@-moz-document url-prefix() {
  .ff-banner {
    display: block;
    padding: var(--space);
    background-color: lightyellow;
    text-align: center;
    font-size: 0.9rem;
  }
}

              
            
!

JS

              
                
              
            
!
999px

Console