transform-box

Term side of the Card.
Topic: Transformations
Unit title: transform-box
Categories: Property
Explanation side of the Card

Explanation: The property that sets the reference box for `transform` and `transform-origin`. Values like 'border-box', 'content-box', 'fill-box' or 'view-box' matter most for SVG, where 'fill-box' lets shapes rotate around their own center.

Browser compatibility:
  • The chrome browser supports this feature starting from version 64.
  • The edge browser supports this feature starting from version 79.
  • The firefox browser supports this feature starting from version 55.
  • The safari browser supports this feature starting from version 11.
Availability: 

Example

Wrongcss
.gear {
  transform-origin: center;
  animation: spin 2s linear infinite;
}
Rightcss
.gear {
  transform-box: fill-box;
  transform-origin: center;
  animation: spin 2s linear infinite;
}

With 'fill-box', 'center' means the center of the shape, not the center of the SVG viewport.

Common mistakes

  • An SVG path spins around the top-left of the <svg> instead of its own center.

Key points

  • SVG elements set transform-box: fill-box before using transform-origin: center.
  • HTML elements keep the default box, since 'fill-box' and 'view-box' mainly matter for SVG.

Interview questions

What is the default transform-box?

'view-box', so SVG transforms use the SVG viewport; HTML elements then use their border box.

What is the difference between fill-box and stroke-box?

'fill-box' uses the shape's geometry, while 'stroke-box' also includes the stroke around it.

Analytics cookiesWe'd like to use analytics cookies to see which pages are useful. They're set only if you accept. Privacy Policy