19
In this MDN documentation I find a huge list of color names which can be used in the CSS with their respective hexadecimal values. For example:
--------------------------------------
| nome em En | nome em Pt | hexa |
--------------------------------------
| black | preto | #000000 |
--------------------------------------
| silver | prata | #c0c0c0 |
--------------------------------------
| white | branco | #ffffff |
--------------------------------------
| red | vermelho | #ff0000 |
--------------------------------------
To apply a red background (red
) to a div
I could use:
usando o nome da cor: usando valor hexadecimal:
div{ div{
background-color: red; OU background-color: #ff0000;
} }
Or using RGB:
div{
background-color: rgb(255, 0, 0);
}
Personally I find it much more convenient to use red
than #ff0000
, and apparently I’ve never encountered problems using the names, but I’m not 100% sure if that’s good practice or there’s some problem between browsers.
My question is whether I can use only names of colors instead of the hexadecimal or RGB value, and whether this implies some kind of incompatibility between browsers. Which would be the most recommended use and why?
Until a long time ago it was not recommended to use the color name, as its components could vary from browser to browser, and the display of the application may vary; today I believe this is no longer a problem.
– Woss
Expensive according to W3C there is no problem in calling colors by names... Even there is a table comparing Xhexa and there is no difference. Even color names are also valid for SVG
– hugocsl
There is no incompatibility between using color names, hexadecimal and RGB. But, if you want to get a color with precision of a specific tone you want, you can use hexadecimal or rgb, but other than that, there is no problem.
– Bob Slavtrievich
Does it depend on who is maintaining the CSS? I think if I was going to write an answer, I would go that way. I will research the subject, of all sorts
– Jefferson Quesado