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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

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>CSS Marquee Examples</h1>
<p>An exploration of responsive marquee-style animations with HTML and CSS for the article <a href="https://ryanmulligan.dev/blog/css-marquee/" target="_blank">The Infinite Marquee</a>.

<section>
  <h2>Full-width (default)</h2>
  <input id="enable-animation-1" type="checkbox" />
  <label for="enable-animation-1">Enable animation</label>

  <div class="marquee">
    <ul class="marquee__content">
      <li>1</li>
      <li>2</li>
      <li>3</li>
      <li>4</li>
      <li>5</li>
      <li>6</li>
    </ul>

    <ul aria-hidden="true" class="marquee__content">
      <li>1</li>
      <li>2</li>
      <li>3</li>
      <li>4</li>
      <li>5</li>
      <li>6</li>
    </ul>
  </div>
</section>

<section>
  <h2>Reverse</h2>
  <input id="enable-animation-2" type="checkbox" />
  <label for="enable-animation-2">Enable animation</label>

  <div class="marquee marquee--reverse">
    <ul class="marquee__content">
      <li>1</li>
      <li>2</li>
      <li>3</li>
      <li>4</li>
      <li>5</li>
      <li>6</li>
    </ul>

    <ul aria-hidden="true" class="marquee__content">
      <li>1</li>
      <li>2</li>
      <li>3</li>
      <li>4</li>
      <li>5</li>
      <li>6</li>
    </ul>
  </div>
</section>

<section>
  <h2>Pause on hover</h2>
  <input id="enable-animation-3" type="checkbox" />
  <label for="enable-animation-3">Enable animation</label>

  <div class="marquee marquee--hover-pause">
    <ul class="marquee__content">
      <li>1</li>
      <li>2</li>
      <li>3</li>
      <li>4</li>
      <li>5</li>
      <li>6</li>
    </ul>

    <ul aria-hidden="true" class="marquee__content">
      <li>1</li>
      <li>2</li>
      <li>3</li>
      <li>4</li>
      <li>5</li>
      <li>6</li>
    </ul>
  </div>
</section>

<section>
  <h2>Fit content</h2>
  <input id="enable-animation-4" type="checkbox" />
  <label for="enable-animation-4">Enable animation</label>

  <div class="marquee marquee--fit-content">
    <ul class="marquee__content">
      <li>1</li>
      <li>2</li>
      <li>3</li>
    </ul>

    <ul aria-hidden="true" class="marquee__content">
      <li>1</li>
      <li>2</li>
      <li>3</li>
    </ul>
  </div>
</section>

<section>
  <h2>Fit content + position absolute :last-child</h2>
  <input id="enable-animation-5" type="checkbox" />
  <label for="enable-animation-5">Enable animation</label>

  <div class="marquee marquee--fit-content marquee--pos-absolute">
    <ul class="marquee__content">
      <li>1</li>
      <li>2</li>
      <li>3</li>
    </ul>

    <ul aria-hidden="true" class="marquee__content">
      <li>1</li>
      <li>2</li>
      <li>3</li>
    </ul>
  </div>
</section>
              
            
!

CSS

              
                /* Marquee styles */
.marquee {
  --gap: 1rem;
  position: relative;
  display: flex;
  overflow: hidden;
  user-select: none;
  gap: var(--gap);
}

.marquee__content {
  flex-shrink: 0;
  display: flex;
  justify-content: space-around;
  gap: var(--gap);
  min-width: 100%;
}

@keyframes scroll {
  from {
    transform: translateX(0);
  }
  to {
    transform: translateX(calc(-100% - var(--gap)));
  }
}

/* Pause animation when reduced-motion is set */
@media (prefers-reduced-motion: reduce) {
  .marquee__content {
    animation-play-state: paused !important;
  }
}

/* Enable animation */
.enable-animation .marquee__content {
  animation: scroll 10s linear infinite;
}

/* Reverse animation */
.marquee--reverse .marquee__content {
  animation-direction: reverse;
}

/* Pause on hover */
.marquee--hover-pause:hover .marquee__content {
  animation-play-state: paused;
}

/* Attempt to size parent based on content. Keep in mind that the parent width is equal to both content containers that stretch to fill the parent. */
.marquee--fit-content {
  max-width: fit-content;
}

/* A fit-content sizing fix: Absolute position the duplicate container. This will set the size of the parent wrapper to a single child container. Shout out to Olavi's article that had this solution 👏 @link: https://olavihaapala.fi/2021/02/23/modern-marquee.html  */
.marquee--pos-absolute .marquee__content:last-child {
  position: absolute;
  top: 0;
  left: 0;
}

/* Enable position absolute animation on the duplicate content (last-child) */
.enable-animation .marquee--pos-absolute .marquee__content:last-child {
  animation-name: scroll-abs;
}

@keyframes scroll-abs {
  from {
    transform: translateX(calc(100% + var(--gap)));
  }
  to {
    transform: translateX(0);
  }
}

/* Other page demo styles */
.marquee__content > * {
  flex: 0 0 auto;
  color: white;
  background: dodgerblue;
  margin: 2px;
  padding: 1rem 2rem;
  border-radius: 0.25rem;
  text-align: center;
}

.marquee {
  border: 2px dashed lightgray;
}

* {
  box-sizing: border-box;
}

body {
  padding: 2rem;
  width: 100%;
  min-height: 100vh;
  font-family: system-ui, sans-serif;
  font-size: 1rem;
  line-height: 1.5;
}

h1 {
  font-size: 2rem;
  font-weight: 600;
  line-height: 1.2;
  margin-block: 2rem 1rem;
}

h2 {
  font-size: 1.25rem;
  font-weight: 600;
}

section {
  margin-block: 3rem;
}

section > * + * {
  margin-block-start: 0.5rem;
}

              
            
!

JS

              
                const sections = document.querySelectorAll("section");

[...sections].forEach((section) => {
  const checkbox = section.querySelector("input");

  checkbox.addEventListener("change", () => {
    section.classList.toggle("enable-animation");
  });
});

              
            
!
999px

Console