Overview

CSS-only text marquee

Watch tutorial

JavaScript

TypeScript

CSS

TailwindCSS

Accessibility

React

Angular

JavaScript

TypeScript

CSS

TailwindCSS

Accessibility

React

Angular

You find the fadeout mask recipe linked at the bottom of this page!

<div class="marquee-text">
<div class="marquee-text-track">
<p>JavaScript</p>
<p>TypeScript</p>
<p>CSS</p>
<p>TailwindCSS</p>
<p>Accessibility</p>
<p>React</p>
<p>Angular</p>
<p aria-hidden="true">JavaScript</p>
<p aria-hidden="true">TypeScript</p>
<p aria-hidden="true">CSS</p>
<p aria-hidden="true">TailwindCSS</p>
<p aria-hidden="true">Accessibility</p>
<p aria-hidden="true">React</p>
<p aria-hidden="true">Angular</p>
</div>
</div>
.marquee-text {
overflow: clip;
}
.marquee-text-track {
display: flex;
padding-left: 4.8rem;
gap: 4.8rem;
width: max-content;
animation: marquee-move-text var(--speed, 10s) linear infinite var(
--direction,
forwards
);
}
.marquee-text p {
border: 1px solid white;
background-color: #141414;
border-radius: 999px;
padding: 1rem 2.5rem;
}
@keyframes marquee-move-text {
to {
transform: translateX(-50%);
}
}

Marquees have been a part of the web for decades. Sadly we can’t use the <marquee> element anymore nowadays. So we have to recreate our own version of it!

How it works

The CSS based marquee makes the impression of an endlessly looping text, by duplicating its contents, and swapping the animation back to the start exactly halfway.

Because of this it is important to have the content at least duplicated once. And if you’re using the same word multiple times, you should always use an even amount. Otherwise the midpoint of the animation won’t be the same as the start.

Sounds confusing? Make sure to check the tutorial on CSS text marquees where I explain it in more detail.

Configuration

By default the marquee uses two CSS variables, so you can reuse the marquee without changing the CSS.

  • --speed - The speed of the marquee. Default is 10s.
  • --direction - The direction of the marquee. Default is forwards. Can be set to reverse to make the marquee go the other way.

Other interesting recipes

Using CSS masks to fadeout content CSS-only logo marquee