Skip to content
Tutorials Center
My learning

Topics

Lesson 7 of 37 ยท Utility Basics

Sizing: Width and Height

Control element dimensions with Tailwind v4: spacing-scale sizes, fractions, full and screen units, min and max limits, size-* and container-based max widths.

Width and height utilities decide how big an element is. They look simple (w-64, h-10), but sizing is where layouts usually go wrong: a box that overflows on a phone, an image that stretches, a page that is not quite as tall as the screen. This lesson gives you the full toolbox and a rule of thumb for when to use each tool.

Width and height from the scale

w-* and h-* use the same spacing scale as padding. w-64 is 16rem (256px), h-10 is 2.5rem (40px), and in v4 any number works (w-72, h-13).

HTML
<div class="h-10 w-64 bg-indigo-500"></div>

Beyond numbers, there are named values you will use constantly:

Class CSS Meaning
w-full width: 100% as wide as the parent
w-1/2, w-2/3, w-3/4 50%, 66.66%, 75% fractions of the parent
w-screen 100vw as wide as the viewport
w-auto auto the browser decides (default)
w-fit fit-content shrinks to content, up to the available space
w-min / w-max min-content / max-content narrowest / widest the content wants
h-screen 100vh as tall as the viewport
h-dvh, h-svh, h-lvh dynamic, small, large viewport height mobile browser safe versions

Heights behave differently from widths: a block's height is normally "as tall as its content", so percentage heights (h-full) only work when the parent has a defined height. Instead of fixing height, prefer padding and let content decide.

Fractions, full and fit

Min and max limits

The most useful sizing tools are the limits. They let an element be flexible but stay within bounds:

  • max-w-* stops an element from getting too wide. It is the key to readable text and responsive containers.
  • min-w-* prevents an element from shrinking too small (a common fix in flex rows with long text, together with min-w-0).
  • min-h-* guarantees a minimum height without limiting growth. min-h-screen makes a page at least as tall as the window, a classic for sticky footers.
  • max-h-* caps height, often with overflow-y-auto for scrolling panels.

The max-w scale in v4 uses named container sizes:

Class Width Class Width
max-w-xs 20rem max-w-3xl 48rem
max-w-sm 24rem max-w-4xl 56rem
max-w-md 28rem max-w-5xl 64rem
max-w-lg 32rem max-w-6xl 72rem
max-w-xl 36rem max-w-7xl 80rem
max-w-2xl 42rem max-w-prose 65ch

max-w-prose is special: it limits to about 65 characters, an ideal line length for reading. The classic page wrapper is mx-auto max-w-5xl px-4: centered, never wider than 64rem, with side padding on narrow screens.

max-w keeps text readable

The size utility

When width and height are equal, write one class: size-12 equals w-12 h-12. It is perfect for avatars, icon buttons and square spots:

HTML
<img class="size-10 rounded-full" src="/samples/sunset.svg" alt="">

size-full and size-fit also exist. This is a v3.4 feature that v4 keeps.

size-* for squares and circles

(The sunset image is one of our own sample files; in your project use your own images. object-cover makes an image fill its box without distortion.)

Arbitrary and fractional sizes

When the scale does not have what you need, write it in square brackets or point at a CSS variable (more in Arbitrary Values and !important):

HTML
<div class="w-[22.5rem] h-[calc(100dvh-4rem)]"></div>
<div class="w-(--sidebar-width)"></div>

Rules of thumb

  1. Let content decide height. Fix a width or a max width, and let height follow.
  2. Prefer max-w to w for containers. A fixed w-96 overflows on a 320px phone; w-full max-w-sm adapts.
  3. Use min-h-screen or min-h-dvh for full-page layouts, not h-screen, so long content can still grow.
  4. Use dvh for mobile. 100vh includes the part hidden behind a mobile browser's address bar; dvh adjusts as it collapses.
  5. Flex children need min-w-0 when they contain long unbreakable text; otherwise they refuse to shrink.
  6. Remember box sizing. Preflight sets box-sizing: border-box, so w-64 p-4 is still 16rem wide in total.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which pair is equivalent?

    size-* sets width and height to the same value.
  2. 2. Why is w-full max-w-sm usually better than w-96 for a card?

    w-96 is a fixed 24rem and can overflow on small screens. w-full max-w-sm shrinks with the parent and caps at 24rem.
  3. 3. Which class makes a page at least as tall as the browser window but still able to grow?

    min-h-screen sets a minimum height; content longer than the window can still extend the page.
  4. 4. What does max-w-prose limit text to?

    The prose measure is 65ch, a comfortable line length for reading.

Summary

  • w-* and h-* use the spacing scale, fractions, and keywords like full, screen, fit, min and max.
  • Prefer limits (max-w-*, min-h-*) over fixed sizes so layouts adapt.
  • size-* sets width and height together; max-w-prose gives readable text.
  • Use dvh for full-height mobile layouts and min-w-0 to let flex children shrink.

Next: Borders, Rings and Outlines