CSS Data Type
Description
The <length> CSS data type represents a measurement of distance or size in CSS. It can be used to define the dimensions of elements, spacing between elements, font sizes, and more. A <length> value can be expressed in absolute units such as pixels (px), centimeters (cm), millimeters (mm), points (pt), and inches (in), or in relative units like ems (em), root ems (rem), percentages (%), viewport width (vw), and viewport height (vh). Absolute units are fixed and do not scale with the user’s settings or viewport, whereas relative units adjust according to context such as the parent element’s font size or the viewport size.
The <length> type is frequently used with CSS properties that expect a measurement, such as width, margin, padding, font-size, and border-width. Because it can accept both absolute and relative values, <length> is highly versatile for responsive design, allowing developers to scale elements consistently across different screen sizes.
When using <length> in CSS, it’s important to understand context-dependent behavior. For example, percentage values often relate to the dimensions of a containing element, whereas em-based values are relative to the font size of the current element. Some CSS functions, like calc(), also work seamlessly with <length> values, enabling dynamic calculations of dimensions.
Examples:
/* Absolute lengths */
div.box {
width: 300px;
height: 150px;
border-width: 2pt;
}
/* Relative lengths */
p.text {
font-size: 1.2em;
margin-top: 5%;
padding: 2rem;
}
/* Using calc() with length */
section.container {
width: calc(100vw - 40px);
height: 50vh;
}
The <length> type is essential for precise control over layout, typography, and spacing, giving developers the ability to create both fixed and flexible designs. It is one of the most widely used CSS data types, alongside others like <number> or <percentage>.
Syntax
property: <length>
Values
- cm and mmSpecify centimetres and millimetres.
- inSpecify inches.
- pcSpecify picas, 6 per inch.
- ptSpecify points, 72 per inch.
- pxSpecify pixels, 96 per inch. These are often referred to as CSS pixels, and do not necessarily correspond to the device's resolution.
- emunits equal the point size (nominal height) of the current font. This is historically based on the mechanical typeset width of the (square) letter "M".
- remEqual the em size for the document root (usually html)
- exSpecify the height of the letter "x" in the current font, the general height of lowercase letters without ascenders.
- chSpecify the width of the numeral "0" in the current font, which is roughly the average for most text characters.
- vwSpecify a percentage of the width of the current viewport, e.g., the window.
- vhSpecify a percentage of current viewport’s height.
- vmax and vminspecify the maximum or minimum of the viewport's width or height.
Example
Browser Support
The following information will show you the current browser support for the CSS length data type. Hover over a browser icon to see the version that first introduced support for this CSS data type.
This data type is supported by all modern browsers.
Desktop
Tablets & Mobile
Last updated by CSSPortal on: 2nd January 2026
