CSS Transitions

Smooth changes between states.

✍️ 3 exercises + code challenge in this lesson

A transition animates a property change smoothly instead of instantly, for example when hovering.

transition: property duration timing-function delay;

  • transition: background-color 0.3s ease;
  • transition: all 0.4s; animates every property that changes.
  • Timing functions: ease, linear, ease-in, ease-out, ease-in-out, cubic-bezier().

Key Takeaways: CSS Transitions

Mastering CSS Transitions helps you write clean and reliable CSS code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.

CSS Transitions Code Example

CSS
<style>
  .btn {
    background: #2563EB; color: white; padding: 12px 24px; border: 0; border-radius: 10px; font-size: 16px;
    transition: transform .25s ease, box-shadow .25s ease, background-color .25s;
  }
  .btn:hover { transform: translateY(-4px); box-shadow: 0 12px 24px rgba(37,99,235,.4); background: #1D4ED8; }

  .bar { width: 60px; height: 20px; background: #14B8A6; margin-top: 20px; border-radius: 99px; transition: width 1s ease-in-out; }
  .bar:hover { width: 300px; }
</style>

<button class="btn">Hover me</button>
<div class="bar"></div><small>Hover the bar</small>
Free sign-in required · Google login available

CSS Transitions Practice Exercises

Check what you learned in “CSS Transitions”.

/ 3 solved
Fill in the blank

Animate background colour changes over 0.3 seconds.

button {
  transition:  0.3s;
}
✓ Correct! Not quite. Try again.
Multiple choice

What does a transition do?

✓ Correct! Not quite. Try again.
Code challenge

Give the button a transition of 0.5s.

Write the code in the live editor. Your answer is checked automatically.

Free sign-in required · Google login available

to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.

Stuck on something?

Ask the community in the CodesInTech forum.

Need a developer?

Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.

Explore Our Services