CSS: CSS Transition & Filter

🗓 Last updated: 2026-11-30👤 Written by: Alex✓ Reviewed by: MOTO🏷 Category: CSS Tutorial

Properties in this section: transition-property color transform transition display float visibility opacity

1. CSS Transition

Transition is the simplest way to animate CSS — specify which properties change smoothly, how long, and what timing.

(1) Transition Properties

Property Values Purpose
transition-property all, color, transform Which properties animate
transition-duration 0.3s, 500ms How long the transition takes
transition-timing-function ease, linear, ease-in, ease-out Speed curve
transition-delay 0s, 0.2s Delay before starting
transition all 0.3s ease Shorthand

▶ Example

▶ Try it Yourself

2. CSS Filter

Filters apply visual effects to elements:

(1) Filter Functions

Function Values Effect
blur() 5px, 10px Gaussian blur
brightness() 0.5, 1.5 Darker/brighter
contrast() 0.5, 2 Less/more contrast
grayscale() 0%, 100% Grayscale amount
hue-rotate() 90deg, 180deg Rotate hue
invert() 0%, 100% Invert colors
opacity() 0.5, 1 Transparency
saturate() 0.5, 2 Less/more saturated
sepia() 0%, 100% Sepia tone

▶ Example

▶ Try it Yourself

3. Combining Transition + Filter

▶ Example

▶ Try it Yourself

Properties in this section: transition-property color transform transition display float visibility opacity

❓ FAQ

Q How do I use CSS transition, and what do its four values mean?
A The format is transition: property duration timing-function delay;, e.g. transition: background-color 0.3s ease 0.1s; — the property to animate, how long it takes, the speed curve, and a delay before starting. Put transition on the element itself, not on hover, so the mouse-out direction also animates back smoothly.
Q Is transition: all a good idea?
A It works but isn't recommended. transition: all 0.3s gives every property change a transition, including show/hide layout shifts, and the browser can't optimize for specific properties. List them explicitly: transition: transform 0.3s, opacity 0.3s; — faster, predictable, and you won't get mystery animations.
Q How do I make a button color change smoothly on hover?
A Two rules: button { transition: background-color 0.3s; } button:hover { background-color: #2980b9; }. Keep transition on the button itself and only the target value in hover — then both directions animate; if transition lives inside hover, un-hovering snaps back instantly. Colors, borders, and shadows all transition this way.
Q What's the difference between transition and animation?
A transition needs a trigger (like hover) and only goes from state A to state B — no loops. animation doesn't need a trigger, can auto-play, supports multiple keyframes, loops, and reverse. Simple interactions use transition; complex auto-playing effects use animation.
Q How do I pick between ease, linear, and ease-in-out timing functions?
A linear moves at constant speed — right for spins and loading loops. ease is the default: slow start, faster middle, gentle landing — fine for everyday interactions. ease-out starts fast and settles softly, good for entrances; ease-in is the opposite for exits; ease-in-out is smooth at both ends. For extra character, a custom curve like cubic-bezier(0.22, 1, 0.36, 1) gives a springy feel.
Q Why does my transition sometimes not work?
A Three common causes: the property doesn't support transitions at all (like display or float); the start or end value isn't defined so the browser doesn't know what to animate between; or the element starts at display: none, where transitions don't run — switch to animation, or combine visibility with opacity.
Q What filters does CSS have? How do I make an image grayscale or blurred?
A The everyday set: filter: grayscale(100%) for black-and-white, filter: blur(4px) for blur, brightness(1.2) to lift brightness, sepia(0.8) for a vintage tone, contrast(1.5) for punch. Chain them with spaces in one declaration: filter: grayscale(50%) blur(2px);. A classic pattern is hover-to-color: images default to grayscale(100%) and return to grayscale(0) on hover.
Q How is filter: drop-shadow() different from box-shadow?
A box-shadow follows the element's rectangular box edge, regardless of content shape. drop-shadow() follows the actual outline of the rendered content — shadowing a transparent PNG with box-shadow gives a rectangle, while drop-shadow() hugs the object inside the image. Different tools for different jobs.
Q Does filter: blur() cause performance problems?
A Yes. blur is compute-intensive — blurring large areas (big images, full-page backgrounds) in real time drops frames noticeably. Keep it under control: use blur only on small elements, stay around 10px or less on radius, and consider pre-blurring a background into a static image instead of a live filter. Brief hover-triggered blurs are usually fine; continuous rendering during scrolling deserves caution.

📖 Summary

📝 Exercises

  1. Create a button that changes background color in 0.3s on hover, with slight scale increase.
  2. Create an image gallery: images show grayscale by default, smoothly become colorful on hover.
  3. Create a "navigation underline animation" — bottom line expands from center on hover.
  4. Use filter + transition to make images brighter and slightly blurred on hover.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

Content reviewed by MOTO · Found an error? Report it

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