Sizing

Max-Width

Utilities for setting the maximum width of an element.

Quick reference

Class
Properties
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-fitmax-width: fit-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;

Show all classes

Basic usage

Setting the maximum width

Set the maximum width of an element using the max-w-{size} utilities.

Max-Width - 图1

  1. <div class="max-w-md ...">
  2. <!-- ... -->
  3. </div>

Reading width

The max-w-prose utility gives an element a max-width optimized for readability and adapts based on the font size.

Max-Width - 图2

  1. <div class="text-sm max-w-prose ...">
  2. <p>Oh yeah. It's the best part. It's crunchy, it's explosive, it's where the muffin breaks free of the pan and sort of does it's own thing. I'll tell you. That's a million dollor idea right there. Just sell the tops.</p>
  3. </div>
  4. <div class="text-base max-w-prose ...">
  5. <p>Oh yeah. It's the best part. It's crunchy, it's explosive, it's where the muffin breaks free of the pan and sort of does it's own thing. I'll tell you. That's a million dollor idea right there. Just sell the tops.</p>
  6. </div>
  7. <div class="text-xl max-w-prose ...">
  8. <p>Oh yeah. It's the best part. It's crunchy, it's explosive, it's where the muffin breaks free of the pan and sort of does it's own thing. I'll tell you. That's a million dollor idea right there. Just sell the tops.</p>
  9. </div>

Constraining to your breakpoints

The max-w-screen-{breakpoint} classes can be used to give an element a max-width matching a specific breakpoint. These values are automatically derived from the theme.screens section of your tailwind.config.js file.

  1. <div class="max-w-screen-2xl">
  2. <!-- ... -->
  3. </div>

Applying conditionally

Hover, focus, and other states

Tailwind lets you conditionally apply utility classes in different states using variant modifiers. For example, use hover:max-w-lg to only apply the max-w-lg utility on hover.

  1. <div class="max-w-sm hover:max-w-lg">
  2. <!-- ... -->
  3. </div>

For a complete list of all available state modifiers, check out the Hover, Focus, & Other States documentation.

Breakpoints and media queries

You can also use variant modifiers to target media queries like responsive breakpoints, dark mode, prefers-reduced-motion, and more. For example, use md:max-w-lg to apply the max-w-lg utility at only medium screen sizes and above.

  1. <div class="max-w-sm md:max-w-lg">
  2. <!-- ... -->
  3. </div>

To learn more, check out the documentation on Responsive Design, Dark Mode and other media query modifiers.


Using custom values

Customizing your theme

You can customize your max-width scale by editing theme.maxWidth or theme.extend.maxWidth in your tailwind.config.js file.

tailwind.config.js

  1. module.exports = { theme: { maxWidth: { '1/2': '50%', } }}

Learn more about customizing the default theme in the theme customization documentation.

Arbitrary values

If you need to use a one-off max-width value that doesn’t make sense to include in your theme, use square brackets to generate a property on the fly using any arbitrary value.

  1. <div class="max-w-[50%]">
  2. <!-- ... -->
  3. </div>

Learn more about arbitrary value support in the arbitrary values documentation.