Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST

HTML and CSS Transitions


Transitions

CSS transitions animate changes to CSS properties, creating smooth hover states, focus styles, and UI feedback without JavaScript.


Core properties

  • transition-property - which properties to animate (e.g., background-color, transform).
  • transition-duration - total time for the transition.
  • transition-timing-function - easing curve (e.g., ease, cubic-bezier()).
  • transition-delay - wait time before animation starts.
  • transition shorthand sets all four at once.

Note: Easing controls how fast or slow the animation feels.

ease-in starts slow, while ease-out ends slow.

If you want to read more about CSS Transitions or get an in-depth understanding, go to CSS Transitions in our CSS tutorial.


Example: Buttons

This example animates background color and slight lift on hover/focus using the transition shorthand for smooth feedback.

Animated CTA

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles.css" type="text/css">
</head>
<body>
  <a class="cta" href="#">Launch project</a>
</body>
</html>
.cta {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  border-radius: 999px;
  padding: 12px 22px;
  background: #2563eb;
  color: #fff;
  text-decoration: none;
  transition: background 180ms ease, transform 180ms ease;
}
.cta:hover,
.cta:focus-visible {
  background: #1d4ed8;
  transform: translateY(-2px);
}
Try it Yourself »

On interaction, the background changes and the element translates up a few pixels.

The easing makes the motion feel responsive, not abrupt.



Timing functions

  • Common curves: ease, linear, ease-in, ease-out, ease-in-out.
  • Custom easing with cubic-bezier(x1, y1, x2, y2).
  • Use steps(n, direction) for discrete animations (menus, counters).

Responsive motion

  • Respect @media (prefers-reduced-motion: reduce) by disabling or simplifying transitions.
  • Avoid large transform distances that cause layout shifts.
  • Limit duration to 200-300ms for snappy feedback, longer for complex transitions.

Note: Reduced motion is an accessibility setting; honoring it prevents discomfort for sensitive users.



×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2025 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.