---
title: "Width & Height"
description: "Arithmetic dimensions, fractions, content and viewport sizing, and explicit constraints. Density does not change geometric sizes."
slug: "width-height"
---

import { DocPage, PageHeader, SkillPanel, Example, ExampleLabel, ExampleHint, ExampleCode, SourceFiles, SourceNote, StatesSection, CodeBlock, Demo, DemoCode, ChangelogEntries, ArchBody, StatsClaim, StatsCards, PageOverlay, DocText, DocLink, H2, SkillField, SkillText, SkillRow, SkillGrid, Variant, ApiPill, Dim, CodeCard, TableCard } from "../../lib/components/index";

<DocPage meta={meta}>

<PageHeader slug="width-height" title="Width &amp; Height" introStyle="max-width:38rem;">
  Arithmetic dimensions, fractions, content and viewport sizing, and explicit constraints. Density does not change geometric sizes. Every code block shows exactly the classes that render the demo above it; demos marked with a width toolbar can be resized between Mobile, Tablet and Desktop.
</PageHeader>

<h2 id="numeric" class="h2-display">Numeric dimensions</h2>

<DocText><code>w-n</code>, <code>h-n</code> and <code>size-n</code> map directly to <code>n × --size-base</code> - <code>w-48</code> is 48 × 4px = 192px at the default root. Width and height are physical axes, matching their CSS names, and density does not change them.</DocText>

```html example schema="none"
<div class="stack gap-4" data-demo="width-height">
  <div class="demo-tile w-48 h-8">w-48 h-8</div>
  <div class="demo-tile w-24 h-8">w-24 h-8</div>
  <div class="flex items-center gap-3">
    <div class="demo-tile size-8"></div>
    <span class="demo-label demo-label-inline">size-8 - same in both axes</span>
  </div>
</div>
```


<div class="sep" />

<h2 id="fractions" class="h2-display">Fractions and full width</h2>

<DocText><code>w-1/2</code>, <code>w-1/3</code>, <code>w-2/3</code>, <code>w-1/4</code>, <code>w-3/4</code> and <code>w-full</code> size against the containing block. Percentage heights like <code>h-1/2</code> need a definite containing height.</DocText>

```html example schema="none"
<div class="stack gap-3">
  <div class="demo-tile w-full h-6">w-full</div>
  <div class="demo-tile w-3/4 h-6">w-3/4</div>
  <div class="demo-tile w-2/3 h-6">w-2/3</div>
  <div class="demo-tile w-1/2 h-6">w-1/2</div>
  <div class="demo-tile w-1/3 h-6">w-1/3</div>
  <div class="demo-tile w-1/4 h-6">w-1/4</div>
</div>
```


<DocText>The classic sidebar/main split - resize the demo with the toolbar and watch it adapt:</DocText>

```html example schema="none"
<div class="flex flex-wrap gap-4">
  <aside class="w-1/3 demo-tile demo-outline h-24" data-variant="muted" style="min-width: 8rem">w-1/3 - Filters</aside>
  <section class="demo-tile h-24" style="flex: 1; min-width: 12rem">w-2/3 - Results</section>
</div>
```


<div class="sep" />

<h2 id="intrinsic" class="h2-display">Content-based sizing</h2>

<DocText><code>w-auto</code> defers to the layout algorithm; <code>w-fit</code> shrinks to the content; <code>w-min</code> and <code>w-max</code> use the content's minimum and maximum intrinsic widths. These are the right tools for badges, chips and buttons that should hug their label.</DocText>

```html example schema="none"
<div class="stack gap-3">
  <div class="demo-tile w-fit h-6 px-2" data-variant="secondary">w-fit hugs this label</div>
  <div class="demo-tile w-min h-6 px-2" data-variant="secondary">w-min wraps early</div>
  <div class="demo-tile w-auto h-6 px-2" data-variant="secondary"
    >w-auto fills the block direction like any block box</div
  >
</div>
```


<div class="sep" />

<h2 id="constraints" class="h2-display">Constraints: min, max and none</h2>

<DocText>Dimensions are constraints, not clipping. <code>max-w-\*</code> caps a box without narrowing the page below the cap; <code>min-h-\*</code> guarantees a floor while content can grow past it; <code>max-w-none</code> removes a cap a component shipped with.</DocText>

```html example schema="none"
<div class="stack gap-4">
  <div class="demo-tile max-w-32 h-auto p-2" data-variant="muted"
    >max-w-32 caps this note at 128px, whatever the page does</div
  >
  <div class="demo-tile min-h-24 p-2" data-variant="outline"
    >min-h-24 keeps this box at least 96px tall even with one line of content</div
  >
</div>
```


