CSS <length-percentage> Data Type
The <length-percentage> data type is a value that can be either a <length>, such as 20px, or a <percentage>, such as 50%.
Description
The <length-percentage> CSS data type represents a value that can be either a <length>, such as 20px or 2rem, or a <percentage>, such as 50%. It is one of the most common types in CSS, used by properties including width, height, margin, padding, top, left, gap, border-radius and translate.
When a percentage is used, the property defines what it is a percentage of. width: 50% is half the width of the containing block, padding and margin percentages (even vertical ones) are relative to the containing block's width, border-radius percentages use the element's own size, and translate percentages use the element's own width and height. Knowing the reference is the key to predicting percentage results.
Lengths and percentages can be combined in calc(), min(), max() and clamp(), for example calc(100% - 2rem). This mix is only possible because both values resolve to a length in the end.
Examples:
.container {
width: min(90%, 1100px);
margin-inline: auto;
}
.sidebar {
width: 280px; /* length */
}
.main {
width: calc(100% - 280px - 2rem); /* both combined */
}
.tooltip {
translate: -50% 8px; /* % of its own width, then a length */
}
Interactive Demo
Syntax
<length-percentage> = <length> | <percentage>
Values
- <length>Refer to <length> for possible values.
- <percentage>Refer to <percentage> for possible values. What the percentage is relative to depends on the property.
Example
Browser Support
The following information will show you the current browser support for the CSS length-percentage data type. Hover over a browser icon to see the version that first introduced support for this CSS data type.
Desktop





Tablets & Mobile





