Модификаторы прозрачности и цвета
Используйте синтаксис модификатора прозрачности со слешем, например bg-blue-500/50, чтобы управлять прозрачностью фона и текста.
«Модификаторы прозрачности и цвета» — бесплатный урок Tailwind CSS Academy на CoddyKit. Это урок 3 из 4. Ты можешь прочитать весь урок бесплатно ниже — а потом практиковать его прямо в браузере с встроенным редактором кода и ИИ-репетитором 24/7. Это часть пути обучения Tailwind CSS Academy, и твой прогресс синхронизируется между веб-версией и приложением CoddyKit. Курс Tailwind CSS Academy содержит 4 уроков всего.
Части этого урока еще не переведены и отображаются на английском.
The opacity Property in CSS
CSS opacity controls the overall transparency of an element, from 0 (invisible) to 1 (fully opaque). The critical thing to understand is that opacity is inherited by children: setting opacity: 0.5 on a card also makes its text, images, and buttons 50% transparent. This is often not what you want — you usually only need the background to be transparent, not the content.
<!-- opacity affects EVERYTHING including children -->
<div class="opacity-50 bg-blue-600 p-6">
<p class="text-white">This text is also 50% transparent (probably not intended)</p>
</div>Tailwind's opacity-* Utilities
Tailwind maps opacity-* utilities to CSS opacity values. Available steps include opacity-0, opacity-5, opacity-10, opacity-25, opacity-50, opacity-75, opacity-90, opacity-95, and opacity-100. These are useful for disabled states, hover fades, and overlay elements where you intentionally want the whole element to be semi-transparent.
<!-- Disabled button with reduced opacity -->
<button class="bg-indigo-600 text-white px-6 py-2 rounded opacity-50 cursor-not-allowed">
Disabled
</button>
<!-- Loading overlay -->
<div class="fixed inset-0 bg-white opacity-75"></div>The Color Modifier (Slash Syntax)
Tailwind v3 introduced the slash opacity modifier, which applies opacity directly to a color value without affecting children. Write bg-blue-600/50 to set the background to blue-600 at 50% opacity — only the background is transparent, text and children remain fully opaque. This is the preferred way to create translucent colored surfaces.
<!-- Slash modifier: only the background is transparent -->
<div class="bg-blue-600/20 p-6 rounded-xl">
<p class="text-blue-900 font-medium">This text stays fully opaque at 100% opacity</p>
</div>
<!-- Compared to element-level opacity: -->
<div class="bg-blue-600 opacity-20 p-6 rounded-xl">
<p class="text-white">Text is also transparent here — probably wrong!</p>
</div>Available Opacity Steps
The slash modifier accepts any value from 0 to 100 in steps of 5: /0, /5, /10, /20, /25, /30, /40, /50, /60, /70, /75, /80, /90, /95, /100. You can also use arbitrary values like /[33] for exactly 33% opacity. The modifier works on any color utility: bg-*, text-*, border-*, ring-*, and shadow-*.
<div class="bg-indigo-500/10 p-2 mb-1">10% background</div>
<div class="bg-indigo-500/25 p-2 mb-1">25% background</div>
<div class="bg-indigo-500/50 p-2 mb-1">50% background</div>
<div class="bg-indigo-500/75 p-2 mb-1">75% background</div>
<div class="bg-indigo-500 p-2">100% background (default)</div>Text Opacity With Modifier
The slash modifier on text-* utilities creates semi-transparent text without a separate opacity class. text-gray-900/50 renders the near-black color at 50% opacity, creating a muted effect. This is commonly used for placeholder text, secondary labels, and disabled text that needs to appear faded rather than a different color.
<p class="text-gray-900">Full opacity text</p>
<p class="text-gray-900/75">75% opacity text</p>
<p class="text-gray-900/50">50% opacity text (secondary)</p>
<p class="text-gray-900/25">25% opacity text (subtle hint)</p>Border Opacity With Modifier
Apply the slash modifier to border colors for translucent borders: border-gray-900/10 creates a very subtle border that works on both light and dark backgrounds. This technique is popular for dividers and card borders where a fully opaque border would be too harsh. Combine with dark: variants for automatic theme adaptation.
<div class="border border-gray-900/10 dark:border-white/10 rounded-xl p-6">
Card with a transparent border
</div>
<hr class="border-t border-gray-900/10 my-8" />Backdrop Blur and Frosted Glass
Combine bg-white/80 with backdrop-blur-md to create a frosted glass effect — a translucent element with a blurred view of what is behind it. This modern UI pattern is used in sticky navigation bars, floating panels, and notification drawers. The backdrop-blur-* utilities use the CSS backdrop-filter property.
<nav class="sticky top-0 z-50 bg-white/80 backdrop-blur-md border-b border-gray-200/50 px-8 py-4">
<span class="text-xl font-bold">MyApp</span>
</nav>Overlay Backdrop Pattern
Modal dialogs and drawers typically need a semi-transparent backdrop behind them. The bg-gray-900/50 class creates the standard dark overlay. Using the slash modifier instead of opacity-50 means the backdrop's own background is semi-transparent while still intercepting clicks and preventing interaction with the content behind it.
<!-- Modal backdrop -->
<div class="fixed inset-0 bg-gray-900/50 z-40">
<!-- Clicking this closes the modal -->
</div>
<!-- Modal content appears above backdrop -->
<div class="fixed inset-0 flex items-center justify-center z-50">
<div class="bg-white rounded-2xl p-8 shadow-2xl w-full max-w-md">
Modal Content
</div>
</div>Hover Opacity Effects
Use hover:opacity-* to fade elements on hover. Applying opacity-100 hover:opacity-75 slightly dims an element when hovered, giving tactile feedback without a color change. This is subtle and elegant for image overlays, card hover states, and gallery items where you want a visual response without an aggressive color shift.
<!-- Image gallery item with hover fade -->
<div class="group relative overflow-hidden rounded-xl">
<img src="photo.jpg"
class="w-full h-48 object-cover opacity-100 group-hover:opacity-75 transition-opacity duration-300"
alt="" />
<div class="absolute inset-0 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity">
<span class="text-white font-bold">View Photo</span>
</div>
</div>Ring Opacity Modifier
The slash modifier also works on ring-* focus indicators. ring-indigo-500/50 creates a semi-transparent focus ring that is visible but not jarring. This is especially useful in dark mode where a fully opaque ring can look harsh. Combine with focus-visible: to show the ring only when needed for keyboard navigation.
<input
type="text"
class="border border-gray-300 rounded-lg px-4 py-2
focus:outline-none focus-visible:ring-2 focus-visible:ring-indigo-500/50
focus-visible:border-indigo-500"
placeholder="Email address"
/>Arbitrary Opacity Values
When the predefined opacity steps (5, 10, 25, 50, 75, 100) do not meet your needs, use arbitrary values with bracket notation: bg-blue-600/[33] applies exactly 33% opacity. Arbitrary values give you pixel-perfect control for design specifications that require unusual transparency values, though sticking to the predefined steps usually produces a more consistent design.
<!-- Arbitrary opacity value -->
<div class="bg-indigo-600/[15] p-4 rounded-lg">
Very subtle 15% indigo tint
</div>
<!-- Also works for element-level opacity -->
<div class="opacity-[33] text-gray-900">
33% transparent element
</div>Quick Check
Test your understanding of Tailwind CSS Mastery concepts from this lesson.
Lesson Recap
In this lesson you learned: opacity-* utilities affect the entire element and its children, the slash modifier (bg-color/opacity) makes only the color property transparent while children remain opaque, and backdrop-blur-md with bg-white/80 creates a frosted glass effect. Next up we control background image sizing, position, and repeat patterns.
Часто задаваемые вопросы
Урок «Модификаторы прозрачности и цвета» бесплатный?
Да — полный текст урока «Модификаторы прозрачности и цвета» бесплатно доступен здесь в веб-версии. Чтобы практиковать его интерактивно (встроенный редактор кода и ИИ-репетитор 24/7) и разблокировать остальной курс Tailwind CSS Academy, подпишись на CoddyKit PRO. Курс Tailwind CSS Academy содержит 4 уроков всего.
Чему я научусь в уроке «Модификаторы прозрачности и цвета»?
Используйте синтаксис модификатора прозрачности со слешем, например bg-blue-500/50, чтобы управлять прозрачностью фона и текста. Ты практикуешь Tailwind CSS Academy с помощью реального кода, который запускаешь прямо в браузере, и ИИ-репетитор 24/7 отвечает на твои вопросы во время урока.
Нужен ли мне опыт, чтобы начать Tailwind CSS Academy?
Предыдущий опыт не требуется. Tailwind CSS Academy на CoddyKit структурирован для всех уровней — от новичков до продвинутых, поэтому ты можешь начать отсюда или с самого начала и учиться в своем темпе. Это урок 3 из 4.
Сколько времени занимает урок «Модификаторы прозрачности и цвета»?
Большинство уроков CoddyKit занимают около 5–10 минут. Каждый из них компактный и интерактивный, поэтому ты постоянно делаешь прогресс и продолжаешь с того же места в веб-версии и приложении.
Можно ли писать и запускать код в этом уроке Tailwind CSS Academy?
Да. Каждый урок Tailwind CSS Academy включает встроенный редактор кода, поэтому ты пишешь и запускаешь реальный код прямо в браузере и получаешь моментальную обратную связь от AI — локальная установка не требуется.
Все уроки этого курса
- Палитра цветов Tailwind
- Градиенты фона
- Модификаторы прозрачности и цвета
- Размер, положение и повтор фонового изображения