In this tutorial, I’ll guide you through the process of creating a dynamic, animated ‘Buy Now’ button using CSS3. This updated guide is perfect for beginners and will walk you through the essential HTML and CSS code needed to bring your button to life, whether you’re setting up an eCommerce store or enhancing your web design skills.
Overview
Our goal is to create a ‘Buy Now’ button that not only grabs attention but also provides a seamless user experience by revealing the price upon hovering. This button could easily be linked to your shopping cart, payment gateway like PayPal, or any other relevant page.
Step 1: Setting Up the HTML
First, let’s lay down the HTML structure. The button consists of a main class, with three additional classes for the ‘Buy Now’ text, the hidden price, and the optional image icon. Here’s the basic markup:
<a class="buybtn" href="#">
<span class="buybtn-text">Buy Now</span>
<span class="buybtn-hidden-text">£149.99</span>
</a>
Step 2: Styling the Button with CSS
Next, we’ll style the button using CSS. We’ll create three distinct states: normal, hover, and active. This will involve background gradients, shadows, and smooth transitions to give your button a polished, modern look.
Button and Text Styling
We’ll start by styling the button in its normal state, ensuring it stands out with a gradient background, subtle shadows, and responsive text. Here’s the CSS for that:
a {
color: #fff;
text-decoration: none;
}
.buybtn {
font-family: Arial, sans-serif;
background: linear-gradient(to bottom, #ff8400 0%, #ff6600 100%);
padding-left: 20px;
padding-right: 65px;
height: 45px;
display: inline-block;
position: relative;
border: 1px solid #ff5a00;
box-shadow: 0px 1px 1px rgba(255, 255, 255, 0.8) inset,
1px 1px 3px rgba(0, 0, 0, 0.2),
0px 0px 0px 4px rgba(188, 188, 188, 0.5);
border-radius: 5px;
margin: 10px 0px;
overflow: hidden;
transition: all 0.3s linear;
}
.buybtn-text {
padding-top: 10px;
display: block;
font-size: 18px;
white-space: nowrap;
text-shadow: 0px 1px 1px rgba(255, 255, 255, 0.3);
color: #6e1d08;
transition: all 0.2s linear;
}
.buybtn-hidden-text {
position: absolute;
height: 100%;
top: 0;
right: 52px;
width: 0;
background: #6e1d08;
text-shadow: 0px -1px 1px #363f49;
color: #fff;
font-size: 18px;
white-space: nowrap;
text-transform: uppercase;
text-align: left;
text-indent: 17px;
overflow: hidden;
line-height: 42px;
box-shadow: -1px 0px 1px rgba(255, 255, 255, 0.4),
1px 1px 2px rgba(0, 0, 0, 0.2) inset;
transition: width 0.3s linear;
}
.buybtn-image {
position: absolute;
right: 0;
top: 0;
height: 100%;
width: 52px;
border-left: 1px solid #ff5a00;
box-shadow: 1px 0px 1px rgba(255, 255, 255, 0.4) inset;
}
.buybtn-image span {
width: 38px;
height: 38px;
opacity: 0.7;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
background: transparent url(../images/cart.png) no-repeat 75% 55%;
transition: all 0.3s linear;
}
.buybtn:hover .buybtn-text {
text-shadow: 0px 1px 1px #5d81ab;
color: #fff;
}
.buybtn:hover .buybtn-hidden-text {
width: 100px;
}
.buybtn:hover .buybtn-image span {
opacity: 1;
}
.buybtn:active {
background: #ff5a00;
}
Hover Styling
Now, let’s define what happens when users hover over the button. We’ll make the text color shift to white, reveal the hidden price, and make the image icon more prominent:
.buybtn:hover .buybtn-text {
text-shadow: 0px 1px 1px #5d81ab;
color: #fff;
}
.buybtn:hover .buybtn-hidden-text {
width: 100px;
}
.buybtn:hover .buybtn-image span {
opacity: 1;
}
Active State Styling
Finally, we’ll adjust the button’s appearance for when it’s clicked, providing immediate feedback to the user:
.buybtn:active {
background: #ff5a00;
}
Final Thoughts
And that’s it! You now have a sleek, animated ‘Buy Now’ button fully styled with CSS3, ready to enhance your eCommerce site or web project. Feel free to experiment with the styles and transitions to match your brand’s look and feel. With this 2024 update, your buttons will be both functional and visually appealing, adding that extra touch of professionalism to your site.
Quick answer about Animated CSS3 Buy Now Button
Summary: This page gives visitors a clearer explanation of Animated CSS3 Buy Now Button, why it matters, and what they can do next on Ozairwebs.
What this page should help users understand
A helpful page should answer the main question quickly, then support that answer with useful details, clear headings, examples, and next steps. It should avoid empty filler and should not make unsupported claims.
- Main topic: Animated CSS3 Buy Now Button.
- Related context: Services, Web, WordPress, Seo, Development, Commerce, Solution, Mobile.
- Recommended next step: review the details on this page and open a related page when more context is needed.
Useful context
This section improves readability, answer extraction, semantic coverage, and user navigation. It is intentionally written with safe wording so the website owner can refine exact business details later without losing the page structure.
Helpful related pages
Visitors can use the following internal pages to verify details or continue their journey.
- Web Design, WordPress & SEO in Pakistan for Global Brands
- Contact us Information | Ozairwebs
- Privacy Policy Page | OZAIR WEBS
- About us
- WordPress Automatic Plugin: Import Amazon Product to WooCommerce
- Custom Schema Injector (Post, product, pages, and custom
- Protect Your WordPress Content from Copying and Right-Click with functions.php and
- The Importance of SEO in SaaS Business Websites: Practical Strategies for Founders and
Frequently asked questions
1What should visitors know about Animated CSS3 Buy Now Button before continuing?
Animated CSS3 Buy Now Button covers the key details visitors need on Ozairwebs; related pages linked below add further specifics.
2Where can visitors find more detail on this topic?
Related internal links, product or category pages, and the website contact options below provide more specific information.
3Who should visitors contact with questions about Animated CSS3 Buy Now Button?
Visitors can use Ozairwebs’s contact or support options for questions this page does not fully answer.