<DocText>In flex layouts a requested width may shrink: add <code>shrink-0</code> when that is intentional, and put <code>min-w-0</code> on the flexible child so long content wraps instead of widening the page:</DocText>

```html example schema="none"
<div class="flex gap-4">
  <aside class="demo-tile w-24 shrink-0 h-16">w-24 shrink-0</aside>
  <main
    class="flex-1 min-w-0 wrap-anywhere demo-tile h-auto p-2"
    data-variant="outline"
    style="justify-content: flex-start"
    >flex-1 min-w-0 - AnUnusuallyLongIdentifierThatMustWrapInsteadOfWideningThePage</main
  >
</div>
```


<DocText>A constrained box turns its overflow into a scrollbar with <code>overflow-x-auto</code>; pair it with <code>whitespace-nowrap</code> on the content so wide rows scroll instead of wrapping into a mess:</DocText>

```html example schema="none"
<div
  class="demo-tile demo-outline max-w-64 overflow-x-auto"
  data-variant="muted"
  style="display: block; padding: 0.75rem"
>
  <table class="table whitespace-nowrap" style="font-size: 0.8125rem">
    <thead
      ><tr class="table-row"
        ><th class="table-head">Component</th><th class="table-head">Native basis</th
        ><th class="table-head">Needs JS</th></tr
      ></thead
    >
    <tbody>
      <tr class="table-row"
        ><td class="table-cell">Dialog</td><td class="table-cell">&lt;dialog&gt; + showModal()</td
        ><td class="table-cell">State API only</td></tr
      >
      <tr class="table-row"
        ><td class="table-cell">Accordion</td><td class="table-cell">&lt;details name&gt;</td
        ><td class="table-cell">No</td></tr
      >
    </tbody>
  </table>
</div>
```


<div class="sep" />

<h2 id="logical" class="h2-display">Logical dimensions</h2>

<DocText><code>inline-\*</code> and <code>block-\*</code> mirror the numeric scale on the writing-mode axes: inline is width in horizontal writing, height in vertical writing. Below, the same classes - <code>inline-40 block-24 ps-4</code> - in three contexts. The filled area is the content box; the gap the <code>ps-4</code> leaves follows inline-start: left in LTR, right in RTL, top in vertical writing.</DocText>

```html example schema="none"
<div class="flex flex-wrap gap-6">
  <div>
    <p class="demo-label">LTR</p>
    <div
      class="demo-tile inline-40 block-24 ps-4"
      data-variant="outline"
      style="padding-block: 0.25rem; padding-inline-end: 0.25rem"
    >
      <div class="demo-tile h-full" data-variant="muted" style="flex: 1">content</div>
    </div>
  </div>
  <div dir="rtl">
    <p class="demo-label">RTL - same classes</p>
    <div
      class="demo-tile inline-40 block-24 ps-4"
      data-variant="outline"
      style="padding-block: 0.25rem; padding-inline-end: 0.25rem"
    >
      <div class="demo-tile h-full" data-variant="muted" style="flex: 1">content</div>
    </div>
  </div>
  <div>
    <p class="demo-label">vertical-rl - same classes</p>
    <div
      class="demo-tile inline-40 block-24 ps-4"
      data-variant="outline"
      style="writing-mode: vertical-rl; padding-block: 0.25rem; padding-inline-end: 0.25rem"
    >
      <div class="demo-tile" data-variant="muted" style="flex: 1; inline-size: 100%">content</div>
    </div>
  </div>
</div>
```


<div class="sep" />

<h2 id="viewport" class="h2-display">Viewport sizes and the app shell</h2>

<DocText><code>h-screen</code> / <code>min-h-screen</code> / <code>max-h-screen</code> are 100vh, with <code>dvh</code>, <code>svh</code> and <code>lvh</code> variants for mobile browser chrome. Their classic use is the app shell - header, fluid content, footer at the bottom even with little content. The demo renders that pattern inside a fixed-height frame; at page level you would write <code>min-h-screen</code> instead of <code>h-full</code>.</DocText>

```html example schema="none"
<div class="demo-outline" style="block-size: 16rem">
  <div class="stack h-full gap-0">
    <header class="demo-tile h-10" style="border-radius: 0">header</header>
    <div class="flex-1 min-h-0 demo-tile h-auto" data-variant="muted">flex-1 - content fills whatever is left</div>
    <footer class="demo-tile h-10" data-variant="secondary" style="border-radius: 0"
      >footer - pushed down, never floating mid-page</footer
    >
  </div>
</div>
```


