Matching color name to color code

some color names are not matched to color codes by one to one.

The color name “violet” as an example,
some say the code of it “#8F00FF”.
some say the code of it “#7F00FF”.
some say the code of it “#8601AF”.
some say the code of it “#EE82EE”.

What is the correct code of the color name “violet”?

The color code of RGG seems to be defferent from the HTML color code.
The color code of color wheel seems to be defferent from the RBG color code.

For web publishing what color code should I always use?

Probably a better approach is just pick a color you like in Photoshop and not worry about it. For me, Photoshop says that violet is


rgb(238, 130, 238)

I have some color classes in my css file for using them in my webpage.

.red {color:#ff0000}
.blue {color:#0000ff}
.black {color:#000000}
:      :

In this case I have to get the correct color code which matches to the color name.

It’s not a good idea to use classes with names like that. If you have elements all over the place with class=“red” and you decide to color them blue, that will look rather silly.

The color codes you listed there are the correct codes for those colors.

I won’t decide to color them blue.
I like to make users to use it when they are posting
I guess “<span class=“red”>red text</span>” is much better than"<span style=“color:#ff0000”>red text</span>" to users.

Yeah, but I didn’t say to do that. :slight_smile: What if you decide later that red is not a good color for users who are posting? So a better thing to do is use something like this:

<span [COLOR="#FF0000"]class="post"[/COLOR]>post text</span>

.post {color: red;}

That way, you can style posts (inside the .post span) any way you like, without your code looking odd if you have “red” classes styled with a different color.

It’s just a bad idea in general to name classes after an appearance of any kind. Make the class names rather focus on the role of the element.

The ‘color keywords’ are limited though and not consistent amongst browsers even the WCAG suggested against using them, i.e. use numbers, not names, for colours. If you want a rough guide though what numbers “violet” may loosely equate to:

[font=verdana]And remember that that is a new feature in CSS3, which is a long way from being ready for deployment. In CSS1 and CSS2, the only legal colour names are the the basic 16 colours (white, black, gray, silver, blue, navy, lime, green, red, maroon, fuscia, purple, aqua, teal, yellow, olive), and that for any other colours you must use #hex or (r,g,b) codes. Most browsers will play ball with named colours, because they try to do what they think authors want, but it isn’t guaranteed.

(HTML 4, on the other hand, does allow you to use all named colours, except that you wouldn’t stoop so low as to declare a colour in HTML now, would you!)[/font]

Obviously that is why I said numbers not names as that (see link) basically was based on X11, I think Fred5 will be intending on using those CSS matches. CSS 2.1 has 17: aqua, black, blue, fuchsia, gray, green, lime, maroon, navy, olive, [orange], purple, red, silver, teal, white, and yellow. Though of course really you should avoid using those ‘keywords’ also.

The use of HTML elements and attributes for specifying colour is deprecated anyway so that usage should have stopped well over 10-years ago since the only places you could use the ‘color’ attribute was BASEFONT and FONT. LOL. The only other places you could apply colour values (keywords) being obviously: bgcolor, text, link, alink and vlink - again all deprecated for good reason. In otherwords use numbers not names.