Creating CSS3 Button Hover Effects

The CSS3 “hover” is a pseudo-class that enables you to select and style elements on a web page when the mouse moves over an element. You can use Javascript or CSS style sheets to react to this event depending on your objective. For example:

The CSS code above styles a button with class ‘checkout’. The default color of the button is blue and when the mouse is over the button, the color changes to green.


This effect can be used in very ingenious ways. Let’s say you want to persuade a guest on your website to sign-up for a newsletter that you send out every month. You have strategically placed a big blue button with the text “New On This Site ?” . When the guest clicks the button, the sign-up form magically appears.

Steps To Implement The Hover Effect

Create your webpage

Add your big blue action button just below the h1 element

Style your big button by adding a style sheet

Style sheets can be either internal or external. Since we’re building a simple webpage, the first option will be used for this tutorial. Add an internal style sheet just after the title tag.

Identify and select the element that will fire the hover effect

There are several ways of identifying web elements on a page, including adding a class, a unique id or just by tags. For our case, we shall use the id method since it’s more pinpointed. Add an id on the button element.

Style your button

When the page loads, the button will have a blue background and text in white.

The padding style adds some breathing space inside the button to make it look big.

Add the hover effect just below the already existing style so that you have 3 styles

We want to change the background-color from blue to white and the text from white to blue when the user mouses over the button.

Save your page as mainpage.html

This is how the script should look like at this point.



Move your mouse over the button

You should see the background-color and text color change.
Notice that the color change is reversed as soon as the mouse moves outside the button area. The hover effect is a temporary event that lasts as long as the mouse stays within the styled element.  

The hover effect cannot work on mobile devices since it primarily works with the mouse. For your mobile users, you can consider an alternative. Also as we have mentioned, Javascript is also able to react to a hover event giving you an alternative route to bring up some really cool hidden treasures on your website.

Button Hover Effect Collections

Collection 1



Collection 2



Comments on this entry are closed.