DEV Community

Nachiket Panchal
Nachiket Panchal

Posted on • Originally published at errorsea.com on

2 2

How to Change Button Color on Hover Using CSS

Every element on a website is considered to be important in terms of user experience. In addition, website representation is also another kind of factor which has a significant impact on uses. That’s why buttons and other clickable elements should be user friendly and nice looking.

Changing the color of buttons on hover looks quite impressive and feels upmarket rather than single color buttons. So here, we are going to discuss how to change the background color of the button using simple CSS. We should also choose the color of the button related to our website color. Even more, the color should be material, so it looks elegant to our users.

Change Button Background Color on Hover Using CSS

We have :hover attribute to manage hover events of HTML elements via CSS.

Syntax

.class\_name:hover{
/* CSS lines */
}
Enter fullscreen mode Exit fullscreen mode

Example 1

<!DOCTYPE html>
<html>
   <head>
      <title>Change Button Color on Hover Using CSS - errorsea</title>
      <style> .myButton{ padding: 10px 20px; background-color: #1E88E5; border: 0px; color: #fff; } .myButton:hover{ background-color: #fff; border: 1px solid #1E88E5; color: #1E88E5; } </style>
   </head>
   <body> <button class="myButton">Hover Me</button></body>
</html>
Enter fullscreen mode Exit fullscreen mode

We can also add some transition effects to make it more fluid and user friendly.

Example 2

In this example, we have added a little transition effect on hover to make the background color changing process more smooth and meaningful.

<!DOCTYPE html>
<html>
   <head>
      <title>Change Button Color on Hover Using CSS - errorsea</title>
      <style> .myButton{ padding: 10px 20px; background-color: #1E88E5; border: 0px; color: #fff; transition: 0.25s linear; } .myButton:hover{ background-color: #fff; border: 1px solid #1E88E5; color: #1E88E5; } </style>
   </head>
   <body> <button class="myButton">Hover Me</button></body>
</html>
Enter fullscreen mode Exit fullscreen mode

Enjoy Designing 🙂

The post How to Change Button Color on Hover Using CSS appeared first on errorsea.

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay