Is it possible to define a color in CSS by its name plus an alpha transparency value?
I.e.:
#mytext { color: red 0.5 }
rather than reso
No. As of 2020, the CSS Colors specification only allows colors to be specified as:
#rrggbb
)#rgb
)rgb( r, g, b )
notation (using percentages or 0-255 numbers)#rrggbbaa
)rgba( r, g, b, a )
notation (Note that CSS4 requires rgb
to accept 4 arguments but not all browsers support this), note that a
is in the range 0-1.0
instead of 0-255
.hsl( h, s, l )
hsla( h, s, l, a )
Each of these are mutually-exclusive.
Color-names are less useful now than they were in the days of CSS1.x because the named colors (with the exception of orange
) are all members of the old "16-color" display palette and generally look ugly today.
If you want to use color names to improve readability then use comments, like so:
color: rgb(0,0,0,0.5); /* semi-transparent black */
(put the comment after the semi-colon because many CSS editors only preserve comments when they're located outside of property declarations).
CSS3 adds more named-colors, including the 24-bit X11 color set, as well as the hsl(h,s,l)
function, but still does not allow the mixing of named-colors and opacity values: http://www.w3.org/TR/css3-color/