Creating Marquee Text with CSS

Marquee text (scrolling or moving text) can be created using CSS animations. Here’s how to do it with explanations:

Basic Marquee Effect

Let’s add some text content for marquee.

Now, add some CSS as given below.

The above CSS creates a marquee effect to the text content given above.

Explanation:

  1. Container Setup:

    • overflow: hidden ensures content outside the container isn’t visible
    • white-space: nowrap prevents text from wrapping to multiple lines
  2. Text Element:

    • display: inline-block allows the element to be animated properly
    • padding-left: 100% starts the text completely off-screen to the right
  3. Animation:

    • @keyframes marquee defines the animation sequence
    • transform: translateX(-100%) moves the element left by its full width
    • The animation runs for 15 seconds, linearly, and infinitely

Advanced Marquee with Pause on Hover

If you want to add some advanced effect to marquee like pause on hover, you can add more CSS as given below.

Continuous Marquee (No Gap)

For a seamless loop where the text reappears immediately after disappearing:

Notes:

  • The original <marquee> HTML tag is obsolete and shouldn’t be used
  • CSS animations are more performant than JavaScript solutions for simple marquees
  • Consider accessibility – moving text can be problematic for some users
  • Adjust animation duration based on text length for optimal reading speed

Browser Support:

CSS animations are supported in all modern browsers. For very old browsers, you might need vendor prefixes (-webkit-, -moz-, -o-).

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.