search
HomeWeb Front-endCSS TutorialHow to create a button hover animation effect using CSS?

How to create a button hover animation effect using CSS?

The hover animation effect in CSS means that the appearance of the element changes when the mouse pointer hovers over it. We use CSS to create various animation effects on hover, such as scaling, fading, sliding or rotating elements.

Properties of button hover animation effects

  • transform − This property allows you to scale, rotate or translate the element.

  • opacity − This attribute sets the transparency level of the element, where 1 means fully visible and 0 means fully transparent.

  • background-color − This property sets the background color of the element.

  • color − This property sets the text color of the element.

  • transition − This property controls the animation effect between two states, such as the default state and the hover state.

  • bottom and top - attributes position the element relative to its container.

Use CSS to create button hover animation effects

Button hover animations are a great way to add visual appeal to your website. To create a button hover animation effect using CSS, we usually use the :hover pseudo-class selector combined with CSS transitions or keyframe animations. With the following steps, we can easily create a button hover animation effect.

  • Step One - Create the HTML code for the sticky ball animation

  • Step 2 - Add CSS styles to the button

  • Step 3 - Add hover animation effect

In this article we will explore three examples to create button hover animation effects in CSS.

Example 1 - Hover to zoom

In this example, the button will have a blue background and white text. When the mouse pointer is hovering over the button, the button will scale by 20% in 0.5 seconds using the transform property in a smooth transition, and the background color will change to green.

<!DOCTYPE html>
<html>
<head>
   <style>
      Body{
         text-align:center;
      }
      .scale-up-btn {
         background-color: blue;
         color: white;
         padding: 10px 30px;
         margin:20px;
         border: none;
         transition: transform 0.5s ease;
         transform: scale(1);
         border-radius:10px;
      }
      .scale-up-btn:hover {
         transform: scale(1.2);
         background-color: green;
      }
   </style>
</head>
   <body>
      <h2 id="Button-hover-animation-effect-using-CSS">Button hover animation effect using CSS</h2>
      <h3 id="Scale-Up-on-Hover-effect">Scale Up on Hover effect</h3>
      <button class="scale-up-btn">Hover Me</button>
   </body>
</html>

Example 2: Fade in on mouseover

In this example, the button will have a blue background and white text, with an initial opacity of 0.5. When the mouse pointer hovers over the button, the opacity will smoothly transition to 1 in 0.5 seconds.

<!DOCTYPE html>
<html>
<head>
   <style>
      body{
         text-align:center;
      }
      .fade-in-btn {
         background-color: blue;
         color: white;
         padding: 10px 20px;
         margin:15px;
         border: none;
         opacity: 0.5;
         transition: opacity 0.5s ease;
      }
      .fade-in-btn:hover {
         opacity: 1;
      }
   </style>
</head>
   <body>
      <h2 id="Button-hover-animation-effect-using-CSS">Button hover animation effect using CSS</h2>
      <h3 id="Fade-In-Effect-on-Hover">Fade In Effect on Hover</h3>
      <button class="fade-in-btn">Hover Me</button>
   </body>
</html>

Example 3: Swipe up on mouseover

In this example, the button will have a blue background and white text, with the position set to relative. The bottom property is set to 0, meaning the button is at the bottom of its container. When the mouse pointer hovers over the button, the bottom property will increase to 20px, causing the button to slide up with a smooth transition in 0.5 seconds.

<!DOCTYPE html>
<html>
<head>
   <style>
      body{
         text-align:center;
      }
      .slide-up-btn {
         background-color: blue;
         color: white;
         padding: 15px 30px;
         border: none;
         position: relative;
         bottom: 0;
         transition: bottom 0.5s ease;
         border-radius:10px;
      }
      .slide-up-btn:hover {
         bottom: 20px;
      }
   </style>
</head>
   <body>
      <h3 id="Slide-Up-Effect-on-Hover">Slide Up Effect on Hover</h3>
      <button class="slide-up-btn">Hover Me</button>
   </body>
</html>

in conclusion

Button hover animation effects are a great way to add visual appeal to your website. By using CSS we can create dynamic and engaging effects that make the website stand out. Just a few lines of code.

The above is the detailed content of How to create a button hover animation effect using CSS?. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:tutorialspoint. If there is any infringement, please contact admin@php.cn delete
Demystifying Screen Readers: Accessible Forms & Best PracticesDemystifying Screen Readers: Accessible Forms & Best PracticesMar 08, 2025 am 09:45 AM

This is the 3rd post in a small series we did on form accessibility. If you missed the second post, check out "Managing User Focus with :focus-visible". In

Adding Box Shadows to WordPress Blocks and ElementsAdding Box Shadows to WordPress Blocks and ElementsMar 09, 2025 pm 12:53 PM

The CSS box-shadow and outline properties gained theme.json support in WordPress 6.1. Let's look at a few examples of how it works in real themes, and what options we have to apply these styles to WordPress blocks and elements.

Working With GraphQL CachingWorking With GraphQL CachingMar 19, 2025 am 09:36 AM

If you’ve recently started working with GraphQL, or reviewed its pros and cons, you’ve no doubt heard things like “GraphQL doesn’t support caching” or

Making Your First Custom Svelte TransitionMaking Your First Custom Svelte TransitionMar 15, 2025 am 11:08 AM

The Svelte transition API provides a way to animate components when they enter or leave the document, including custom Svelte transitions.

Classy and Cool Custom CSS Scrollbars: A ShowcaseClassy and Cool Custom CSS Scrollbars: A ShowcaseMar 10, 2025 am 11:37 AM

In this article we will be diving into the world of scrollbars. I know, it doesn’t sound too glamorous, but trust me, a well-designed page goes hand-in-hand

Show, Don't TellShow, Don't TellMar 16, 2025 am 11:49 AM

How much time do you spend designing the content presentation for your websites? When you write a new blog post or create a new page, are you thinking about

Building an Ethereum app using Redwood.js and FaunaBuilding an Ethereum app using Redwood.js and FaunaMar 28, 2025 am 09:18 AM

With the recent climb of Bitcoin’s price over 20k $USD, and to it recently breaking 30k, I thought it’s worth taking a deep dive back into creating Ethereum

What the Heck Are npm Commands?What the Heck Are npm Commands?Mar 15, 2025 am 11:36 AM

npm commands run various tasks for you, either as a one-off or a continuously running process for things like starting a server or compiling code.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools