See all posts

Tailwind Width: How to use Tailwind CSS Width and examples

Tailwind Width: How to use Tailwind CSS Width and examples

Tailwind CSS Width

Tailwind CSS makes it easy to control layout without writing custom CSS. Instead of jumping between stylesheets, you can define widths directly in your markup using simple utility classes.

This guide walks through Tailwind’s width utilities, including width, max-width, and min-width, with clear explanations, practical examples, and real use cases you’ll run into when building layouts.

Table of content

Tailwind Width

The Tailwind width utility lets you set an element’s width using predefined classes. These range from very small values like w-0 up to layout-based values such as w-full and w-screen.

Because these utilities are based on Tailwind’s spacing scale, they stay consistent across your layout and remove the need for one-off CSS rules.

html
<div class="w-32">This div is 128 pixels wide.</div>

Tailwind Width Classes

Tailwind provides a wide set of width utilities, covering fixed sizes, percentages, viewport widths, and content-based sizing.

These classes map directly to CSS width values, which makes them predictable and easy to reason about.

ClassProperties
w-0width: 0px;
w-pxwidth: 1px;
w-0.5width: 0.125rem; /_ 2px _/
w-1width: 0.25rem; /_ 4px _/
w-1.5width: 0.375rem; /_ 6px _/
w-2width: 0.5rem; /_ 8px _/
w-2.5width: 0.625rem;/_10px _/
w-3width: 0.75rem; /_ 12px _/
w-3.5width: 0.875rem; /_ 14px _/
w-4width: 1rem; /_ 16px _/
w-5width: 1.25rem; /_ 20px _/
w-6width: 1.5rem; /_ 24px _/
w-7width: 1.75rem; /_ 28px _/
w-8width: 2rem; /_ 32px _/
w-9width: 2.25rem; /_ 36px _/
w-10width: 2.5rem; /_ 40px _/
w-11width: 2.75rem; /_ 44px _/
w-12width: 3rem; /_ 48px _/
w-14width: 3.5rem; /_ 56px _/
w-16width: 4rem; /_ 64px _/
w-20width: 5rem; /_ 80px _/
w-24width: 6rem; /_ 96px _/
w-28width: 7rem; /_ 112px _/
w-32width: 8rem; /_ 128px _/
w-36width: 9rem; /_ 144px _/
w-40width: 10rem; /_ 160px _/
w-44width: 11rem; /_ 176px _/
w-48width: 12rem; /_ 192px _/
w-52width: 13rem; /_ 208px _/
w-56width: 14rem; /_ 224px _/
w-60width: 15rem; /_ 240px _/
w-64width: 16rem; /_ 256px _/
w-72width: 18rem; /_ 288px _/
w-80width: 20rem; /_ 320px _/
w-96width: 24rem; /_ 384px _/
w-autowidth: auto;
w-1/2width: 50%;
w-1/3width: 33.333333%;
w-2/3width: 66.666667%;
w-1/4width: 25%;
w-2/4width: 50%;
w-3/4width: 75%;
w-1/5width: 20%;
w-2/5width: 40%;
w-3/5width: 60%;
w-4/5width: 80%;
w-1/6width: 16.666667%;
w-2/6width: 33.333333%;
w-3/6width: 50%;
w-4/6width: 66.666667%;
w-5/6width: 83.333333%;
w-1/12width: 8.333333%;
w-2/12width: 16.666667%;
w-3/12width: 25%;
w-4/12width: 33.333333%;
w-5/12width: 41.666667%;
w-6/12width: 50%;
w-7/12width: 58.333333%;
w-8/12width: 66.666667%;
w-9/12width: 75%;
w-10/12width: 83.333333%;
w-11/12width: 91.666667%;
w-fullwidth: 100%;
w-screenwidth: 100vw;
w-minwidth: min-content;
w-maxwidth: max-content;
w-fitwidth: fit-content;

How to apply Tailwind CSS Width

Applying width in Tailwind is as simple as adding a class to your element. The utility does exactly one thing: sets the width.

