Animated Buttons

CSS Button Styling Examples: Part Two

Eight button examples showcasing some basic - but fun - animations. From a smooth hover effect, to icons, to the old school "realistic" keyboard button.

Back to Code Examples

Buttons guide users, support your site's branding, and invite clicks. At their core, they're just simple rectangles. But add a touch of animation, and they don’t just look better - they feel more responsive and refined.

The most basic use of animation is to transition smoothly between the default and hover states. The user might not consciously notice it - and that’s exactly the goal. The change feels natural instead of abrupt, especially when there’s a strong contrast between the two states. Want to go a little further? Try fading between gradients or using a sliding animation to reveal a different color underneath.

Another popular option is to animate an icon into view on hover. This subtle motion adds energy and reinforces the call to action. Arrows are a classic choice, but any icon that fits your design can work.

If you’re looking for something simpler, you can start with these simply styled button examples instead.


Below are eight button examples to serve as inspiration for your website. For this demonstration, each button is a <div> wrapped in an <a> tag, rather than a <button> or <input> element. This setup offers more flexibility and ease when styling. Anchor (<a>) tags alone can be temperamental with padding, while <button> elements don't naturally navigate anywhere—you'd need JavaScript or an anchor wrapper to make them clickable. As for <input> buttons, they're limited to forms and come with their own quirky styling behaviors.

That’s why the base structure for the buttons in this post looks like this:

<a href="#"><div>Click here!</div></a>


On to the examples...

Animated Button - Smooth Color Change

This is the more refined version of the basic rectangular button. The background color still changes on hover, but now it does so smoothly—giving the button (and your site) a more responsive, polished feel.

It’s all thanks to a single rule:

transition: background-color 200ms linear;

This tells the browser to animate any change in background color. Including it in both the base and hover states ensures a smooth transition in both directions.

HTML:

Copy to clipboard
<a href='#'><div id='button-example-1604'>Click here!</div></a>

CSS:

Copy to clipboard

#button-example-1604 {

color: #fffff7; background-color: #A37C40; padding: 20px 40px; font-size: 18px; font-weight: 600; width: 200px; text-align: center; transition: background-color 200ms linear;

}

#button-example-1604:hover {

background-color: #2B1412; transition: background-color 200ms linear;

}

Animated Button - Color Slides in from Left on Hover

A gentle fade is nice, but what if you want your hover color to slide in with flair? This effect is surprisingly simple—and can give your buttons a distinctive, eye-catching feel.

Here, the slide is created using an inset box-shadow. While typically used for casting shadows, box-shadow can also be inset to simulate a color overlay. Paired with a transition rule, this lets the color “fill” the button from left to right on hover.

HTML:

Copy to clipboard
<a href='#'><div id='button-example-1605'>Click here!</div></a>

CSS:

Copy to clipboard

#button-example-1605 {

color: #fffff7; background-color: #2B1412; padding: 20px 40px; font-size: 18px; font-weight: 600; width: 200px; text-align: center; box-shadow: inset 0 0 #D0A7A2; transition: ease-out 0.5s;

}

#button-example-1605:hover {

box-shadow: inset 280px 0 #D0A7A2;

}

Animated Button - Color Bar with Slide on Hover

This button uses an inset box-shadow to create a bold band of contrasting color on the right side. This color band slides over on hover to cover the whole button. It’s a clean, modern look - more akin to a tab than a traditional button, but still sharp and professional.

Here's a breakdown of what is going on with the box-shadow:

  • inset - renders the shadow inside the element, rather than outside.
  • 10px - the horizontal offset (or width of the inset bar in this case). On hover, it increases to the width of the button, creating a complete fill.
  • 0 - the vertical offset; since it's zero, the shadow only appears as a vertical bar on the right side.
  • #A3C09B - the solid color used for the inset fill.

HTML:

Copy to clipboard
<a href='#'><div id='button-example-1607'>Click here!</div></a>

CSS:

Copy to clipboard

#button-example-1607 {

color: #fffff7; background-color: #373936; padding: 20px 40px; font-size: 18px; font-weight: 600; width: 200px; text-align: center; box-shadow: inset 10px 0 #A3C09B; transition: ease-out 0.5s;

}

