If you’re just starting with CSS and want to make a cool, moving text effect, you’re in the right place!
We’ll show you how to create a marquee animation that scrolls text across the screen.
To make it even better, we’ll add a pause button when you hover over it so you can easily read the text or click any links.
Let’s get started!
First, we’ll create a simple HTML file. Inside this file, we’ll create a container to hold our scrolling text.
index.html
, or add the HTML Widget in WordPressindex.html
Start with a basic HTML structure and add a div
container for the text, or simply add the code to the widget on WordPress. This container will control how the text moves across the screen.We’ll use two main parts,
We’ll also use links within the text so you can click on them.
Here’s the HTML code to set up the container
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Marquee Animation</title>
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600&display=swap" rel="stylesheet">
<link rel="stylesheet" href="style.css"> <!-- Link to your CSS file -->
</head>
<body>
<!-- Add only the below section to the HTML Widget-->
<div class="marquee-container">
<div class="marquee">
<a href="#">Expand Your Reach</a> →
<a href="#">Build Brand Authority</a> →
<a href="#">Capture More Leads</a> →
<a href="#">Drive More Sales</a>
</div>
</div>
<!-- Add only the above section to the HTML Widget-->
</body>
</html>
Next, create a style.css
file in the same folder as index.html
. Add the following CSS to set up basic styles for the marquee.
We’ll set up two main styles,
We’ll also use a preferred font to make the text look nice.
/* Link to the Preferred font from Google Fonts Goes Here */@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;600&display=swap');
/* Outer container for overflow control */.marquee-container {
overflow: hidden;
width: 100%;
white-space: nowrap; /* Prevents text from wrapping */}
/* Inner marquee text */.marquee {
display: inline-block;
font-family: 'Poppins', sans-serif; /* Apply Preferred font */ font-size: 30px; /* Adjust size as needed */ color: #656565; /* Adjust color as needed */ padding-right: 100%; /* Ensures text starts off-screen */ animation: marquee 25s linear infinite; /* Animates text from right to left */}
.marquee a {
text-decoration: none; /* Remove underline from links */ color: inherit; /* Ensures links have the same colour as text */ cursor: pointer; /* Show pointer cursor on hover */}
Next, we’ll create a smooth animation effect.
We’ll use ‘keyframes’ to define how the text moves over time.
It’ll start from the right and gradually move to the left.
Add the following CSS code to your style section
file,
@keyframes marquee {
0% {
transform: translateX(100%); /* Start from right edge of the container */ }
100% {
transform: translateX(-100%); /* Move to the left edge, out of view */ }
}
Finally, we’ll make the animation pause when someone hovers over it. This will make it easier to read and click on links.
We’ll use a unique CSS trick to achieve this. This tells the browser to pause the animation anytime someone hovers over the .marquee
element.
Add the following hover effect to your CSS.
/* Pause animation on hover */.marquee:hover {
animation-play-state: paused;
}
We’ll adjust the text size for phones and tablets using a special technique called ‘media queries’ to make it look good on smaller screens.
/* Responsive font size */@media (max-width: 768px) {
.marquee {
font-size: 18px; /* Smaller font for mobile */ padding-right: 200%; /* Increased padding for better scroll effect on smaller screens */ animation: marquee 30s linear infinite; /* Slower animation for mobile */ }
}
This is a simple but cool way to add movement to your website using just CSS. It’s an excellent way to start learning about CSS animations. You can customise it by changing the speed, colour, and font size.
Now, your text scrolls smoothly and pauses when you hover over it, making it easy to read. Try experimenting with different settings to make it your own!
Here’s how the complete CSS code.
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;600&display=swap');
/* Outer container for overflow control */.marquee-container {
overflow: hidden;
width: 100%;
white-space: nowrap;
}
/* Inner marquee text */.marquee {
display: inline-block;
font-family: 'Poppins', sans-serif;
font-size: 30px;
color: #656565;
padding-right: 100%;
animation: marquee 25s linear infinite;
}
/* Keyframes for right-to-left animation */@keyframes marquee {
0% {
transform: translateX(100%);
}
100% {
transform: translateX(-100%);
}
}
/* Pause animation on hover */.marquee:hover {
animation-play-state: paused;
}
/* Remove underline and add pointer for links */.marquee a {
text-decoration: none;
color: inherit;
cursor: pointer;
}
/* Responsive font size */@media (max-width: 768px) {
.marquee {
font-size: 18px;
padding-right: 200%;
animation: marquee 30s linear infinite;
}
}
Here’s the complete HTML code you can add directly to an HTML widget.
This code includes the HTML structure and the CSS styling for the marquee animation with a hover-pause effect.
Let’s break down how it works,
.marquee-container
: This holds everything and controls the scrolling area..marquee
: This contains the actual moving text.<!-- Link to Google Fonts -->
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600&display=swap" rel="stylesheet">
<style>
/* Outer container for overflow control */ .marquee-container {
overflow: hidden;
width: 100%;
white-space: nowrap;
}
/* Inner marquee text */ .marquee {
display: inline-block;
font-family: 'Poppins', sans-serif;
font-size: 30px; /* Adjust size as needed */ color: #656565; /* Adjust color as needed */ padding-right: 100%; /* Ensure text starts off-screen */ animation: marquee 25s linear infinite; /* Adjust speed as needed */ }
/* Keyframes for right-to-left animation */ @keyframes marquee {
0% {
transform: translateX(100%);
}
100% {
transform: translateX(-100%);
}
}
/* Pause animation on hover */ .marquee:hover {
animation-play-state: paused;
}
/* Styling for links */ .marquee a {
text-decoration: none; /* Remove underline */ color: inherit; /* Use the same color as text */ cursor: pointer; /* Show pointer cursor on hover */ }
/* Responsive font size */ @media (max-width: 768px) {
.marquee {
font-size: 18px; /* Adjust font size for smaller screens */ padding-right: 200%; /* Increase padding for mobile screens */ animation: marquee 30s linear infinite; /* Even slower for mobile screens */ }
}
</style>
<div class="marquee-container">
<div class="marquee">
<a href="https://hypesrilanka.com/services/online-advertising/">Expand Your Reach</a> →
<a href="https://hypesrilanka.com/services/search-engine-optimization/">Build Brand Authority</a> →
<a href="https://hypesrilanka.com/services/content-marketing/">Capture More Leads</a> →
<a href="https://hypesrilanka.com/social-media-management/">Drive More Sales</a>
</div>
</div>
Just add the Final Code to your HTML Widget, and you’ll have a cool scrolling text effect with clickable links that pause when you hover over them.
You can see this in action on our home page! Remember to check back into HypeX Digital Marketing Agency Website for more cool tips.
o3-mini and DeepSeek's Surprising DNA Match How did an 80% similarity birthed a more efficient…
This SEO Package is only available once a year during our “25 off SEO” event…
How do you find out whether your ad copy is impactful? The internet is flooded…
While working, I habitually listen to an audiobook or watch YouTube videos about technology and…
10 Steps to Optimising Your Website For Generative Search (2025 Update) You might already know…
Google's AI Studio is a powerful platform that empowers developers to build and train machine…