⚡ CSS Transitions — Smooth Property Changes

Last Updated: November 2025


CSS Transitions make property changes happen smoothly over time, instead of instantly.
They’re perfect for hover effects, button animations, or menu slides.

🗣 Hinglish Tip: Transition ka matlab hai — "style ekdum se change na ho, balki dheere dheere ho."


Syntax

selector {
  transition: property duration timing-function delay;
}

Each part means:

  • property → Which CSS property to animate
  • duration → How long the transition lasts
  • timing-function → Speed pattern (ease, linear, etc.)
  • delay → Wait time before it starts
button {
  background-color: skyblue;
  transition: background-color 0.5s ease;
}

button:hover {
  background-color: steelblue;
}

When you hover, background color changes smoothly in 0.5s.


🧩 Transition Properties Explained

PropertyDescriptionExample
transition-propertySpecifies which property to transitiontransition-property: width;
transition-durationDefines how long the transition laststransition-duration: 2s;
transition-timing-functionSpeed curve of the transitiontransition-timing-function: ease-in-out;
transition-delayDelay before the transition startstransition-delay: 0.5s;

Shorthand Property

.box {
  /* transition: property duration timing-function delay; */
  transition: all 1s ease-in-out 0.2s;
}

all means — apply transition to every animatable property.


🌀 Timing Functions

FunctionDescriptionEffect
easeDefault, slow-fast-slowSmooth natural motion
linearConstant speedSteady change
ease-inStarts slow, ends fastFast entry
ease-outStarts fast, ends slowSoft exit
ease-in-outSlow start & endBalanced
cubic-bezier(x1, y1, x2, y2)Custom controlFine-tuned curve

🗣 Hinglish Tip: Timing function ek curve hoti hai — jo decide karti hai speed ka pattern har frame me.


##Width & Color Change

.box {
  width: 100px;
  height: 100px;
  background: coral;
  transition: width 1s, background 0.5s;
}

.box:hover {
  width: 200px;
  background: lightgreen;
}

Both width and background color animate smoothly.


Move on Hover

.move {
  width: 80px;
  height: 80px;
  background: tomato;
  position: relative;
  transition: left 1s ease;
}

.move:hover {
  left: 100px;
}

Moves smoothly from left to right.


Multiple Properties

.card {
  width: 150px;
  height: 150px;
  background: #ffcc00;
  border-radius: 10px;
  transition: transform 0.5s, box-shadow 0.3s;
}

.card:hover {
  transform: scale(1.1);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
}

Grows and adds shadow smoothly when hovered.


Delay Example

.delayed {
  width: 100px;
  height: 100px;
  background: purple;
  transition: background 1s ease 0.5s;
}

.delayed:hover {
  background: violet;
}

Transition starts after 0.5 seconds of hover.