html
<div class="w-1/2">This element has a width of half the parent container.</div>

This approach keeps layout decisions visible in your markup, which is especially helpful when scanning or refactoring components later.

How to Set Full Width in Tailwind

To make an element span the full width of its parent, use w-full. This is commonly used for containers, buttons, inputs, and layout wrappers.

html
<div class="w-full">
This div will stretch to the full width of its container.
</div>

Preview

This div will take up the full width of its parent container.

Tailwind Fixed width

Fixed widths are useful when an element should always stay the same size, regardless of screen width. Common examples include avatars, icons, cards, and sidebars.

html
<div class="flex justify-center items-center">
<div class="w-20">width of 80px</div>
<div class="w-32">width of 80px</div>
<div class="w-40">width of 80px</div>
</div>

Preview

width of 80px
width of 128px
width of 160px

Because these values come from the spacing scale, they stay consistent with padding and margin utilities.

Percentage-Based Widths

Tailwind supports fractional widths that map directly to percentages. These are ideal for grid-like layouts and proportional spacing

html
<div class="flex flex-col items-center justify-center">
<div class="w-2/6">width of 33.33%</div>
<div class="w-1/2">width of 50%</div>
<div class="w-3/4">width of 75%</div>
</div>

Preview

width of 33.33%
width of 50%
width of 75%

Fractional widths work well inside flex and grid layouts and help avoid hardcoded values.

Responsive Width Adjustments

Tailwind’s responsive prefixes let you change widths at different breakpoints without writing media queries.

html
<div class="w-full md:w-1/2 lg:w-1/4">
This element has a full width on small screens, half width on medium screens,
and one-fourth width on large screens.
</div>

Preview

This element has a full width on small screens, half width on medium screens, and one-fourth width on large screens.

This pattern is common for cards, sidebars, and multi-column layouts.

Customizing Widths with Tailwind

If the default scale doesn’t cover a specific design requirement, you can extend it in your Tailwind configuration.

js
module.exports = {
theme: {
extend: {
width: {
96: "24rem", // Adds a new width utility for 24rem
},
},
},
};
html
<div class="text-lg w-96">This div has with of 24rem</div>

Custom values should be added sparingly, but they’re useful when working with fixed design constraints.

Tailwind Max Width

Max width is commonly used to keep content readable, especially for text-heavy sections. Instead of letting content stretch across large screens, you can cap its width while keeping it responsive.

Tailwind’s max-width utilities range from small sizes like max-w-xs to layout-focused values like max-w-prose and max-w-screen-lg.

Tailwind Max Width Classes

Below are some classes used in Tailwind CSS for max width.

ClassProperties
max-w-0max-width: 0rem;
max-w-nonemax-width: none;
max-w-xsmax-width: 20rem;
max-w-smmax-width: 24rem;
max-w-mdmax-width: 28rem;
max-w-lgmax-width: 32rem;
max-w-xlmax-width: 36rem;
max-w-2xlmax-width: 42rem;
max-w-3xlmax-width: 48rem;
max-w-4xlmax-width: 56rem;
max-w-5xlmax-width: 64rem;
max-w-6xlmax-width: 72rem;
max-w-7xlmax-width: 80rem;
max-w-fullmax-width: 100%;
max-w-minmax-width: min-content;
max-w-maxmax-width: max-content;
max-w-prosemax-width: 65ch;
max-w-screen-smmax-width: 640px;
max-w-screen-mdmax-width: 768px;
max-w-screen-lgmax-width: 1024px;
max-w-screen-xlmax-width: 1280px;
max-w-screen-2xlmax-width: 1536px;

How to Use Tailwind Max Width

To use max width, add a max-w-* class to your element. This limits how wide it can grow while still allowing it to shrink on smaller screens.

  • max-w-md sets the max width to 40rem (medium-sized screens)
  • max-w-lg sets the max width to 60rem (large screens)
