🎨 CSS Button Hover Effect: Background Slide Left to Right Transition
Want to give your buttons a modern, eye-catching hover effect? In this quick tutorial, we’ll create a smooth CSS Button Hover Effect left-to-right background transition on a button using only HTML and CSS. No JavaScript is needed!
Perfect for landing pages, call-to-action buttons, or anywhere you want to add a bit of interactive flair.
🔧 What We’re Building
Here’s what the button will do:
- The background color will slide in from the left to right when hovered.
- The text color will change for better contrast.
- The transition will be smooth and modern, adding polish to your UI.
Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body {
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
background-color: #bba8ff;
height: 100dvh;
}
.btn {
border: none;
outline: none;
padding: 15px 30px;
font-size: 16px;
font-weight: 600;
font-family: sans-serif;
background-color: #fff;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
border-radius: 0.25rem;
cursor: pointer;
position: relative;
z-index: 1;
&::before {
content: '';
position: absolute;
background-color: #000;
top: 0;
bottom: 0;
right: 0;
width: 0;
z-index: -1;
border-radius: 0.25rem;
transition: width 0.4s ease-out;
}
&:hover {
color: #fff;
&::before {
left: 0;
right: auto;
width: 100%;
}
}
}
</style>
</head>
<body>
<button class="btn">Go</button>
</body>
</html>
📘 Summary
This left-to-right background transition is a simple yet powerful CSS trick that can instantly level up your UI designs. Customize it with different colors, timing functions, or even gradients to make it fit your brand’s style.
🔔 Stay Connected
For more frontend tips, tricks, and tutorials:
📌 Subscribe to Stackify Forge on YouTube
Read Our Other Blogs