#button-example-1607:hover {

box-shadow: inset 280px 0 #A3C09B; color: #373936;

}

Animated Button - Smooth Color to Gradient Change

A rectangular button that shifts from a solid color to a gradient on hover. Since gradients don’t transition smoothly with transition, this effect uses actual CSS animations. The trick: the gradient background is already there - just positioned off-screen. On hover, the animation slides it into view.

Two keyframe animations are used - one for hover in, one for hover out - to create a smooth transition in both directions. The background position values in the animations are carefully coordinated with the hover state and animation timing to ensure a seamless effect without visible jumps. If your button has different dimensions, you may need to tweak these values for best results.

One quirk of this approach is that the "hover out" animation plays on page load. But unless the button is visible right away, it’s unlikely anyone will notice - and it’s a small price to pay for smooth, animated gradient transitions.

HTML:

Copy to clipboard
<a href='#'><div id='button-example-1608'>Click here!</div></a>

CSS:

Copy to clipboard

#button-example-1608 {

color: #fffff7; background: #A37C40 linear-gradient(90deg, #decfb8 0%, #decfb8 50%, #A37C40 100%) 0% 0% no-repeat; background-size: 200% 200%; background-position: 0% 0%; animation: HoverOut 0.5s ease 1; padding: 20px 40px; font-size: 18px; font-weight: 600; width: 200px; text-align: center;

}

#button-example-1608:hover {

animation: HoverIn 0.5s ease 1; background-position: 100% 0%

}

@keyframes HoverIn { 0%{background-position: 0% 0%} 100%{background-position: 60% 0%} } @keyframes HoverOut { 0%{background-position: 60% 0%} 100%{background-position: 0% 0%} }

Animated Button - Gradient Flip

A basic rectangular button, where the gradient flips direction on hover. Since gradients don’t transition smoothly by default, we use a CSS animation to create a fluid shift between gradient states.

If you look closely at the css, you'll see that "flipping" is a misnomer here. Technically, the gradient isn’t flipping - it’s being repositioned. The background is scaled up and animated horizontally, creating the illusion of a directional change.

One caveat: the “hover out” animation runs on page load. But unless the button is high on the page, most users won’t notice - and the payoff is a smooth, eye-catching transition.

HTML:

Copy to clipboard
<a href='#'><div id='button-example-1683'>Click here!</div></a>

CSS:

Copy to clipboard

#button-example-1683 {

color: #fffff7; background: #D0A7A2 linear-gradient(90deg, #2b1412 0%, #d0a7a2 40%, #d0a7a2 60%, #2b1412 100%) 0% 0% no-repeat; background-size: 200% 200%; background-position: 0% 0%; animation: HoverOut 0.15s ease 1; padding: 20px 40px; font-size: 18px; font-weight: 600; width: 200px; text-align: center;

}

#button-example-1683:hover {

animation: HoverIn 0.15s ease 1; background-position: 100% 0%

}

@keyframes HoverIn { 0%{background-position: 0% 0%} 100%{background-position: 100% 0%} } @keyframes HoverOut { 0%{background-position: 100% 0%} 100%{background-position: 0% 0%} }

Animated Button - Appearing Icon

In this example, an icon appears on hover, inviting users to click and proceed to the next page or content. This adds a subtle, engaging animation while maintaining a professional look.

The icon is inserted via a ::before pseudo-element, initially set to opacity 0. On hover, its opacity transitions to 1, while the main text is indented - creating the effect of the text sliding aside to reveal the icon.

FontAwesome is a popular icon library with many options, often seen on websites. Free versions are available, but you’ll need to install the library on your site to use the icons. Browse the full collection and get installation details here.

HTML:

Copy to clipboard
<a href='#'><div id='button-example-1684'>Click here!</div></a>

CSS:

Copy to clipboard

#button-example-1684 {

color: #fffff7; background: #3E5837; transition: all 0.25s linear 0s; padding: 20px 40px; font-size: 18px; font-weight: 600; width: 200px; text-align: center; position: relative;

}

#button-example-1684:hover {

text-indent: -10px; background: #2C3F27;

}

#button-example-1684:before {

