Transitions

CSS Transitions

A transition animates a property smoothly from one value to another when it changes, for example on hover.

transition: property duration timing-function delay;
transition: background-color 0.3s ease, transform 0.2s ease-out;

Example

Example

Hover over the card:

<!DOCTYPE html>
<html>
<head>
  <title>Page Title</title>
  <style>
    .card {
      width: 200px; padding: 20px; font-family: Arial; border-radius: 10px;
      background: #e7e9eb;
      transition: background-color .3s ease, transform .3s ease, box-shadow .3s ease;
    }
    .card:hover {
      background: #04AA6D; color: white;
      transform: translateY(-6px);
      box-shadow: 0 10px 20px rgba(0,0,0,.2);
    }
  </style>
</head>
<body>

<div class="card">Hover me</div>

</body>
</html>

Result

Timing Functions

ValueFeel
ease (default)slow start, fast middle, slow end
linearconstant speed
ease-in / ease-outaccelerate / decelerate
cubic-bezier(.2,.8,.2,1)a custom curve

Tip: Animate transform and opacity where possible: the browser can do it on the GPU without re-calculating layout.