Approach 1. HTML <marquee>
tag
Event though it is deprecated, HTML <marquee>
tag is still the easiest way to add scrolling text in your page, and it is supported by most browsers.
1 | <marquee>This text will scroll from right to left</marquee> |
Demo:
Pros:
- the best browser compatibility
Cons:
- This tag has already been deprecated.
Approach 2. CSS animation
An alternative way is using CSS animation. We are able to implement a simple marquee effect without any JavaScript codes, the following demo works on modern browsers.
The most important part is @keyframes
rules:
1 | @keyframes scrollingtext { |
Demo:
Pros:
- standard-compatible
Cons:
- Works on mordern browsers only
- The text does not appear immediately after disappeared.