Favorites

CSS <length-percentage> Data Type

<length-percentage>
CSS Data TypeThis data type is supported by all modern browsers.
Updated 21st November 2026

The <length-percentage> data type is a value that can be either a <length>, such as 20px, or a <percentage>, such as 50%.

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee

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

Bar
Demo Code
HTML Code
<div class="demo-track">
	<div class="demo-element">Bar</div>
</div>
CSS Code
.demo-track {
	width: 300px;
	padding: 8px 0;
	background: #f4f4f4;
	outline: 1px dashed #b0b0b0;
}
.demo-element {
	height: 36px;
	display: flex;
	align-items: center;
	padding: 0 8px;
	box-sizing: border-box;
	background: #4361ee;
	color: #fff;
	font-size: 12px;
	white-space: nowrap;
	width: 160px;
}

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

<div class="wrap">
<h1>CSS &lt;length-percentage&gt; examples</h1>
<div class="card parent">
<div class="bar a">160px</div>
<div class="bar b">60%</div>
<div class="bar c">calc(100% - 80px)</div>
<div class="bar d">clamp(120px, 40%, 300px)</div>
</div>
<p class="note">Resize the window: the percentage-based bars change, the 160px bar does not.</p>
</div>
/* Base demo layout */
* { box-sizing: border-box; }

body {
  margin: 24px;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial;
  background: #f5f7fb;
  color: #102a43;
}

.wrap {
  max-width: 860px;
  margin: 0 auto;
}

h1 {
  font-size: 20px;
  margin: 0 0 16px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
}

.card {
  background: #fff;
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 6px 18px rgba(16, 42, 67, 0.08);
}

.label {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
  font-size: 12px;
  color: #486581;
  margin-top: 10px;
  word-break: break-word;
}

.note {
  font-size: 13px;
  color: #486581;
  margin-top: 14px;
}

/*  examples */
.parent {
  width: 100%;
  padding: 8px;
  border-radius: 10px;
  background: #e2e8f0;
}

.bar {
  height: 30px;
  margin: 6px 0;
  border-radius: 6px;
  background: linear-gradient(90deg, #2563eb, #06b6d4);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  padding-left: 8px;
}

.a { width: 160px; }
.b { width: 60%; }
.c { width: calc(100% - 80px); }
.d { width: clamp(120px, 40%, 300px); }
Open in editor

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.

This data type is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee