Max-Width

Utilities for setting the maximum width of an element

Class reference

ClassProperties
.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-fullmax-width: 100%;

Usage

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

Max-Width - 图1

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

Responsive

To control the min-width of an element at a specific breakpoint, add a {screen}: prefix to any existing min-width utility.

For more information about Tailwind’s responsive design features, check out the Responsive Design documentation.

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

Max-Width - 图2


Customizing

Max-Width Scale

Customize Tailwind’s default max-width scale in the theme.maxWidth section of your tailwind.config.js file.

  1. // tailwind.config.js
  2. module.exports = {
  3. theme: {
  4. maxWidth: {
  5. + '1/4': '25%',
  6. + '1/2': '50%',
  7. + '3/4': '75%',
  8. }
  9. }
  10. }

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

Responsive and pseudo-class variants

By default, only responsive variants are generated for max-width utilities.

You can control which variants are generated for the max-width utilities by modifying the maxWidth property in the variants section of your tailwind.config.js file.

For example, this config will also generate hover and focus variants:

  1. // tailwind.config.js
  2. module.exports = {
  3. variants: {
  4. // ...
  5. - maxWidth: ['responsive'],
  6. + maxWidth: ['responsive', 'hover', 'focus'],
  7. }
  8. }

Disabling

If you don’t plan to use the max-width utilities in your project, you can disable them entirely by setting the maxWidth property to false in the corePlugins section of your config file:

  1. // tailwind.config.js
  2. module.exports = {
  3. corePlugins: {
  4. // ...
  5. + maxWidth: false,
  6. }
  7. }