content: "\f105"; font-family: FontAwesome; font-size: 18px; line-height: 68px; position: absolute; right: 0; top: 0; height: 100%; opacity: 0; width: 60px; transition: all 0.25s linear 0s;

}

#button-example-1684:hover:before {

text-indent: 0px; opacity: 1;

}

Animated Button - "Realistic" Button

Sometimes it’s fun to be literal. These buttons mimic real-world keyboard keys and feature a satisfying “pressed” animation on hover. The effect is achieved with a carefully layered box-shadow. Each line in the box-shadow rule adds a separate shadow, slightly darker than the one before, to create a smooth, stacked shading effect beneath the button.

The box-shadow property can accept multiple shadows at once, separated by commas; I’ve written each shadow on its own line for readability. Each individual shadow rule creates a thin horizontal line of color, gradually building up a dimensional base. On hover, half of the lines are removed to simulate compression. The final shadow includes a blur radius to give a soft, realistic drop shadow.

A key challenge with this design is choosing the right color progression. You’ll need to start with the base color and gradually darken it with each successive shadow to achieve the smooth, layered shading effect. It can take a bit of trial and error, but the result is well worth it for a polished, dimensional look.

HTML:

Copy to clipboard
<a href='#'><div id='button-example-1688'>Click here!</div></a>

CSS:

Copy to clipboard

#button-example-1688 {

background-color: #AD665C; color: #fffff7; padding: 17px 40px; font-size: 18px; font-weight: 600; width: 200px; text-align: center; margin-bottom: 10px; border-radius: 3px; box-shadow: inset 0 1px #A35B52, 0 1px #95544B, 0 2px #935148, 0 4px #8e4d44, 0 5px #894940, 0 6px #82443b, 0 6px 7px #7a3f37;

}

#button-example-1688:hover {

transform: translateY(3px); box-shadow: inset 0 1px #A35B52, 0 1px #95544B, 0 2px #8e4d44, 0 3px #82443b, 0 4px 6px #7a3f37;

}

Animated Button - Spinning Block

A button that behaves more like a flipping block - on hover it spins to reveal a new side. Each side can be customized independently with different text, colors, fonts, or styles.

The effect is achieved by placing the front and back faces in the ::before and ::after pseudo-elements. The main button div remains invisible; it provides structural support and ensures the element doesn't deform during the transition. On hover, each pseudo-element is rotated and shifted using transform, creating the illusion of one face sliding away as the other rotates into view. Once the animation completes, the inactive side is hidden with opacity: 0 to complete the illusion.

The animation itself is straightforward. No custom keyframes are needed - just a simple transition on transform and opacity for each side.

HTML:

Copy to clipboard
<a href='#'><div id='button-example-1729'>Click here!</div></a>

CSS:

Copy to clipboard

#button-example-1729 {

opacity: 1; outline: 0; color: #243120; background-color: #243120; padding: 20px 40px; width: 200px; position: relative; text-align: center; display: block; filter: drop-shadow(5px 5px 1px rgba(7.1, 9.8, 6.3, 0.6));

}

#button-example-1729:before {

top: 0; left: 0; opacity: 1; color: #fffff7; background-color: #243120; display: block; width: 200px; padding: 20px 40px; font-size: 18px; font-weight: 600; transition: 0.5s; position: absolute; content: "Click me!"; transform: translateY(0) rotateX(0);

}

#button-example-1729:hover:before {

opacity: 0; transform: translateY(50%) rotateX(90deg);

}

#button-example-1729:after {

top: 0; left: 0; opacity: 0; width: 100%; color: #fffff7; display: block; width: 200px; padding: 20px 40px; font-size: 18px; font-weight: 600; transition: 0.5s; position: absolute; background: #6A975E; content: "Please click."; transform: translateY(-50%) rotateX(90deg);

}

#button-example-1729:hover:after {

opacity: 1; transform: translateY(0) rotateX(0);

}

Pumpkins n' Pies

For gluten-free baking enthusiasts and garden lovers: discover delicious, from-scratch recipes featuring sourdough, whole foods, and most importantly – pie! Explore gardening tips from central Illinois, along with a byte of code for fellow developers.
 © 2025 Abhishek & Miriam Chaturvedi