If you’ve ever wanted to add some dynamic, scrolling text to your website, then HTML marquee is a simple solution. The marquee tag allows developers to create scrolling text, adding a level of engagement to webpages. While the <marquee>
element is no longer part of the HTML5 standard, it is still widely used and supported by many browsers, making it an easy and effective option for visually enhancing your content.
In this guide, we will cover everything you need to know about using scrolling text in HTML using marquee, including how to use it, alternatives, troubleshooting, and best practices.
By the end of this post, you will be able to add engaging scrolling text to your website and understand the pros and cons of using this feature.
What is the HTML Marquee Tag?
The HTML marquee tag (<marquee>
) is an element used to display scrolling or sliding text on a webpage. It can be used to move text horizontally or vertically across the screen, making it useful for announcements, ticker messages, or adding a decorative element to your page.
- Key Features:
- Supports horizontal and vertical scrolling.
- Allows customization of scroll speed, direction, and behavior.
- Provides an easy way to grab the attention of visitors.
Example: You can create a simple scrolling message such as “Welcome to Our Website!” using the marquee tag.
How to Show Scrolling Text Message in HTML Using Marquee
The marquee tag is used in combination with several attributes to customize the scrolling behavior. Below is a step-by-step explanation of how to use the marquee tag to create a scrolling text effect.
Basic Example of Scrolling Text Using Marquee
The following code demonstrates how to create a simple scrolling message using the <marquee>
tag in HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Scrolling Text Example</title>
</head>
<body>
<marquee>Welcome to Our Website! Stay tuned for exciting updates.</marquee>
</body>
</html>
- Explanation:
<marquee>
: Defines the scrolling area.- Text inside
<marquee>
: The text content you want to scroll. - The text will move from right to left by default.
Customizing the Marquee Scrolling Text
You can customize the scrolling text with various attributes to adjust the speed, direction, behavior, and more.
Commonly Used Marquee Attributes
direction
: Specifies the direction of scrolling text. Options includeleft
,right
,up
, anddown
.
<marquee direction="right">Scrolling to the right!</marquee>
behavior
: Defines the behavior of the scrolling text. Options arescroll
,slide
, andalternate
.
<marquee behavior="alternate">Bouncing text back and forth.</marquee>
scrollamount
: Controls the speed of the scrolling text by defining the number of pixels moved per frame.
<marquee scrollamount="10">Faster scrolling text!</marquee>
loop
: Specifies how many times the marquee will loop. Use-1
for infinite looping.
<marquee loop="3">This will loop three times.</marquee>
bgcolor
: Sets the background color of the scrolling area.
<marquee bgcolor="yellow">Scrolling with a background color.</marquee>
Setting Up Your Project to Use the Marquee Tag
- Include the HTML Marquee Tag: Place the
<marquee>
element within your HTML where you want the scrolling text to appear. - Customize the Attributes: Use attributes like
direction
,behavior
,scrollamount
, etc., to fine-tune the appearance of your scrolling text. - Preview and Test: Preview your webpage in multiple browsers to ensure compatibility and make necessary adjustments.
Common Issues and Solutions When Using the Marquee Tag
1. Browser Compatibility
While the marquee tag is supported by many older browsers, it is not part of the HTML5 standard and may not work well in some modern browsers.
Solution: Consider using CSS animations or JavaScript for better cross-browser support.
.marquee {
overflow: hidden;
white-space: nowrap;
box-sizing: border-box;
animation: marquee 10s linear infinite;
}
@keyframes marquee {
from { transform: translateX(100%); }
to { transform: translateX(-100%); }
}
2. Accessibility Concerns
Scrolling text can be distracting for users, especially those with visual impairments.
Solution: Avoid overusing the marquee and use it only for non-critical content. Provide an option to pause or stop the marquee for better accessibility.
<marquee onmouseover="this.stop();" onmouseout="this.start();">Hover to pause scrolling text.</marquee>
Best Practices for Using Scrolling Text in HTML
- Use Sparingly: Avoid using scrolling text for essential information as it can be distracting.
- Customize with CSS and JavaScript: Modernize the scrolling effect with CSS animations for a cleaner and more consistent user experience.
- Accessibility First: Always consider the accessibility of your website. Use a marquee only when absolutely necessary, and provide options for users to control the scrolling.
- Fallback for Unsupported Browsers: Include fallback content or a CSS-based alternative in case the marquee tag is not supported.
How to Create Dynamic Scrolling Effects Without <marquee>
Given that the <marquee>
element is outdated, many developers use CSS and JavaScript to achieve similar effects with greater control and customization.
Example of a CSS-Based Scrolling Effect
<div class="marquee">Welcome to Our Website! Enjoy the latest updates.</div>
<style>
.marquee {
width: 100%;
overflow: hidden;
white-space: nowrap;
animation: scroll-left 10s linear infinite;
}
@keyframes scroll-left {
from { transform: translateX(100%); }
to { transform: translateX(-100%); }
}
</style>
Conclusion
Adding scrolling text messages in HTML using the marquee tag is a simple and effective way to make your content stand out. While the <marquee>
tag is no longer standard in HTML5, it is still widely supported and easy to use. This guide provided a comprehensive look at how to create, customize, and troubleshoot scrolling text using the marquee tag, as well as best practices for improving user experience and accessibility.
For more modern solutions, consider CSS or JavaScript-based animations, which offer greater flexibility and compatibility across browsers.