This paragraph will be about 65 characters wide - the ideal line length for comfortable reading.
Page Title
Your content here...
You're building a form, a card, or maybe a content section. Without any width constraints, it stretches all the way across the screen on large monitors and looks absolutely terrible.
This is where max-width comes in handy. It keeps your content readable and your designs looking professional, no matter what screen size your visitors are using.
Tailwind CSS gives you tons of max-width utilities out of the box, and I'm going to show you exactly how to use them.
Tailwind comes with preset max-width classes that cover most common use cases. These range from extra small (max-w-xs) all the way up to extra large (max-w-7xl).
Here's what they translate to in actual pixel values:
| Class | Width | Pixels (at 16px base) |
|---|---|---|
max-w-xs |
20rem | 320px |
max-w-sm |
24rem | 384px |
max-w-md |
28rem | 448px |
max-w-lg |
32rem | 512px |
max-w-xl |
36rem | 576px |
max-w-2xl |
42rem | 672px |
max-w-3xl |
48rem | 768px |
max-w-4xl |
56rem | 896px |
max-w-5xl |
64rem | 1024px |
max-w-6xl |
72rem | 1152px |
max-w-7xl |
80rem | 1280px |
These preset classes are perfect for cards, forms, and content containers. Let me show you how they look in action:
```html
This is max-w-xs (320px)
This is max-w-md (448px)
This is max-w-2xl (672px)
```
As you can see, each size serves a different purpose. I usually reach for max-w-md for forms, max-w-2xl for blog content, and max-w-5xl or larger for dashboard-style layouts.
There are also some special max-width values worth knowing about:
max-w-full - Sets max-width to 100% (useful for images)max-w-screen - Sets max-width to 100vw (full viewport width)max-w-none - Removes any max-width constraintmax-w-prose - Optimized for reading (around 65 characters per line)Here's where things get really powerful. You can apply different max-width values at different breakpoints using Tailwind's responsive prefixes.
The pattern is simple: {breakpoint}:max-w-{size}
For example, md:max-w-lg means "apply max-w-lg starting at the medium breakpoint". This is super useful when you want full-width elements on mobile but constrained widths on larger screens.
Let me show you a real-world example. Say you're building a hero section that should be full-width on mobile but have a max-width on desktop:
```html
Your Hero Title
This container is full-width on mobile, 896px on tablets, and 1152px on desktops
```
This pattern is everywhere in modern web design. Your content breathes on mobile, but stays readable and focused on larger screens.
You can also go the other direction – start with a constraint and remove it at larger breakpoints using max-w-none:
```html
```
The responsive approach gives you total control over how your layout adapts. Start mobile-first and progressively enhance for larger screens.
Sometimes you don't want a fixed pixel width – you want something relative to the parent container. That's where fractional max-width classes come in.
Tailwind provides these out of the box:
max-w-1/2 - 50% of parentmax-w-1/3 and max-w-2/3 - Thirdsmax-w-1/4, max-w-2/4, max-w-3/4 - Quartersmax-w-1/5 through max-w-4/5 - FifthsThese are perfect for creating flexible layouts that adapt to their container size. Let me show you a two-column layout example:
```html
Main content (66.67% width)
Sidebar (33.33% width)
```
The big difference between fractional widths and fixed widths is how they behave when the parent container changes size. Fixed widths stay... well, fixed. Fractional widths scale proportionally.
Here's when I use each:
| Use Case | Width Type | Why |
|---|---|---|
| Blog post content | Fixed (max-w-2xl) |
Consistent reading width regardless of screen |
| Dashboard cards | Fractional (max-w-1/3) |
Adapt to available space in the layout |
| Form inputs | Fixed (max-w-md) |
Predictable, comfortable input width |
| Image galleries | Fractional (max-w-1/4) |
Fill available space evenly |
You can also combine fractional widths with responsive prefixes for even more control: max-w-full md:max-w-1/2 lg:max-w-1/3
What if the preset values don't fit your design? No problem. Tailwind lets you use arbitrary values with bracket notation.
The syntax is straightforward: max-w-[value]
You can use any CSS unit – pixels, rems, ems, percentages, viewport units, even calc():
```html
Custom pixel width
Custom rem width
85% of parent
90% of viewport
Dynamic calculation
```
Each unit has its place:
My go-to choice? Rems for most cases. They respect user preferences and scale nicely. I'll use pixels when I need exact control (like matching a design mockup), and character units for text-heavy content.
Here's a practical example using ch units for optimal reading width:
```html
This paragraph will be about 65 characters wide -
the ideal line length for comfortable reading.
```
The ch unit is seriously underrated for text content. It keeps your text readable regardless of font family or size.
Here's the pattern you'll see everywhere: combine max-w-* with mx-auto to center content on the page.
The mx-auto class sets left and right margins to auto, which pushes the element to the center. When you pair it with a max-width, you get a perfectly centered container that never gets too wide.
```html
Centered Content
This container is centered and has a max-width of 896px
```
Notice I also added px-4 in the example? That's padding on the left and right. Without it, your content would touch the edges on mobile. Always add horizontal padding when centering content.
Here's a complete example showing a typical page layout:
```html
Page Title
Your content here...
```
This layered approach – wider outer container, narrower inner content – gives you flexibility while maintaining visual hierarchy. The outer container (max-w-6xl) holds everything, but the article content (max-w-2xl) stays narrow for better reading.
You can nest max-widths as much as needed. Just remember that an inner max-width can only make things narrower, never wider than its parent.
That's everything you need to know about using max-width in Tailwind CSS. Start with the preset classes, use responsive breakpoints to adapt your layouts, and reach for arbitrary values when you need custom widths.
The combination of max-w-* and mx-auto will become second nature once you start using it. It's one of those patterns that just works.
Get notified when we add new templates, components, and more!
WindyBase is a weekly curated Tailwind CSS template and tool directory built for the modern developer.
© 2025 WindyBase. All rights reserved.