codingstuff.io
ExploreTutorialsProblemsCS Subjects
Get Started
ExploreTutorialsProblemsCS Subjects
Get Started
codingstuff.io

Master the art of building software through interactive tutorials, real-world problems, and guided projects.

Pune, Maharashtra, India

codingstuffmail@gmail.com

Product

  • Explore
  • Tutorials
  • Problems
  • CS Subjects

Company

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Sitemap

© 2026 codingstuff.io. All rights reserved.

Built with ❤️ for developers everywhere

/
/
All Tutorials
🎨

HTML & CSS

29 / 59 topics
28CSS Animation29CSS Transitions30CSS Transforms31CSS Variables32CSS Pseudo-elements33CSS Pseudo-classes
Tutorials/HTML & CSS/CSS Transitions
🎨HTML & CSS

CSS Transitions

Updated 2026-05-15
10 min read

CSS Transitions

Introduction

In the world of web development, creating visually appealing and interactive user interfaces is crucial. One way to enhance the user experience is by using CSS transitions. CSS transitions allow you to smoothly animate changes in CSS properties over a specified duration. This tutorial will introduce you to CSS transitions, their basic syntax, and how they can be used to create smooth animations.

Concept

CSS transitions are a powerful feature that enable developers to animate changes in CSS properties without the need for JavaScript. They work by specifying the property or properties you want to animate, the duration of the animation, and optionally, timing functions and delays.

The basic syntax for a CSS transition is as follows:

transition: &lt;property&gt; &lt;duration&gt; <timing-function> &lt;delay&gt;;
  • &lt;property&gt;: The CSS property you want to animate (e.g., width, height, color).
  • &lt;duration&gt;: The length of time the transition should take (e.g., 0.5s, 200ms).
  • <timing-function>: The speed curve of the transition (e.g., ease, linear, ease-in, ease-out, ease-in-out). Default is ease.
  • &lt;delay&gt;: The amount of time to wait before starting the transition. Default is 0s.

Examples

Let's explore some practical examples to understand how CSS transitions work.

Example 1: Basic Transition on Hover

In this example, we will create a simple button that changes its background color when hovered over.

<!DOCTYPE html>
<html lang="en">
&lt;head&gt;
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    &lt;title&gt;CSS Transition Example</title>
    &lt;style&gt;
        .button {
            padding: 10px 20px;
            font-size: 16px;
            color: white;
            background-color: blue;
            border: none;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }

        .button:hover {
            background-color: red;
        }
    </style>
</head>
&lt;body&gt;
    <button class="button">Hover over me!</button>
</body>
</html>

In this example, the transition property is applied to the .button class. When the button is hovered over, the background-color changes from blue to red over a duration of 0.3 seconds with an ease timing function.

Example 2: Multiple Properties Transition

You can also animate multiple properties at once. In this example, we will create a box that changes its size and color when hovered over.

<!DOCTYPE html>
<html lang="en">
&lt;head&gt;
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    &lt;title&gt;CSS Transition Example</title>
    &lt;style&gt;
        .box {
            width: 100px;
            height: 100px;
            background-color: green;
            transition: width 0.5s ease, height 0.5s ease, background-color 0.3s ease;
        }

        .box:hover {
            width: 200px;
            height: 200px;
            background-color: purple;
        }
    </style>
</head>
&lt;body&gt;
    <div class="box"></div>
</body>
</html>

In this example, the transition property is applied to multiple properties (width, height, and background-color). When the box is hovered over, all these properties change simultaneously.

Example 3: Delayed Transition

Sometimes you might want to delay the start of a transition. In this example, we will create a text element that changes its color after a delay when hovered over.

<!DOCTYPE html>
<html lang="en">
&lt;head&gt;
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    &lt;title&gt;CSS Transition Example</title>
    &lt;style&gt;
        .text {
            font-size: 24px;
            color: black;
            transition: color 0.5s ease 1s; /* Delay of 1 second */
        }

        .text:hover {
            color: orange;
        }
    </style>
</head>
&lt;body&gt;
    <p class="text">Hover over me!</p>
</body>
</html>

In this example, the transition property includes a delay of 1 second. When the text is hovered over, the color change will start after a delay of 1 second.

What's Next?

Now that you have learned about CSS transitions, you can enhance your web pages with smooth animations and interactive elements. In the next section, we will explore HTML semantic elements, which are essential for creating well-structured and accessible web content.

Feel free to experiment with different properties, durations, timing functions, and delays to create unique and engaging animations on your web pages.


PreviousCSS AnimationNext CSS Transforms

Recommended Gear

CSS AnimationCSS Transforms