liveBook · Manning

CSS transform property

As explained in Tiny CSS Projects

The CSS transform property changes an element's visual geometry without changing its position in normal document flow or the space allocated around it.

The CSS transform property changes how an element looks without changing its place in normal document flow. Shrinking an element with height can pull content below it upward; shrinking it with transform leaves the allocated space in place. Transform functions can scale, move, rotate, or distort the visible element. section 3.4.1

Make a loader pulse

Give a rectangle three keyframes: transform: scaleY(1) at the start, scaleY(0.2) halfway through, and scaleY(1) at the end. The rectangle appears to shrink to 20% of its height and grow again without pulling nearby content into its space. Set transform-origin: center to make it shrink toward its middle; an SVG element’s initial origin is at its top-left corner. section 3.4.1 section 3.4.6

Use translateY() when content should move visually without making surrounding elements reposition. In an interactive card, transform: translateY(calc(350px - 8rem)) moves the inner content down; hover and focus-within states return it to translateY(0). Because moving content can leave it visible beyond the card, the hidden state also limits the container’s height, clips overflow, and fades nonheader content with opacity. section 5.5

A transform can change instantly or animate. Keyframes define stages for a repeating loader; a transition animates between states. For a share link, transition: transform ease-in-out 250ms animates a hover or focus change from the default scale(1) to scale(1.25) and back. The card’s animated treatment is restricted to hover-capable screens at least 700px wide when reduced motion is not requested. section 3.4.1 section 5.5 section 11.6.1

Listing 3.7 Completed keyframe
@keyframes doScale {                   #1
  from { transform: scaleY(1) }        #2
  50% { transform: scaleY(0.2) }       #3
  to { transform: scaleY(1) }          #4
}                                      #5
rect { animation-name: doScale; }      #6

The loader’s complete keyframe rule shows scaleY() changing the visible height at the start, midpoint, and end. section 3.4.1

How Tiny CSS Projects covers it

How deep it goes
Works through scaleY() keyframes, translateY() states, transform transitions, and transform-origin; defers a full list of transform functions.
Examples
Shows pulsing SVG loader rectangles, a card that reveals content on hover or focus, and a share link that enlarges.
What it assumes
Starts from existing rectangles or card markup and explains the transform functions as they are applied.
What you can do after
Build it from scratch with CSS keyframes or transitions to animate visible size and position while preserving surrounding layout.
How it connects
Connects transforms to CSS keyframes, transitions, transform-origin, overflow, opacity, hover, focus-within, and reduced-motion preferences.

Also explained in

Compare how 3 books explain CSS transform property →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Tiny CSS Projects. The section links point to the parts of the book it draws on.