opacity

Các tiện ích để kiểm soát độ mờ của một phần tử.

ClassStyles
opacity-<number>
opacity: <number>%;
opacity-(<custom-property>)
opacity: var(<custom-property>);
opacity-[<value>]
opacity: <value>;

Ví dụ

Ví dụ cơ bản

Sử dụng các tiện ích opacity-<number> như opacity-25opacity-100 để đặt độ mờ của một phần tử:

opacity-100

opacity-75

opacity-50

opacity-25

<button class="bg-indigo-500 opacity-100 ..."></button><button class="bg-indigo-500 opacity-75 ..."></button><button class="bg-indigo-500 opacity-50 ..."></button><button class="bg-indigo-500 opacity-25 ..."></button>

Áp dụng có điều kiện

Prefix an opacity utility with a variant like disabled:* to only apply the utility in that state:

<input class="opacity-100 disabled:opacity-75 ..." type="text" />

Learn more about using variants in the variants documentation.

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

Use the opacity-[<value>] syntax to set the opacity based on a completely custom value:

<button class="opacity-[.67] ...">  <!-- ... --></button>

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

<button class="opacity-(--my-opacity) ...">  <!-- ... --></button>

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

Responsive design

Prefix an opacity utility with a breakpoint variant like md: to only apply the utility at medium screen sizes and above:

<button class="opacity-50 md:opacity-100 ...">  <!-- ... --></button>

Learn more about using variants in the variants documentation.

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