Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any cons to using color names in place of color codes in CSS?

Tags:

css

colors

For example writing red is more efficient than #cc0000. It has less characters, takes up less space, and is easier to remember.

Are there any down sides to using color names over hex codes or RGB values? This includes programming in a multi-developer environment.

like image 296
Jitendra Vyas Avatar asked Jul 12 '10 17:07

Jitendra Vyas


People also ask

Can we use color name in CSS?

If you develop for browsers that support CSS3, which are all major browsers since IE9, you can use color names in CSS.

What is one limitation of named CSS colors that hexadecimal and RGB colors do not have?

What is one limitation of named CSS colors that hexadecimal and RGB colors do not have? Named CSS colors are limited to a specific set and cannot represent the full color palette.

Why are hex values more useful than just color names?

Because they use hexadecimal, and because 255 is the maximum value for a component, every possible color can be expressed using just 6 digits. This system also means that there are a huge range of colors available, because each component can take on any value from 0 to 255.

Which is the correct way to identify color in CSS?

The most common way to specify colors in CSS is to use their hexadecimal (or hex) values. Hex values are actually just a different way to represent RGB values. Instead of using three numbers between 0 and 255, you use six hexadecimal numbers. Hex numbers can be 0-9 and A-F.


1 Answers

Different browsers may not agree on what some color names mean. There are not names for all 16 million 24-bit colors. In fact there are only 17 W3C-standard color names. It's probably OK to use those.

Personally I use a templating system at build time to pre-process my CSS files, so that I can keep a standard set of site colors and refer to them by name. That way I get the best of both worlds: I know exactly what my RGB color values are, but I can use simpler names in the CSS.

(Of course, it's still not possible to know exactly how a color will look on a given user's browser.)

edit — in the 5 years since this answer was written, preprocessors like Less and Sass have become pretty common. Those provide some very sophisticated tools for managing colors (and many other things) in CSS sources.

like image 143
Pointy Avatar answered Oct 05 '22 11:10

Pointy