Blog

Horizontal News Ticker with HTML and CSS

Horizontal CSS news ticker with a pause control and stationary headline cards

Horizontal News Ticker with HTML and CSS

A horizontal news ticker can use CSS keyframes to translate a row of headlines across a clipped viewport. Repeat the same visual group twice and move the track by half its total width for a continuous loop. Provide a persistent pause control, honor reduced-motion preferences and keep a stationary list of the same links available.

This tutorial builds a responsive, CSS-only ticker without the obsolete marquee element. The moving strip is decorative; readers use ordinary, nonmoving links to open each headline. No JavaScript or live-news service is required for this sample.

Live demo: responsive news ticker with pause and speed controls

Horizontal news ticker playground

Watch the sample headlines move, pause them, or change the lap duration. Use the stationary links below to read without following moving text.

Lap duration

The ticker runs unless the pointer is over the moving strip.Scrolling is paused. Uncheck Pause scrolling to resume.

Your browser is showing a static preview. Use the headlines below.

Reduced motion is enabled on your device. The moving preview is hidden; all headlines remain available below.

Read the headlines without scrolling

The headlines are sample HTML content, not a live RSS feed. No JavaScript or external feed service is used. Only the decorative moving strip is hidden from assistive technology.

Why use CSS instead of the marquee element?

The HTML marquee element is obsolete and should not be used for new work. CSS gives you explicit control over movement, timing and fallback styles. See the MDN marquee reference for its deprecated status.

Motion is optional presentation. An announcement should still be understandable when a user pauses it, requests reduced motion, uses a screen reader or cannot follow moving text. This example therefore keeps the actual headline links in a stationary list.

1. Separate the visual strip from the usable links

<section class="news-ticker">
  <label><input id="pause-news" type="checkbox"> Pause scrolling</label>
  <!-- Decorative animation: no links or buttons inside. -->
  <div class="news-viewport" aria-hidden="true">
    <div class="news-track">
      <div class="news-group"><span>First headline</span><span>Second headline</span></div>
      <div class="news-group"><span>First headline</span><span>Second headline</span></div>
    </div>
  </div>
  <ul>
    <li><a href="/first-story/">First headline</a></li>
    <li><a href="/second-story/">Second headline</a></li>
  </ul>
</section>

The two visual groups are identical and contain spans rather than links. Their shared viewport is hidden from assistive technology to prevent duplicate announcements. All navigation stays in the regular list below. Never put focusable controls inside an aria-hidden subtree, and do not hide content there unless an equivalent usable alternative exists.

In the sample code, replace the illustrative story URLs with real destinations. The downloadable project uses local sample sections so it works fully offline; the public demo links to related SanWebCorner tutorials and the JSON Formatter.

2. Create a continuous CSS scrolling loop

.news-viewport { overflow: hidden; min-width: 0; }
.news-track { display: flex; width: max-content; }
.news-group { display: flex; flex-shrink: 0; gap: 2rem;
  padding-right: 2rem; white-space: nowrap; }
@keyframes news-scroll {
  from { transform: translateX(0); }
  to { transform: translateX(-50%); }
}
/* Older browsers keep the preview static. */
@supports selector(:has(*)) {
  .news-track { animation: news-scroll 24s linear infinite; }
  .news-ticker:has(#pause-news:checked) .news-track {
    animation-play-state: paused;
  }
}
@media (hover: hover) {
  .news-viewport:hover .news-track { animation-play-state: paused; }
}
@media (prefers-reduced-motion: reduce) {
  .news-track { animation: none !important; }
  .news-viewport { display: none; }
}

The full track contains two equal-width groups. At translateX(-50%), the second group is exactly where the first one began. Resetting the animation to zero then shows identical content at the loop boundary. Each group owns its trailing spacing; there is no extra gap on the track that would throw off the half-width distance.

Keep both copies identical, including fonts, category badges, gaps and padding. Different group widths produce a visible jump. Use linear easing for even progress through each lap. A fixed duration is not a fixed pixel speed: adding longer content makes the same lap cover more distance.

3. Give readers a persistent pause control

The checkbox sets animation-play-state to paused and resumes from the current position when unchecked. Unlike hover alone, a checkbox can retain pause after the pointer or keyboard focus moves elsewhere. The demo also pauses while a hover-capable pointer is over the strip. MDN explains the animation-play-state property.

W3C’s Pause, Stop, Hide guidance describes the need for controls when nonessential moving content starts automatically, lasts more than five seconds and appears alongside other content. This component provides a pause mechanism; that is not a claim that the entire website has passed a WCAG audit.

4. Adjust speed and support reduced motion

Preset Duration of one lap Behavior
Slow 36 seconds More time for each headline.
Standard 24 seconds The initial sample setting.
Fast 14 seconds A quicker preview, with pause still available.

The full project changes a CSS custom property through native radio controls and :has(). Changing duration can shift the current position. Browsers without :has() do not enable the animation; the static reading list still works.

When prefers-reduced-motion requests reduction, the demo disables the animation and hides its decorative strip and unnecessary controls. It displays a short note while keeping all three real links available. Use this preference as a practical fallback rather than requiring users to watch animation to get the message.

5. Keep the ticker responsive

The layout uses minmax(0, 1fr) and min-width: 0 so a long track can be clipped within the page instead of stretching its columns. At narrow widths, the badge moves above the strip and the stationary links stack vertically. Do not confuse a narrow window with a touch-input device; their interaction capabilities can differ.

Download and run the complete source

  1. Download and extract the ZIP.
  2. Open index.html in a current browser. The project has no dependencies or external assets.
  3. Try Pause scrolling, the three lap-duration choices and the stationary links.
  4. Check narrow layouts and your device’s reduced-motion preference before adapting it to your site.

Common news ticker problems

  • A jump at the loop boundary: ensure both groups have equal widths and account for all spacing.
  • The page scrolls sideways: check the viewport’s overflow and the parent grid’s minimum width.
  • The ticker stays still: inspect the pause checkbox, hover state, reduced-motion preference and :has() support.
  • Screen readers hear every headline twice: keep the decorative copies hidden and provide one usable stationary reading list.
  • New headlines never appear automatically: CSS animates existing HTML; it does not fetch an RSS feed or API.

Frequently asked questions

Can I make a horizontal news ticker without JavaScript?

Yes. HTML supplies the content and controls; CSS supplies the loop, pause state and duration. Live feeds or server updates require a separate data source.

Can the moving headlines be clickable?

They can be in a different design, but this example deliberately places the usable links in a stationary list. Do not add links to its aria-hidden moving strip.

Can I use it for breaking news?

You can supply timely headlines, but this sample is not a newsroom system or live feed. Essential or urgent information should also appear clearly in normal page content.

How do I add more headlines?

Add each headline to the real reading list and both visual copies. Keep the copies identical, then retest group widths and choose an appropriate duration.

Conclusion

A useful HTML/CSS news ticker combines a seamless visual loop with user-controlled motion and a dependable static reading path. Download the source to adapt the layout and controls while keeping the real headlines available without scrolling animation.