MyInternships.in

Spacing and Sizing

Width and Height

Width (w-*) and height (h-*) utilities size elements using the spacing scale, fractions, percentages and viewport units.


Ways to set a size

ClassMeaning
w-164rem (64px) — from the scale
w-1/250% of the parent
w-full100% of the parent
w-screen100% of the viewport width
h-screen100% of the viewport height
max-w-mdCap the width at a readable size
Fractional widths in a row
Example
<div class="flex gap-2">
  <div class="w-1/3 bg-sky-500 text-white p-4 rounded text-center">1/3</div>
  <div class="w-2/3 bg-sky-700 text-white p-4 rounded text-center">2/3</div>
</div>

Constrain with max-width

w-full lets an element fill its parent, while max-w-* stops it getting too wide on large screens — ideal for readable text columns and cards.

A responsive card that never gets too wide
Example
<div class="w-full max-w-sm mx-auto bg-white p-6 rounded-xl shadow">
  <p>Full width on mobile, capped at max-w-sm on desktop.</p>
</div>
ℹ️

Common max-width steps: max-w-sm, max-w-md, max-w-lg, max-w-xl … up to max-w-7xl. Use them for content wrappers.

Related Tailwind Topics

Keep learning with these closely related lessons.