How to change text transparency in HTML/CSS?

Nosrettap picture Nosrettap · May 31, 2012 · Viewed 404.2k times · Source

I'm very new to HTML/CSS and I'm trying to display some text as like 50% transparent. So far I have the HTML to display the text with full opacity

<html><font color=\"black\" face=\"arial\" size=\"4\">THIS IS MY TEXT</font></html>

However, I'm not sure how to change its opacity. I've tried looking online, but I'm not sure exactly what to do with the code I find.

Answer

Mattias Buelens picture Mattias Buelens · May 31, 2012

opacity applies to the whole element, so if you have a background, border or other effects on that element, those will also become transparent. If you only want the text to be transparent, use rgba.

#foo {
    color: #000; /* Fallback for older browsers */
    color: rgba(0, 0, 0, 0.5);

    font-size: 16pt;
    font-family: Arial, sans-serif;
}

Also, steer far, far away from <font>. We have CSS for that now.