Skip to content

CSS Transition Not Smooth Fix

DodaTech Updated 2026-06-24 3 min read

In this tutorial, you'll learn about CSS Transition Not Smooth Fix. We cover key concepts, practical examples, and best practices.

The Problem

You add transition: all 0.3s to an element but the change is instant and jarring. The transition either does not fire, fires on the wrong property, or animates choppily.

Quick Fix

Step 1: Specify the property and duration

.element {
    /* Wrong — no transition defined */
    background-color: blue;
}
.element:hover {
    background-color: red;
}

/* Right */
.element {
    background-color: blue;
    transition: background-color 0.3s ease;
}
.element:hover {
    background-color: red;
}

Expected output: Background color changes smoothly over 300ms on hover.

Step 2: Do not transition display

CSS cannot animate display. Use opacity and visibility instead:

/* Wrong — display does not animate */
.modal {
    display: none;
    transition: display 0.3s;
}
.modal.open {
    display: block;
}

/* Right */
.modal {
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
}
.modal.open {
    opacity: 1;
    visibility: visible;
}

Expected output: The modal fades in smoothly.

Step 3: Use transform instead of positional properties

Animating left, top, width, or height triggers layout recalculations:

/* Wrong — layout-triggering properties */
.element {
    left: 0;
    transition: left 0.3s;
}
.element.move {
    left: 100px;
}

/* Right — GPU-accelerated properties */
.element {
    transform: translateX(0);
    transition: transform 0.3s;
}
.element.move {
    transform: translateX(100px);
}

Expected output: The element slides without jank.

Step 4: Check for initial state mismatch

The initial state must match the transitioned property:

/* Wrong — no initial width set */
.element {
    transition: width 0.3s;
}
.element.expand {
    width: 200px;
}

/* Right */
.element {
    width: 100px;
    transition: width 0.3s;
}

Expected output: Width transitions from 100px to 200px.

Step 5: Avoid transition: all for performance

/* Wrong — transitions everything */
.element {
    transition: all 0.3s;
}
/* Right — target specific properties */
.element {
    transition: opacity 0.3s, transform 0.3s;
}

Expected output: Only targeted properties animate, reducing GPU load.

Prevention

  • Always set an initial value for the property you want to transition
  • Use transform and opacity for smooth 60fps animations
  • Avoid transition: all — be explicit about which properties animate
  • Test transitions with Chrome DevTools Performance tab

Common Mistakes with transition not smooth

  1. Using foldl instead of foldl' causing stack overflow on large lists
  2. Forgetting deriving (Show, Eq) on custom data types needed for debugging
  3. Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable

These mistakes appear frequently in real-world CSS code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### Why is my transition instant when it should be smooth?

Most likely missing transition-duration. Without duration, the transition takes 0 seconds by default. Check that both transition-property and transition-duration are set.

Can I transition between two different units?

No. You cannot transition width: auto to width: 200px. Both states must use the same unit type (px, em, %, etc.) for the browser to interpolate between them.

Why does my transition work on hover but not on class add?

Class-based transitions work the same way as hover. The element must have the transition property defined in its base (non-hover) state. If it is only defined in the hover state, the transition away from hover will not animate.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro