Tailwind CSS Max-Width
Setting a Tailwind max-width prevents content from growing too wide, maintaining readability and visual balance—especially in centered layouts, modals, articles, and dashboards.
Tailwind Max Width
The max-width
utility class in Tailwind CSS allows you to control the maximum width of elements.
Setting a max-width
prevents content from growing too wide, maintaining readability and visual balance—especially in centered layouts, modals, articles, and dashboards. Tailwind provides a flexible, scale-based system to apply max-width constraints with utility classes.
How to Set Tailwind Max Width
To set the Tailwind max-width of an element, you can use the max-w-{size}
class, where {size}
can be one of the following options:
-
max-w-{value}
: This sets the maximum width to a specific value in pixels. max-w-xs
, max-w-sm
, max-w-md
, max-w-lg
, max-w-xl
, max-w-2xl
, max-w-3xl
, max-w-4xl
, max-w-5xl
, max-w-6xl
: These are predefined max-width classes that provide commonly used maximum widths for different breakpoints.
-
max-w-full
: This sets the maximum width to 100% of the parent container. max-w-screen-sm
, max-w-screen-md
, max-w-screen-lg
, max-w-screen-xl
: These are predefined max-width classes that set the maximum width to the corresponding breakpoint size of the viewport.
Here's an example of how to use the Tailwind max-width utility classes:
<div class="max-w-lg">This div has a maximum width of large size.</div>
Preview
Percentage-based Max-Width
Tailwind CSS also provides utility classes for setting Tailwind max width as a percentage of the parent container's width. You can use the max-w-{percentage}
class to achieve this. Here's an example:
<div class="max-w-full">
This div has a maximum width of 100% of its parent container.
</div>
Preview
✏️ Arbitrary Value Usage
When you need precise control, use arbitrary values:
<div class="max-w-[600px]">Exactly 600px wide</div>
<div class="max-w-[75ch]">Text width for perfect reading line length</div>
Preview
Text width for perfect reading line length
Great for matching Figma specs or experimenting during layout work.
Responsive Tailwind Max Width
Tailwind CSS allows you to control the maximum width of elements responsively at different breakpoints. To use responsive Tailwind max width classes, you can append the breakpoint prefix to the max-width
classes. For example, md:max-w-48
sets the maximum width to 48 pixels starting from the medium breakpoint and above. Here's an example:
<div class="max-w-lg md:max-w-48">
This div has a maximum width of large size by default, and 48 pixels starting
from the medium breakpoint.
</div>
Preview
This div has a maximum width of large size by default, and 48 pixels
starting from the medium breakpoint.
In the above example, the max-w-lg
class is applied by default, setting the Tailwind max width to a large size. However, starting from the medium breakpoint and above, the md:max-w-48
class is applied, changing the Tailwind max width to 48 pixels.
⚙️ Customization in tailwind.config.js
You can add custom maxWidth values for design tokens, brand rules, or layout constraints.
module.exports = {
theme: {
extend: {
maxWidth: {
content: "42rem",
dialog: "28rem",
fluid: "90vw",
},
},
},
};
<div class="max-w-content mx-auto">Semantic and consistent width</div>
Preview
Semantic and consistent width
This helps enforce design consistency across components.
🧩 Real UI Component Examples
📰 Article Layout
<div class="rounded-t-xl overflow-hidden bg-purple-100 p-5">
<article class="prose max-w-prose mx-auto px-4 bg-white p-2 rounded-md">
<h1 class="m-5 text-center font-bold text-4xl ">Lorem Ipsum</h1>
<img class="rounded-md mb-6 " src="https://images.unsplash.com/photo-1722291992145-ecc95e5bb264?q=80&w=1031&auto=format&fit=crop&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D" />
<h2 class="m-3 font-bold ">What is Lorem Ipsum</h2>
<p class="tracking-wide m-4"> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</p>
<h2 class="m-3 font-bold">Where does it come from?</h2>
<p class="tracking-wide m-4">Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32</p>
</article>
</div>
Preview
Lorem Ipsum

What is Lorem Ipsum
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
Where does it come from?
Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32
📦 Centered Modal
<div class="fixed inset-0 bg-black/50 flex items-center justify-center">
<div class="bg-white max-w-md w-full p-6 rounded shadow-lg">
<h2 class="text-xl font-bold mb-4">Modal Title</h2>
<p>Modal content goes here.</p>
</div>
</div>
Preview
Modal Title
Modal content goes here.
🎯 Responsive Hero Content
<section class="text-center max-w-3xl mx-auto px-4 sm:px-6 lg:px-8">
<h1 class="text-4xl font-extrabold tracking-tight">
Tailwind makes layout easy
</h1>
<p class="mt-4 text-lg">
Constrain content width without writing a line of CSS.
</p>
</section>
Preview
Tailwind makes layout easy
Constrain content width without writing a line of CSS.
✅ Best Practices for Devs & Designers
-
Use max-w-*
to limit content width for readability — especially with text-heavy layouts.
-
Wrap blocks in mx-auto
to center constrained elements (cards, modals, forms).
-
Use semantic names (max-w-content, max-w-article) in tailwind.config.js to create a shared visual language.
-
Combine max-w-*
with w-full
to allow responsive scaling up to a limit.
-
Avoid hardcoding width with w-[600px] unless truly needed —max-w-*
is more flexible.
♿ Accessibility Notes
-
max-width improves readability by keeping line lengths short (ideal is ~50–75 characters).
-
Use max-w-prose
or max-w-[65ch]
in longform content for accessibility and comfort.
-
Avoid using max-w-*
as a substitute for semantic layout structure.
Tailwind Max Width class Table
Class | Properties |
---|
max-w-0 | max-width: 0rem; |
max-w-none | max-width: none; |
max-w-xs | max-width: 20rem; |
max-w-sm | max-width: 24rem; |
max-w-md | max-width: 28rem; |
max-w-lg | max-width: 32rem; |
max-w-xl | max-width: 36rem; |
max-w-2xl | max-width: 42rem; |
max-w-3xl | max-width: 48rem; |
max-w-4xl | max-width: 52rem; |
max-w-5xl | max-width: 64rem; |
max-w-6xl | max-width: 72rem; |
max-w-xs | max-width: 80rem; |
max-w-full | max-width: 100%; |
max-w-min | max-width: min-content; |
max-w-max | max-width: max-content; |
max-w-prose | max-width: 65ch; |
max-w-screen-sm | max-width: 640px; |
max-w-screen-md | max-width: 768px; |
max-w-screen-lg | max-width: 1024px; |
max-w-screen-xl | max-width: 1280px; |
max-w-screen-2xl | max-width: 1536px; |
✨ What's Next?
Now that you’ve mastered Tailwind Max Width, try experimenting with:
Windframe Tailwind blocks
Pricing