Background Color Transition using CSS

In this tutorial we will see how to create smooth Background Color Transition using CSS. CSS transition property is used for this which will change the background color smoothly.

HTML Code

Simple HTML Code is given below, In this code both button element is used as main element, it's background color is changed using css code.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Background Color Transition using CSS</title>
</head>
<body>
  <div>
    <button>HowToCodeSchool.com</button>
  </div>
</body>
</html>

CSS Code

CSS code is given below, In this code transition property is used which will change the background color of button element from blue (#009CF0) to purple (#D000F0) in 2 seconds.

button {
font-size: 20px;
color: #fff;
padding: 10px 20px;
border: none;
cursor: pointer;
background: #009CF0;
-webkit-transition: background 2s; /* For Safari */
transition: background 2s; /* For modern browsers */
}
button:hover {
background: #D000F0;
}

transition property

The transition property specify the name of the CSS property for which the transition effect will work. It also specify the time duration of transition, it's timing function and delay.

Demo

Video Tutorial

Watch video tutorial on Background Color Transition using CSS.

Responsive Sidebar Menu with CSS and JavaScript Cool CSS Button with Hover Animation Pure CSS Custom Radio Buttons Custom Emoji Radio Buttons with CSS Color Picker Design with HTML CSS and JavaScript Custom Radio Buttons with CSS Engraved HTML Buttons With CSS Neumorphic Buttons Design with CSS Cool Profile Card Design with HTML CSS Neumorphic Search Bar Design with HTML and CSS Simple Login Form with Placeholder Animation Pure CSS Button with Folded Corner Background Color Change Slider with HTML CSS and JavaScript 404 Page Not Found Template Design with HTML and CSS Movies Blog Card Design with HTML and CSS Simple CSS Border Animation with before and after Selector Custom Social Select Dropdown Menu with CSS and JavaScript Facebook Offline and Online Notification with CSS and JS New Year 2022 Text Animation with CSS and JS Change Placeholder Color using CSS Custom Select Tag DropDown with CSS and JavaScript Simple Price Range Slider With HTML CSS and JavaScript Profile Card With Hover Effect using HTML and CSS Circle With Two Colors using CSS Simple FAQ Accordion With HTML CSS and JavaScript