Skip to content

Motion

Motion in NightCSS is built from two things: semantic duration/easing tokens for hand-written transitions, and the speed-* / timing-* utilities for repeated pairs. A transition still needs a property, so set transition-property in your CSS or component.

Token Value Use for
--nc-duration-fast 150ms Hover, focus, pressed states
--nc-duration-base 250ms Panels, dropdowns, theme changes
--nc-duration-slow 400ms Entrances, larger movements
--nc-ease-standard cubic-bezier(0.4, 0, 0.2, 1) Most UI motion
--nc-ease-emphasized cubic-bezier(0, 0, 0.2, 1) Entrances and emphasis

Hover or focus a chip to compare durations:

fast 150msbase 250msslow 400ms

Under prefers-reduced-motion: reduce, the duration tokens collapse to 0.01ms. Anything that reads them becomes effectively instant without extra code.

The ladders cover finer steps than the semantic set. Apply them to a transition that already has a property:

Class Duration
speed-shortest 150ms
speed-shorter 200ms
speed-short 250ms
speed-base 300ms
speed-slow 375ms
speed-slower 500ms
speed-lazy 750ms
Class Timing function
timing-linear linear
timing-ease cubic-bezier(.25, .1, .25, 1)
timing-ease-in cubic-bezier(.42, 0, 1, 1)
timing-ease-out cubic-bezier(0, 0, .58, 1)
timing-ease-in-out cubic-bezier(.42, 0, .58, 1)
timing-standard cubic-bezier(.4, 0, .2, 1)
timing-emphasized cubic-bezier(0, 0, .2, 1)
timing-decelerated cubic-bezier(0, 0, .2, 1)
timing-accelerated cubic-bezier(.4, 0, 1, 1)
timing-sharp cubic-bezier(.4, 0, .6, 1)
<button class="speed-short timing-standard" style="transition-property: background-color, color">
Save
</button>

Every speed collapses under prefers-reduced-motion: reduce. For one-off values, the --speed and --timing knobs work inline:

<div class="speed-short" style="--speed: 120ms">…</div>

There are no breakpoint variants for motion. Motion should not depend on viewport size.

List the properties you are changing. Avoid transition: all, which animates layout and paint work you did not intend:

.card {
transition:
transform var(--nc-duration-fast) var(--nc-ease-standard),
box-shadow var(--nc-duration-fast) var(--nc-ease-standard),
border-color var(--nc-duration-fast) var(--nc-ease-standard);
}
.card:hover {
transform: translateY(-2px);
box-shadow: var(--nc-shadow-md);
border-color: var(--nc-accent);
}

Hover me

A lift

Transform and shadow, 150ms.

Same recipe

Another card

The motion is consistent because the tokens are.

For colour-only feedback, transition color, background-color, and border-color:

.link {
color: var(--nc-text-muted);
transition: color var(--nc-duration-fast) var(--nc-ease-standard);
}
.link:hover {
color: var(--nc-accent);
}

Keep the press shorter than the hover. A press should feel immediate:

.button {
transition:
transform var(--nc-duration-fast) var(--nc-ease-standard),
background-color var(--nc-duration-fast) var(--nc-ease-standard);
}
.button:active {
transform: translateY(1px);
}

For a one-off entrance, a keyframe is fine. Keep the distance small and the duration under 400ms:

@keyframes fade-up {
from {
opacity: 0;
transform: translateY(0.75rem);
}
to {
opacity: 1;
transform: none;
}
}
.enter {
animation: fade-up var(--nc-duration-slow) var(--nc-ease-emphasized) both;
}

Entrance

This block fades up once when the page loads.

Add the reduced-motion escape when the animation is decorative:

@media (prefers-reduced-motion: reduce) {
.enter {
animation: none;
}
}

The duration tokens already collapse, but animation: none removes the movement entirely, which is what some users need.

For elements that enter the top layer, @starting-style lets the browser animate from a pre-open state without JavaScript:

dialog[open] {
opacity: 1;
transform: translateY(0);
transition:
opacity var(--nc-duration-base) var(--nc-ease-standard),
transform var(--nc-duration-base) var(--nc-ease-standard);
}
@starting-style {
dialog[open] {
opacity: 0;
transform: translateY(0.5rem);
}
}

The same pattern works for [popover]:popover-open. See Native Patterns for the markup.

The View Transitions API is a progressive enhancement. Opt in with one rule:

@view-transition {
navigation: auto;
}

Name the elements that should morph across navigations:

.card img {
view-transition-name: cover;
}

If the browser does not support it, the page navigates normally. Do not put essential state in the transition.

  • Animate transform and opacity where possible; they can run on the compositor.
  • Avoid animating width, height, top, left, and margin. They trigger layout on every frame.
  • Keep feedback transitions at 150ms–250ms. Longer feels sluggish for a button and is better reserved for an entrance.
  • Do not animate a looping background behind body copy.
  • Use will-change only on an element that is about to move, and remove it afterwards; it is not a general performance switch.
  • Respect prefers-reduced-motion for anything that moves, scales, or parallaxes.
  • Do not make hover the only way to discover an action; keyboard and touch users need the same information.
  • A focus ring should appear immediately. Transition the colour if you like, but do not delay the ring.
  • Flashing, strobing, and large parallax effects are not worth the risk. Keep motion subtle and purposeful.

The class is the markup shorthand. The same style in a component stylesheet:

.chip {
transition-duration: var(--nc-speed-short);
transition-timing-function: var(--nc-timing-standard);
}

The Sass subpackage exposes the same values: nc.nc-speed("short") and nc.nc-timing("standard"). See Sass subpackage.

A breakpoint is the same declaration inside a media query; you do not need a second class.