Skip to content
engineering workbench.by StudyPort Academy
Learning path
Advanced16 minLESSON 14 / 16

Transitions and animations

Change a control, or edit the CSS. The preview uses that same CSS.

easing

Play moved the token with the duration and easing in the CSS. Linear kept a steady speed, and ease-in-out slowed the start and the end. The token traveled the same distance each time. Only the timing changed.

+Go deeper

Only some properties ease

A transition watches a property and eases it when the value changes. Transform and opacity are the cheap ones. Width, height, and anything that changes the of the neighbors can force the page to lay out again on every frame. Prefer transform for a move.

Duration is how long

The time is in milliseconds in the playground and in the declaration: 600ms is a bit over half a second. A very short duration feels like a snap. A very long one feels stuck. The distance of the move stays in the transform. Duration does not change how far it goes.

Easing is the shape

linear keeps a constant speed. ease starts and ends a little softer. ease-in starts slow. ease-out ends slow. ease-in-out does both. The same 180px move feels different because the speed along the way changed.

Easing shapes
NameSpeedWhen it feels right
linearConstantA progress meter or a continuous slide
easeSoft endsA small interface change
ease-inSlow startSomething leaving
ease-outSlow endSomething arriving
ease-in-outSlow at both endsA longer move

Replay the same change

The button adds and removes a class that changes transform. The transition declaration does the easing. A transition only runs when something else changes the property, such as that class or a hover. An animation runs by itself: @keyframes names the steps, and the animation property plays them, including a count of infinite. The playground is the transition, so you can feel the easing. If you edit the duration in the CSS and the number is not one of the slider stops, the control shows a custom value and the next replay still uses your number.

Reduced motion is a query

A can ask for prefers-reduced-motion. Inside it, set a near-zero duration or remove the transition. The person asked the page to be still. The playground already does this when the system setting is on.

04

Guided challenge

Transitions and animations

The declaration says 600ms. The script logs 200ms. Read the duration from the style attribute.

Opening editor…
LIVE PREVIEW
Console 0

Your console output appears here.

Saved on this deviceJavaScript · ES2022

EXPECTED CONSOLE OUTPUT

600ms
ease
Go

Hints 0/2

    Use all hints or make 3 failed runs (0/3).

    05

    Free sandbox

    Edit the HTML and CSS. The JavaScript tab can read the result. This draft is saved separately.

    Opening editor…
    LIVE PREVIEW
    Console 0

    Your console output appears here.

    Saved on this deviceJavaScript · ES2022
    06

    Quiz

    A quick check for understanding. Retry as often as you like; your learning path stays open.

    01Which property is the better one to move a box?
    02What does easing change?

    Ready to call this one understood?

    Mark this lesson complete to earn 200 XP. You can always revisit it.

    Sign in to save progress
    Next lesson