html
<div class="flex">
<div class="w-1/2 bg-indigo-600 h-12 rounded-l-lg">w-1/2</div>
<div class="w-1/2 bg-indigo-500 h-12 rounded-r-lg">w-1/2</div>
</div>
<div class="flex ...">
<div class="w-2/5 bg-indigo-600 h-12 rounded-l-lg">w-2/5</div>
<div class="w-3/5 bg-indigo-500 h-12 rounded-r-lg">w-3/5</div>
</div>
<div class="flex ...">
<div class="w-1/3 bg-indigo-600 h-12 rounded-l-lg">w-1/3</div>
<div class="w-2/3 bg-indigo-500 h-12 rounded-r-lg">w-2/3</div>
</div>
<div class="flex ...">
<div class="w-1/4 bg-indigo-600 h-12 rounded-l-lg">w-1/4</div>
<div class="w-3/4 bg-indigo-500 h-12 rounded-r-lg">w-3/4</div>
</div>
<div class="flex ...">
<div class="w-1/5 bg-indigo-600 h-12 rounded-l-lg">w-1/5</div>
<div class="w-4/5 bg-indigo-500 h-12 rounded-r-lg">w-4/5</div>
</div>
<div class="flex ...">
<div class="w-1/6 bg-indigo-600 h-12 rounded-l-lg">w-1/6</div>
<div class="w-5/6 bg-indigo-500 h-12 rounded-r-lg">w-5/6</div>
</div>
<div class="w-full bg-indigo-500 h-12 rounded-lg">w-full</div>

Preview

w-1/2
w-1/2
w-2/5
w-3/5
w-1/3
w-2/3
w-1/4
w-3/4
w-1/5
w-4/5
w-1/6
w-5/6
w-full

To use max width, add a max-w-* class to your element. This limits how wide it can grow while still allowing it to shrink on smaller screens.

Tailwind Min Width

Min width ensures an element never shrinks below a certain size. This is useful for buttons, table columns, and layout elements that shouldn’t collapse.

If the content exceeds the minimum width, the element will grow naturally.

Tailwind Min-Width Classes

ClassProperties
min-w-0min-width: 0px;
min-w-fullmin-width: 100%;
min-w-minmin-width: min-content;
min-w-maxmin-width: max-content;
min-w-fitmin-width: fit-content;

If the content is bigger than the minimum width, the min-width property has no impact. This prevents the width property's value from being less than the min-width. You can also check out Tailwind min-width page to learn more.

How to Use Tailwind Min Width

html
<div className="w-24 min-w-full bg-indigo-600 h-12 rounded">min-w-full</div>
<div className="w-12 min-w-0 bg-indigo-300 h-12 rounded">min-w-0</div>
<div className="w-12 min-w-max bg-indigo-300 h-12 rounded">min-w-max</div>
<div className="flex ...">
<div className="w-24 min-w-fit bg-indigo-600 h-12 rounded">min-w-fit</div>
<div className=" w-24 min-w-mini bg-indigo-300 h-12">min-w-mini</div>
</div>

Preview

min-w-full

min-w-0

min-w-max

min-w-fit

min-w-mini

Min width is especially helpful in flex layouts where items might otherwise shrink too much.

Customizing Tailwind Max Width, and Min Width

While Tailwind provides a range of pre-defined max width and min width classes, you may need to create custom values for your project. Luckily, Tailwind makes it easy to do so. Simply add custom values to your tailwind.config.js file, like so:

js
module.exports = {
maxWidth: {
100: "800px",
},
minWidth: {
100: "200px",
},
};

This will add new width, max width, and min width classes max-w-100, and min-w-100, which set the max width, and min width to 800px, and 200px respectively.

Conclusion

Tailwind’s width utilities cover almost every layout scenario you’ll encounter. Fixed widths work well for consistent components, fractional widths simplify responsive layouts, and max-width keeps content readable on large screens.

With responsive variants and custom values, you can shape layouts directly in your markup without falling back to custom CSS, and without losing control over consistency.


Windframe is an AI visual editor for rapidly building stunning web UIs & websites

Start building stunning web UIs & websites!

Build from scratch or select prebuilt tailwind templates