- Instant help with your CSS coding problems

Create semi transparent background in TailwindCSS

Question:
How to create semi transparent background in TailwindCSS?
Answer:
<div class="bg-slate-400/70">Lorem ipsum</div>

Description:

TailwindCSS version 3 introduces a new method for specifying transparency. 

The old version was bg-opacity-{value} for the background color. This can still be used, but the recommended syntax is bg-color/{value} . The new syntax works for all color utility classes.

Example:

In case of the following code

<div class="bg-slate-400">Lorem ipsum</div>

the CSS looks like this:

.bg-slate-400 {
    --tw-bg-opacity: 1;
    background-color: rgb(148 163 184 / var(--tw-bg-opacity));
}

If we add transparency to the background color:

<div class="bg-slate-400/70">Lorem ipsum</div>

then the CSS will be:

.bg-slate-400\/70 {
    background-color: rgb(148 163 184 / 0.7);
}
Share "How to create semi transparent background in TailwindCSS?"
Interesting things
OpanAi's ChatGPT