<DocText>Prefer <code>dvh</code> units when content must survive the mobile URL bar collapsing. <code>w-screen</code> is 100vw - it includes the scrollbar and ignores the parent, so <code>w-full</code> is usually the right choice inside a page.</DocText>

<div class="sep" />

<h2 id="app-layout" class="h2-display">Real world: a fixed sidebar and a fluid main</h2>

<DocText>The most common layout on the web: a fixed-width sidebar that never squishes (<code>w-56 shrink-0</code>) next to a main region that takes whatever is left (<code>flex-1 min-w-0</code>). Resize with the toolbar - the sidebar holds 224px while the main column gives.</DocText>

```html example schema="none"
<div class="flex gap-4">
  <aside class="demo-tile w-56 shrink-0 h-40" data-variant="secondary">w-56 shrink-0 - nav</aside>
  <main class="flex-1 min-w-0 stack gap-3">
    <div class="demo-tile h-10">flex-1 - page title bar</div>
    <div class="flex gap-3">
      <div class="demo-tile flex-1 h-24" data-variant="muted">flex-1</div>
      <div class="demo-tile flex-1 h-24" data-variant="muted">flex-1</div>
      <div class="demo-tile w-24 shrink-0 h-24" data-variant="accent">w-24</div>
    </div>
  </main>
</div>
```


<div class="sep" />

<h2 id="real-world" class="h2-display">Real world: profile rows</h2>

<DocText>A comment/mention row: square avatar (<code>size-10 shrink-0</code>), text that can shrink and wrap (<code>flex-1 min-w-0</code>), and a timestamp that never wraps (<code>shrink-0</code>). Every width on the row is one of the utilities from this page.</DocText>

```html example schema="none"
<div class="stack gap-4" style="max-width: 26rem">
  <div class="flex items-center gap-3">
    <div class="demo-tile size-10 shrink-0" data-variant="accent">AL</div>
    <div class="flex-1 min-w-0">
      <p class="row-title">Ada Lovelace</p>
      <p
        class="text-muted-foreground"
        style="margin: 0; font-size: 0.8125rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap"
        >left a comment on the sizing module</p
      >
    </div>
    <span class="demo-label shrink-0 demo-label-inline">2h</span>
  </div>
  <div class="flex items-center gap-3">
    <div class="demo-tile size-10 shrink-0" data-variant="secondary">GR</div>
    <div class="flex-1 min-w-0">
      <p class="row-title">Grace Hopper</p>
      <p
        class="text-muted-foreground"
        style="margin: 0; font-size: 0.8125rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap"
        >approved the request</p
      >
    </div>
    <span class="demo-label shrink-0 demo-label-inline">5h</span>
  </div>
</div>
```


<div class="sep" />

<h2 id="available" class="h2-display">Available classes</h2>

<div class="overflow-x-auto mb-6">
  <table class="table" data-variant="simple">
    <thead>
      <tr>
        <th scope="col">Family</th>
        <th scope="col">Values</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>
          <code>w-\*, h-\*, size-\*, min-w-\*, min-h-\*, max-w-\*, max-h-\*</code>
        </td>
        <td>Numeric scale below; <code>px</code> = one CSS pixel.</td>
      </tr>
      <tr>
        <td>
          <code>inline-\*, block-\*</code>
        </td>
        <td>Numeric scale; <code>px</code>; auto/full/min/max/fit; fractions.</td>
      </tr>
      <tr>
        <td>
          <code>w-\*, h-\*</code>
        </td>
        <td>auto, full, min, max, fit; 1/2, 1/3, 2/3, 1/4, 3/4.</td>
      </tr>
      <tr>
        <td>
          <code>min-w-\*, min-h-\*, max-w-\*, max-h-\*</code>
        </td>
        <td>full, min, max, fit; max-w-none and max-h-none remove caps.</td>
      </tr>
      <tr>
        <td>
          <code>h-\*, min-h-\*, max-h-\*</code>
        </td>
        <td>screen (100vh), dvh, svh, lvh.</td>
      </tr>
      <tr>
        <td>
          <code>w-screen</code>
        </td>
        <td>100vw; includes viewport width rather than parent width.</td>
      </tr>
      <tr>
        <td>
          <code>box-border, box-content</code>
        </td>
        <td>Explicit box-sizing; no global reset is installed.</td>
      </tr>
    </tbody>
  </table>
</div>

<DocText>The numeric scale, rendered - every bar below is its real class at the default 4px base. Values not listed require ordinary CSS. <code>size-4</code> sets both width and height; it does not set flex-shrink or box-sizing.</DocText>

```html example schema="none"
<div class="stack gap-2" data-demo="scale">
  <div class="flex items-center gap-3">
    <span class="demo-label demo-label-end">0</span>
    <div class="demo-tile w-0 h-3" style="min-width: 1px"></div>
    <span class="demo-label demo-label-inline">0px</span>
  </div>
  <div class="flex items-center gap-3">
    <span class="demo-label demo-label-end">0.5</span>
    <div class="demo-tile w-0.5 h-3"></div>
    <span class="demo-label demo-label-inline">2px</span>
  </div>
  <div class="flex items-center gap-3">
    <span class="demo-label demo-label-end">1</span>
    <div class="demo-tile w-1 h-3"></div>
    <span class="demo-label demo-label-inline">4px</span>
  </div>
  <div class="flex items-center gap-3">
    <span class="demo-label demo-label-end">1.5</span>
    <div class="demo-tile w-1.5 h-3"></div>
    <span class="demo-label demo-label-inline">6px</span>
  </div>
  <div class="flex items-center gap-3">
    <span class="demo-label demo-label-end">2</span>
    <div class="demo-tile w-2 h-3"></div>
    <span class="demo-label demo-label-inline">8px</span>
  </div>
  <div class="flex items-center gap-3">
    <span class="demo-label demo-label-end">2.5</span>
    <div class="demo-tile w-2.5 h-3"></div>
    <span class="demo-label demo-label-inline">10px</span>
  </div>
  <div class="flex items-center gap-3">
    <span class="demo-label demo-label-end">3</span>
    <div class="demo-tile w-3 h-3"></div>
    <span class="demo-label demo-label-inline">12px</span>
  </div>
  <div class="flex items-center gap-3">
    <span class="demo-label demo-label-end">3.5</span>
    <div class="demo-tile w-3.5 h-3"></div>
    <span class="demo-label demo-label-inline">14px</span>
  </div>
  <div class="flex items-center gap-3">
    <span class="demo-label demo-label-end">4</span>
    <div class="demo-tile w-4 h-3"></div>
    <span class="demo-label demo-label-inline">16px</span>
  </div>
  <div class="flex items-center gap-3">
    <span class="demo-label demo-label-end">5</span>
    <div class="demo-tile w-5 h-3"></div>
    <span class="demo-label demo-label-inline">20px</span>
  </div>
  <div class="flex items-center gap-3">
    <span class="demo-label demo-label-end">6</span>
    <div class="demo-tile w-6 h-3"></div>
    <span class="demo-label demo-label-inline">24px</span>
  </div>
  <div class="flex items-center gap-3">
    <span class="demo-label demo-label-end">7</span>
    <div class="demo-tile w-7 h-3"></div>
    <span class="demo-label demo-label-inline">28px</span>
  </div>
  <div class="flex items-center gap-3">
    <span class="demo-label demo-label-end">8</span>
    <div class="demo-tile w-8 h-3"></div>
    <span class="demo-label demo-label-inline">32px</span>
  </div>
  <div class="flex items-center gap-3">
    <span class="demo-label demo-label-end">9</span>
    <div class="demo-tile w-9 h-3"></div>
    <span class="demo-label demo-label-inline">36px</span>
  </div>
  <div class="flex items-center gap-3">
    <span class="demo-label demo-label-end">10</span>
    <div class="demo-tile w-10 h-3"></div>
    <span class="demo-label demo-label-inline">40px</span>
  </div>
  <div class="flex items-center gap-3">
    <span class="demo-label demo-label-end">11</span>
    <div class="demo-tile w-11 h-3"></div>
    <span class="demo-label demo-label-inline">44px</span>
  </div>
  <div class="flex items-center gap-3">
    <span class="demo-label demo-label-end">12</span>
    <div class="demo-tile w-12 h-3"></div>
    <span class="demo-label demo-label-inline">48px</span>
  </div>
  <div class="flex items-center gap-3">
    <span class="demo-label demo-label-end">14</span>
    <div class="demo-tile w-14 h-3"></div>
    <span class="demo-label demo-label-inline">56px</span>
  </div>
  <div class="flex items-center gap-3">
    <span class="demo-label demo-label-end">16</span>
    <div class="demo-tile w-16 h-3"></div>
    <span class="demo-label demo-label-inline">64px</span>
  </div>
  <div class="flex items-center gap-3">
    <span class="demo-label demo-label-end">20</span>
    <div class="demo-tile w-20 h-3"></div>
    <span class="demo-label demo-label-inline">80px</span>
  </div>
  <div class="flex items-center gap-3">
    <span class="demo-label demo-label-end">24</span>
    <div class="demo-tile w-24 h-3"></div>
    <span class="demo-label demo-label-inline">96px</span>
  </div>
  <div class="flex items-center gap-3">
    <span class="demo-label demo-label-end">28</span>
    <div class="demo-tile w-28 h-3"></div>
    <span class="demo-label demo-label-inline">112px</span>
  </div>
  <div class="flex items-center gap-3">
    <span class="demo-label demo-label-end">32</span>
    <div class="demo-tile w-32 h-3"></div>
    <span class="demo-label demo-label-inline">128px</span>
  </div>
  <div class="flex items-center gap-3">
    <span class="demo-label demo-label-end">36</span>
    <div class="demo-tile w-36 h-3"></div>
    <span class="demo-label demo-label-inline">144px</span>
  </div>
  <div class="flex items-center gap-3">
    <span class="demo-label demo-label-end">40</span>
    <div class="demo-tile w-40 h-3"></div>
    <span class="demo-label demo-label-inline">160px</span>
  </div>
  <div class="flex items-center gap-3">
    <span class="demo-label demo-label-end">48</span>
    <div class="demo-tile w-48 h-3"></div>
    <span class="demo-label demo-label-inline">192px</span>
  </div>
  <div class="flex items-center gap-3">
    <span class="demo-label demo-label-end">56</span>
    <div class="demo-tile w-56 h-3"></div>
    <span class="demo-label demo-label-inline">224px</span>
  </div>
  <div class="flex items-center gap-3">
    <span class="demo-label demo-label-end">64</span>
    <div class="demo-tile w-64 h-3"></div>
    <span class="demo-label demo-label-inline">256px</span>
  </div>
  <div class="flex items-center gap-3">
    <span class="demo-label demo-label-end">72</span>
    <div class="demo-tile w-72 h-3"></div>
    <span class="demo-label demo-label-inline">288px</span>
  </div>
  <div class="flex items-center gap-3">
    <span class="demo-label demo-label-end">80</span>
    <div class="demo-tile w-80 h-3"></div>
    <span class="demo-label demo-label-inline">320px</span>
  </div>
  <div class="flex items-center gap-3">
    <span class="demo-label demo-label-end">96</span>
    <div class="demo-tile w-96 h-3"></div>
    <span class="demo-label demo-label-inline">384px</span>
  </div>
</div>
```


<div class="sep" />

<h2 id="custom" class="h2-display">Application-specific sizes</h2>

<DocText>Values outside the scale are ordinary CSS - a clamped inspector panel and an optimal reading width. Resize with the toolbar: the inspector's <code>clamp()</code> tracks the frame width while the prose column stays at its measure.</DocText>

```html example schema="none"
<div class="flex flex-wrap gap-4">
  <aside class="demo-tile h-32 p-2" data-variant="accent" style="width: clamp(10rem, 35%, 14rem)"
    >inspector - clamp(10rem, 35%, 14rem)</aside
  >
  <article
    class="demo-tile h-auto p-4"
    data-variant="muted"
    style="max-inline-size: 38ch; flex: 1; min-width: 14rem; display: block"
    >article-copy - max-inline-size keeps the measure readable no matter how wide the frame gets. This sentence just
    fills space to make the line length visible.</article
  >
</div>
```

```css
.inspector { width: clamp(16rem, 30vw, 24rem); }
.application-shell { min-height: 100dvh; }
.article-copy { max-inline-size: 70ch; }
```


<DocText>Keep content widths, typography and control recipes semantically distinct from the small geometric <code>--size-xs...xl</code> aliases. Load sizing.css; load layout.css as well for Flex/Grid helpers.</DocText>

<div class="sep" />

<h2 id="references" class="h2-display">Platform references</h2>

<DocText><a class="link" href="https://www.w3.org/TR/css-values-4/" target="_blank" rel="noopener">CSS Values and Units</a> · <a class="link" href="https://www.w3.org/TR/css-logical-1/" target="_blank" rel="noopener">CSS logical properties</a></DocText>

</DocPage>
