CSS3 Transitions: transition-property, duration, timing-function, delay, Smooth Hover and Focus Effects

HTML5 and CSS3 45 min min read Updated: Nov 17, 2026 Beginner
CSS3 Transitions: transition-property, duration, timing-function, delay, Smooth Hover and Focus Effects
Beginner Topic 2 of 3

The Idea

Normally a style change happens instantly. A transition makes it happen gradually over time.

css .btn { background: #0b5fff; color: #fff; transition: background-color .3s ease, transform .2s ease; } .btn:hover, .btn:focus-visible { background: #0846c4; transform: translateY(-2px); }
Measured in Chrome

transition-duration on the button: 0.3s, 0.2s

Put the transition on the normal state so it works both going in and going back.

The Four Parts

PropertyMeaningExample
transition-propertyWhich property animatesbackground-color, all
transition-durationHow long.3s, 300ms
transition-timing-functionSpeed curveease, linear, ease-in-out
transition-delayWait before starting.1s

Shorthand order: property duration timing-function delay.

Timing Functions

ValueFeel
linearConstant speed
easeStarts fast, ends slow (default)
ease-inStarts slow
ease-outEnds slow, feels natural for things entering
cubic-bezier(.2,.8,.2,1)Your own curve
steps(4)Jumps in steps

What Can Be Transitioned?

Properties with number-like values: color, background-color, opacity, transform, width, margin, box-shadow. But display cannot animate between none and block.

Smooth and cheap Prefer transform and opacity. They run smoothly. Animating width, height, top or left forces the browser to re-lay out the page and can look choppy.

Fade a Menu In

css .dropdown { opacity: 0; visibility: hidden; transform: translateY(-8px); transition: opacity .2s ease, transform .2s ease, visibility .2s; } .has-menu:hover .dropdown, .has-menu:focus-within .dropdown { opacity: 1; visibility: visible; transform: none; }

Using visibility along with opacity keeps hidden links out of the tab order and away from screen readers until shown.

Underline That Grows

css .link { background: linear-gradient(currentColor, currentColor) left bottom / 0 2px no-repeat; transition: background-size .25s; } .link:hover { background-size: 100% 2px; }
Keep it short Use roughly 150 to 300 milliseconds for most interface changes. Very slow effects feel sluggish. Always provide focus styles as well as hover styles.

Practice

  1. Add a smooth hover and focus effect to a button
  2. Fade a card's shadow in on hover
  3. Make a dropdown menu fade and slide in

Conclusion

Transitions smooth the change between two states. Set property, duration and easing on the normal state and prefer transform and opacity.

Quick Summary: Idea; four parts; timing; what can animate; menu; underline.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators