CSStransition shorthand

transition Shorthand

The transition shorthand property combines transition-property, transition-duration, transition-timing-function, and transition-delay into one declaration. It's more concise than writing each property separately, but requires understanding the correct order. The shorthand is very common in modern CSS and supports multiple transitions for different properties.

transition shorthand syntax

CSS
/* transition: property duration timing-function delay */

/* Single property transition */
.button {
  background: #3498db;
  transition: background 0.3s ease 0s;
  /* property, duration, timing, delay */
}

.button:hover {
  background: #2980b9;
}

/* Simplest form (duration only, rest defaults) */
.simple {
  transition: 0.3s;
  /* All properties, 0.3s duration, ease timing, 0 delay */
}

/* Property + duration (most common) */
.common {
  transition: background 0.3s;
  /* 0.3s, ease timing, 0 delay (defaults) */
}

/* All values specified */
.complete {
  transition: transform 0.5s cubic-bezier(0.4, 0.0, 0.2, 1) 0.1s;
  /* Property, duration, custom timing, delay */
}

/* Multiple properties (comma-separated) */
.multi {
  transition:
    background 0.3s ease,
    transform 0.5s ease,
    opacity 0.2s ease;
  /* Each property has its own timing */
}

/* Transition all properties */
.transition-all {
  transition: all 0.3s ease;
  /* Every property change gets the same timing */
}
Shorthand syntax order and defaults

Position

Property

Default

Optional?

1st

transition-property

all

Yes, omit for "all"

2nd

transition-duration

0s

Required (must specify time)

3rd

transition-timing-function

ease

Yes, omit for "ease"

4th

transition-delay

0s

Yes, omit for "0s"

CSS
/* Understanding the order */

/* Can omit property (defaults to 'all') */
.no-property {
  transition: 0.3s ease 0.1s;
  /* Same as: transition: all 0.3s ease 0.1s */
}

/* Can omit timing function (defaults to 'ease') */
.no-timing {
  transition: background 0.3s 0.1s;
  /* Same as: transition: background 0.3s ease 0.1s */
}

/* Can omit delay (defaults to '0s') */
.no-delay {
  transition: background 0.3s ease;
  /* Same as: transition: background 0.3s ease 0s */
}

/* Duration is the ONLY required value */
.minimal {
  transition: 0.3s;
  /* property=all, timing=ease, delay=0s */
}

/* Two values: property + duration (most common) */
.standard {
  transition: background 0.3s;
  /* timing=ease, delay=0s (defaults) */
}

/* Can't omit duration! */
.invalid {
  /* transition: background ease 0.1s; */
  /* ❌ ERROR: duration required, "ease" not recognized as duration */
}

/* Multiple properties with varying timings */
.different-timings {
  transition:
    background 0.2s ease,
    /* Fast color change */
    transform 0.5s cubic-bezier(0.4, 0, 0.2, 1),
    /* Slower transform with custom timing */
    opacity 0.3s ease 0.1s;
    /* Medium fade with delay */
}
Long-form vs shorthand comparison

CSS
/* Long-form (expanded) */
.long-form {
  transition-property: background, transform, box-shadow;
  transition-duration: 0.3s, 0.5s, 0.2s;
  transition-timing-function: ease, ease-out, cubic-bezier(0.4, 0, 0.2, 1);
  transition-delay: 0s, 0.1s, 0s;
}

/* Shorthand (equivalent) */
.shorthand {
  transition:
    background 0.3s ease 0s,
    transform 0.5s ease-out 0.1s,
    box-shadow 0.2s cubic-bezier(0.4, 0, 0.2, 1) 0s;
}

/* Both do the same thing, shorthand is more concise */

/* Shorthand 'all' keyword */
.all-shorthand {
  transition: all 0.3s ease 0.1s;
}

/* Equivalent long-form */
.all-longform {
  transition-property: all;
  transition-duration: 0.3s;
  transition-timing-function: ease;
  transition-delay: 0.1s;
}

/* Mix of shorthand and long-form (avoid - confusing) */
.mixed {
  transition: all 0.3s;
  /* 3 different styles, don't mix if possible */
  transition-delay: 0.1s;
}
Practical examples with shorthand

CSS
/* Button with multiple transitions */
.button {
  background: #3498db;
  transform: scale(1);
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  transition:
    background 0.2s ease,
    transform 0.3s ease,
    box-shadow 0.3s ease;
}

.button:hover {
  background: #2980b9;
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

/* Card with staggered entrance */
.card {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.4s ease, transform 0.4s ease 0.1s;
  /* Opacity fades immediately, transform slides after 0.1s */
}

.card.visible {
  opacity: 1;
  transform: translateY(0);
}

/* Sidebar slide animation */
.sidebar {
  transform: translateX(-100%);
  opacity: 0;
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease;
}

.sidebar.open {
  transform: translateX(0);
  opacity: 1;
}

/* Smooth theme switch */
body {
  background-color: #ffffff;
  color: #000000;
  transition: background-color 0.3s ease, color 0.3s ease;
}

body.dark-mode {
  background-color: #1a1a1a;
  color: #ffffff;
}

/* Navigation underline effect */
.nav-link {
  position: relative;
  color: #333;
  transition: color 0.3s ease;
}

.nav-link::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 0;
  height: 2px;
  background: #3498db;
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.nav-link:hover {
  color: #3498db;
}

.nav-link:hover::after {
  width: 100%;
}

/* Dropdown with multiple stages */
.dropdown-menu {
  max-height: 0;
  opacity: 0;
  pointer-events: none;
  overflow: hidden;
  transition: max-height 0.3s ease, opacity 0.2s ease;
}

.dropdown-trigger:hover ~ .dropdown-menu {
  max-height: 400px;
  opacity: 1;
  pointer-events: auto;
}
Using transition with CSS custom properties

CSS
/* Define standard transitions as custom properties */
:root {
  --transition-fast: 0.2s ease;
  --transition-base: 0.3s ease;
  --transition-slow: 0.5s ease;
  --transition-smooth: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Apply consistently across components */
.button {
  transition: background var(--transition-base), transform var(--transition-base);
}

.card {
  transition: transform var(--transition-smooth), box-shadow var(--transition-base);
}

.modal {
  transition: opacity var(--transition-slow), transform var(--transition-smooth);
}

/* Easily switch all transitions for different themes */
@media (prefers-reduced-motion: reduce) {
  :root {
    --transition-fast: 0.01s ease;
    --transition-base: 0.01s ease;
    --transition-slow: 0.01s ease;
    --transition-smooth: 0.01s ease;
  }
}

/* Define transition by purpose */
:root {
  --transition-micro: 0.15s ease;
  /* Quick feedback (0.1-0.2s) */
  --transition-standard: 0.3s ease;
  /* Normal interaction (0.2-0.4s) */
  --transition-transition: 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  /* Page/modal transitions (0.4-0.8s) */
  --transition-subtle: 1s ease;
  /* Background animations (0.8s+) */
}

.interactive {
  transition: all var(--transition-micro);
}

.content-change {
  transition: all var(--transition-standard);
}

.page-transition {
  transition: all var(--transition-transition);
}
Common mistakes and best practices

CSS
/* ❌ MISTAKE: Duration in wrong position */
.wrong {
  /* transition: ease 0.3s background; */
  /* ❌ Error: "ease" is not a duration */
}

/* ✓ CORRECT: Duration always second */
.correct {
  transition: background 0.3s ease;
}

/* ❌ MISTAKE: Using "all" everywhere */
.bad-all {
  transition: all 0.3s;
  /* Transitions every property, can be inefficient */
}

/* ✓ BETTER: Specify needed properties */
.good-specific {
  transition: background 0.3s, transform 0.3s;
  /* Only transitions what needs it */
}

/* ❌ MISTAKE: Overly complex timing */
.overcomplicated {
  transition:
    background 0.15s cubic-bezier(0.1, 0.2, 0.3, 0.4),
    border 0.2s cubic-bezier(0.5, 0.6, 0.7, 0.8),
    box-shadow 0.25s cubic-bezier(0.1, 0.8, 0.2, 0.9);
}

/* ✓ BETTER: Consistent, simple timing */
.simple-timing {
  transition:
    background 0.3s ease,
    border 0.3s ease,
    box-shadow 0.3s ease;
}

/* ❌ MISTAKE: Conflicting transitions */
.conflicting {
  transition: all 0.3s;
  transition: background 0.5s; /* Overwrites first line */
}

/* ✓ CORRECT: Single transition declaration */
.proper {
  transition: all 0.3s;
}

/* Best practice: Document transition purposes */
.button-hover {
  /* Quick color feedback for user action */
  transition: background 0.2s ease;
}

.modal-entrance {
  /* Smooth fade-in of modal dialog */
  transition: opacity 0.3s ease, transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.content-reveal {
  /* Staggered reveal of content */
  transition: opacity 0.4s ease, transform 0.4s ease 0.1s;
}
Note
The `transition` shorthand combines property, duration, timing-function, and delay. Syntax: `transition: property duration timing delay`. Duration is required; others are optional with defaults (property='all', timing='ease', delay='0s'). For multiple properties, use comma-separated values. Keep it simple: most cases are just `transition: property 0.3s` or `transition: all 0.3s`. Define standard durations as CSS custom properties for consistency.
Next
Transition patterns: [Transition Patterns & Best Practices](/css/transition-patterns).