Information about cookies on this page

Our website uses cookies to ensure the functionality of the website, to collect and analyze information about the performance and usage of the website. Privacy Policy

  • Courses
    • Discord
    • Twitter
    • Linkedin
    • Facebook
    • Instagram
  • Pricing
  • English
  • Čeština
  • Deutsch
  • Русский
Sign inStart free
  • Courses
  • Pricing

Community

Sign in
  
  • Courses
    • Discord
    • Twitter
    • Linkedin
    • Facebook
    • Instagram
  • Pricing
  • English
  • Čeština
  • Deutsch
  • Русский
Sign inStart free
  • Courses
  • Pricing

Community

Sign in

Transparent Colors

In the CSS course, you made colors transparent with an alpha, for example rgba(71, 105, 88, 0.2) or rgb(255 0 0 / 50%). In Tailwind, you write a slash and a number after the color: its opacity in percent, from 0 (fully transparent) to 100 (opaque). Tailwind calls it the opacity modifier:

ClassCSS
bg-orange-500/20background-color: oklch(70.5% 0.213 47.604 / 20%)
bg-black/50background-color: rgb(0 0 0 / 50%)
text-stone-800/70color: oklch(26.8% 0.007 34.298 / 70%)

(Tailwind's exact CSS gets there in a different way, but the color is the same.) Multiples of 5 or 10 are the most common, but any number from 0 to 100 works. And there's one more color, transparent: bg-transparent makes a background fully transparent.

A transparent color lets whatever is behind it show through. That's handy when the color behind it isn't always the same. For example, a bg-black/50 background laid over a photo darkens it, so that white text on top is easy to read. And a light transparent tint fits on any background:

a highlighted word a highlighted word a highlighted word

We'll use it like a highlighter pen: the words "ready for a new home" in the adoption paragraph are in a strong element, and they'll get a light orange background through which the page shows.

The slash makes only that one color transparent. To fade a whole element with everything in it, CSS has the opacity property, which you know from the CSS course; you'll meet its classes in the lesson on borders, shadows and images.

Instructions

  1. 1

    Add the class bg-orange-500/20 to the strong element in the paragraph about adoption.

Back

5/12

  1. 1. The Color Palette
  2. 2. Shades
  3. 3. Quiz: Shades
  4. 4. Page Colors
  5. 5. Transparent Colors
  6. 6. Font Size
  7. 7. Font Weight
  8. 8. Quiz: Font Weight
  9. 9. Line Height and Alignment
  10. 10. Letter Spacing and Case
  11. 11. Font Family and Underline
  12. 12. Summary
Next

Try it yourself

Do this exercise right here in your browser. No account needed.