Favorites

CSS <dimension> Data Type

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

The <dimension> data type is a number followed by a unit, such as 10px, 45deg, 300ms or 2fr. Lengths, angles, times and frequencies are all dimensions.

☕
Enjoying this site?

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

Buy us a coffee

Description

The <dimension> CSS data type represents a <number> immediately followed by a unit, such as 10px, 45deg, 300ms or 2fr. It is a general category rather than a type you normally write in a property definition: every specific measurement type in CSS, including <length>, <angle>, <time>, <frequency>, <resolution> and <flex>, is a kind of <dimension>.

The unit is what gives a dimension its meaning. The same number can mean very different things depending on the unit attached: 2s is a duration, 2rem is a length and 2turn is an angle. There must be no space between the number and the unit, so 10 px is invalid. Units are case-insensitive, which means 10PX and 10px are the same value, though lowercase is the convention. A value of zero still needs its unit in most places, with lengths being the common exception where 0 may be written without one.

Percentages look similar, but <percentage> is a separate type, because a percentage is always relative to some other value rather than being a measurement in its own right. Many properties accept both, which is why combined types such as <length-percentage> and <angle-percentage> exist. Dimensions can also be combined inside calc() as long as they are of the same kind.

Examples:

.card {
  width: 320px;          /* <length> */
  padding: 1.5rem;       /* <length> */
  transform: rotate(3deg);  /* <angle> */
  transition: transform 250ms ease; /* <time> */
}

.grid {
  display: grid;
  grid-template-columns: 1fr 2fr; /* <flex> */
}

@media (min-resolution: 2dppx) { /* <resolution> */
  .logo { background-image: url("logo@2x.png"); }
}

Knowing that all these types share the <dimension> form makes it easier to read property syntax and to understand why mixing units of different kinds in a calculation is invalid.

Interactive Demo

Dimension
Demo Code
HTML Code
<div class="demo-element">Dimension</div>
CSS Code
.demo-element {
	width: 140px;
	padding: 14px;
	background: #4361ee;
	color: #fff;
	font-size: 14px;
	font-weight: bold;
	margin: 20px;
	width: 180px;
}

Syntax

<dimension> = <number><unit>

Values

  • <length>A distance, using units such as px, em, rem, vw, vh, cm or in.
  • <angle>A rotation, using the units deg, grad, rad or turn.
  • <time>A duration, using the units s or ms.
  • <frequency>A rate, using the units Hz or kHz.
  • <resolution>A pixel density, using the units dpi, dpcm, dppx or x.
  • <flex>A fraction of the free space in a grid container, using the unit fr.

Example

<div class="wrap">
<h1>CSS &lt;dimension&gt; examples</h1>
<div class="grid">
<div class="cell">
<div class="length"></div>
<div class="label">120px &times; 3rem</div>
</div>
<div class="cell">
<div class="angle"></div>
<div class="label">rotate(15deg), 600ms (hover)</div>
</div>
<div class="cell">
<div class="time"></div>
<div class="label">1.5s</div>
</div>
</div>
<p class="label">Columns: 1fr 2fr 1fr</p>
</div>
/* Demonstrates several kinds of  values */
* { box-sizing: border-box; }

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

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

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

/*  dimensions: 1fr and 2fr */
.grid {
  display: grid;
  grid-template-columns: 1fr 2fr 1fr;
  gap: 16px;
}

.cell {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 16px;
  text-align: center;
}

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

/*  dimensions */
.length {
  width: 120px;
  height: 3rem;
  margin: 0 auto;
  background: #38bdf8;
  border-radius: 6px;
}

/*  and 
Open in editor

Browser Support

The following information will show you the current browser support for the CSS dimension 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