Front-end Tutorials

Front-end Tutorials

HTMLCSSSassJavaScriptReactJS
CMS Tutorials

CMS Tutorials

WordPress
Tutorials expand

CSS Properties

CSS transition Property

Posted in CSS Tutorial
Updated on Oct 13, 2024
By Mari Selvan
👁️ 21 - Views
⏳ 4 mins
💬 1 Comment
CSS transition Property

Photo Credit to CodeToFun

🙋 Introduction

The transition property in CSS allows you to change property values smoothly (over a given duration). It is commonly used to create animations and enhance user interactions by animating the changes of CSS properties. This makes your web pages more dynamic and engaging.

💡 Syntax

The transition property is a shorthand property for four individual transition properties:

  • transition-property
  • transition-duration
  • transition-timing-function
  • transition-delay
Syntax
Copied
Copy To Clipboard
element {
  transition: property duration timing-function delay;
}

🎛️ Default Value

The default value of the transition property is none 0s ease 0s, which means no transition effect will be applied unless specified.

🏠 Property Values

ValueDescription
transition-propertySpecifies the CSS property to apply the transition to (e.g., width, height, background-color). The default is all, which applies the transition to all properties.
transition-durationSpecifies the duration of the transition. Default is 0s.
transition-timing-functionSpecifies the speed curve of the transition. Default is ease.
  • ease
  • linear
  • ease-in
  • ease-out
  • ease-in-out
  • step-start
  • step-end
transition-delaySpecifies a delay before the transition starts. Default is 0s.

📄 Example

In this example, we'll change the background color of a button with a smooth transition over 0.5 seconds.

index.html
Copied
Copy To Clipboard
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>CSS transition Example</title>
  <style>
    button {
      background-color: blue;
      color: white;
      padding: 10px 20px;
      border: none;
      cursor: pointer;
      transition: background-color 0.5s ease;
    }
    button:hover {
      background-color: red;
    }
  </style>
</head>
<body>
  <h1>Button with Background Color Transition</h1>
  <button>Hover over me!</button>
</body>
</html>

🖥️ Browser Compatibility

The transition property is well-supported in modern browsers, including the latest versions of Chrome, Firefox, Safari, Edge, and Opera. It is always a good practice to test your website across different browsers to ensure compatibility.

🎉 Conclusion

The transition property is a versatile and powerful tool for web developers, enabling the creation of smooth animations and enhancing the user experience.

By specifying transitions for different properties, durations, timing functions, and delays, you can create visually appealing effects that make your web pages more engaging and interactive. Experiment with different combinations and see how the transition property can bring your web projects to life.

👨‍💻 Join our Community:

To get interesting news and instant updates on Front-End, Back-End, CMS and other Frameworks. Please Join the Telegram Channel:

Author

author
👋 Hey, I'm Mari Selvan

For over eight years, I worked as a full-stack web developer. Now, I have chosen my profession as a full-time blogger at codetofun.com.

Buy me a coffee to make codetofun.com free for everyone.

Buy me a Coffee

Share Your Findings to All

Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
We make use of cookies to improve our user experience. By using this website, you agree with our Cookies Policy
AgreeCookie Policy