Width and height
width and height control the dimensions of an element’s box. They are fundamental sizing tools for components, media, and layout primitives.
Overview
width and height control the dimensions of an element’s box. They are fundamental sizing tools for components, media, and layout primitives.
Browser support
| Feature | Desktop | Mobile | ||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Safari | Chrome Android | Safari iOS | |
| 1 | 12 | 1 | 1 | 18 | 1 | |
auto | 1 | 12 | 1 | 1 | 18 | 1 |
| Other | ||||||
| The width CSS property sets an element's width. By default, it sets the width of the content area, but if box-sizing is set to border-box, it sets the width of the border area. | 1 | 12 | 1 | 1 | 18 | 1 |
| CSS property | ||||||
auto | 1 | 12 | 1 | 1 | 18 | 1 |
is animatable Is animatable | 26 | 12 | 16 | 7 | 26 | 7 |
| Other | ||||||
| The CSS data type represents a <number> with a unit attached to it, for example 10px. | 1 | 12 | 1 | 1 | 18 | 1 |
| The CSS data type represents a distance value. Lengths can be used in numerous CSS properties, such as width, height, margin, padding, border-width, font-size, and text-shadow. | 1 | 12 | 1 | 1 | 18 | 1 |
| The CSS data type represents a value that can be either a length or a percentage. | 1 | 12 | 1 | 1 | 18 | 1 |
| The CSS data type represents a percentage value. It is often used to define a size as relative to an element's parent object. Numerous properties can use percentages, such as width, height, margin, padding, and font-size. | 1 | 12 | 1 | 1 | 18 | 1 |
Syntax
.fixed { width: 300px; height: 200px; }
.fluid { width: 100%; height: auto; }
.viewport { width: 100vw; height: 100vh; } Live demo
Use cases
Component sizing
Set intentional dimensions for media, controls, and layout regions that need stable bounds.
Reserved media space
Prevent jumps by reserving image or embed space before content fully loads.
Cautions
- Fixed dimensions can break under translation, zoom, or dynamic content growth.
- Height constraints are especially risky when text length is unpredictable.
Accessibility
- Prefer flexible sizing patterns where text or controls may expand at high zoom or with longer localized content.
Related links
Powered by web-features