Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Transitions | CSS Basics to Advanced lesson | BraveProgrammer
  1. Courses
  2. /
  3. CSS Basics to Advanced

Lesson 20 of 50

·css

Transitions

9 mins

Course progress40%

What you'll learn

Keep these ideas in mind as you work through the lesson.

3 points
  • Only properties that have a **computable intermediate value** can be transitioned (e.g., `display` cannot).
  • Use `will-change` (sparingly) to hint the browser about upcoming transitions.
  • Combine with `prefers-reduced-motion` to respect user preferences.

CSS transitions animate a property from its current state to a new state when a change occurs (usually a pseudo‑class trigger). They are perfect for micro‑interactions.

Syntax

transition: <property> <duration> <timing‑function> <delay>;
  • property – Which CSS property to animate (all or a specific one). Not all properties are transitionable (e.g., display).
  • duration – How long the animation runs (0.3s, 200ms).
  • timing‑function – Controls the acceleration curve (ease, linear, cubic-bezier(), steps()).
  • delay – Optional pause before the transition starts.

Example – Smooth Hover Link

a {
  color:#0066cc;
  text-decoration:none;
  transition:color .2s ease, transform .2s ease;
}
a:hover {
  color:#004499;
  transform:translateY(-2px);
}

The link fades to a darker shade and nudges upward for a subtle gesture.


Best Practices

  • Prefer transform and opacity for any motion – they are handled by the compositor and stay 60 fps.
  • will-change can hint the browser, but over‑using it forces the creation of a new layer, hurting performance. Use only when you know an element will animate.
  • Respect prefers-reduced-motion – turn off non‑essential transitions for users who disable motion.
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition:none !important; }
}

Common Pitfall – Transitioning background-color on Mobile

Mobile browsers occasionally drop the transition due to power‑saving heuristics. Pair it with a fallback that still provides a visual cue (e.g., a subtle box‑shadow).

Make it stickPractice what you've learned1 quiz · 6 practical tests · Optional activities from CSS Basics to AdvancedBrowse activities
Previous lessonPseudo‑Classes & Pseudo‑ElementsContinue to lesson 21TransformsBack to CSS Basics to Advanced curriculum