max-width

Các utility để thiết lập chiều rộng tối đa của một phần tử.

ClassStyles
max-w-<number>
max-width: calc(var(--spacing) * <number>);
max-w-<fraction>
max-width: calc(<fraction> * 100%);
max-w-3xs
max-width: var(--container-3xs); /* 16rem (256px) */
max-w-2xs
max-width: var(--container-2xs); /* 18rem (288px) */
max-w-xs
max-width: var(--container-xs); /* 20rem (320px) */
max-w-sm
max-width: var(--container-sm); /* 24rem (384px) */
max-w-md
max-width: var(--container-md); /* 28rem (448px) */
max-w-lg
max-width: var(--container-lg); /* 32rem (512px) */
max-w-xl
max-width: var(--container-xl); /* 36rem (576px) */
max-w-2xl
max-width: var(--container-2xl); /* 42rem (672px) */

Ví dụ

Ví dụ cơ bản

Sử dụng các utility max-w-<number> như max-w-24max-w-64 để thiết lập chiều rộng tối đa cố định cho một phần tử dựa trên thang khoảng cách:

Resize the example to see the expected behavior

max-w-96
max-w-80
max-w-64
max-w-48
max-w-40
max-w-32
max-w-24
<div class="w-full max-w-96 ...">max-w-96</div><div class="w-full max-w-80 ...">max-w-80</div><div class="w-full max-w-64 ...">max-w-64</div><div class="w-full max-w-48 ...">max-w-48</div><div class="w-full max-w-40 ...">max-w-40</div><div class="w-full max-w-32 ...">max-w-32</div><div class="w-full max-w-24 ...">max-w-24</div>

Sử dụng phần trăm

Sử dụng max-w-full hoặc các utility max-w-<fraction> như max-w-1/2max-w-2/5 để thiết lập chiều rộng tối đa dựa trên phần trăm cho một phần tử:

Resize the example to see the expected behavior

max-w-9/10
max-w-3/4
max-w-1/2
max-w-1/3
<div class="w-full max-w-9/10 ...">max-w-9/10</div><div class="w-full max-w-3/4 ...">max-w-3/4</div><div class="w-full max-w-1/2 ...">max-w-1/2</div><div class="w-full max-w-1/3 ...">max-w-1/3</div>

Sử dụng thang container

Sử dụng các utility như max-w-smmax-w-xl để thiết lập chiều rộng tối đa cố định cho một phần tử dựa trên thang container:

Resize the example to see the expected behavior

Andrew Alfred
Assistant to the Traveling Secretary
<div class="max-w-md ...">  <!-- ... --></div>

Sử dụng breakpoints container

Sử dụng utility container để thiết lập chiều rộng tối đa của một phần tử khớp với min-width của breakpoint hiện tại. Điều này hữu ích nếu bạn muốn thiết kế cho một tập hợp kích thước màn hình cố định thay vì cố gắng điều chỉnh viewport hoàn toàn linh hoạt:

<div class="container">  <!-- ... --></div>

Lưu ý rằng không giống như container bạn có thể đã sử dụng trong các framework khác, container của Tailwind không tự động căn giữa và không có padding ngang tích hợp sẵn. Sử dụng mx-auto và các utility px-<number> để thêm những thứ này:

<div class="container mx-auto px-4">  <!-- ... --></div>

Sử dụng giá trị tùy chỉnh

Use the max-w-[<value>] syntax to set the maximum width based on a completely custom value:

<div class="max-w-[220px] ...">  <!-- ... --></div>

For CSS variables, you can also use the max-w-(<custom-property>) syntax:

<div class="max-w-(--my-max-width) ...">  <!-- ... --></div>

This is just a shorthand for max-w-[var(<custom-property>)] that adds the var() function for you automatically.

Thiết kế phản hồi

Prefix a max-width utility with a breakpoint variant like md: to only apply the utility at medium screen sizes and above:

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

Learn more about using variants in the variants documentation.

Tùy chỉnh theme của bạn

The max-w-<number> utilities are driven by the --spacing theme variable, which can be customized in your own theme:

@theme {  --spacing: 1px; }

Learn more about customizing the spacing scale in the theme variable documentation.

Copyright © 2025 Tailwind Labs Inc.·Chính sách thương hiệu