tags:

views:

46

answers:

2

In how many ways we can give color info in X/HTML, css?

I know some

  1. Hex
  2. color name
  3. rgba

is there any other method?

and which method is preferred to use and which not? Please give explanation.

+3  A: 

The three ways you mention are the only three.

I don't think a specific method is generally preferred, but as a developer, I like to see hex numbers.

I would avoid color names simply because if you want to know the true value of a color you have to look it up which is an annoyance in my workflow.

Also, hex numbers are the most compact way to describe a color (for most colors), so you might be saying a couple bytes of bandwidth by using hex. This doesn't really matter, but it's one of the only differences I can think of.

Ben S
+1  A: 

There is one more method: the one you're missing is old RGB. RGBa includes opacity (that's the 'a', for alpha)--it's not the same as RGB. RGB is supported by a wide array of browsers, old and new; RGBa is supported by a narrower but significant set of browsers: http://css-tricks.com/rgba-browser-support/ (IE being the main holdout, as usual).

Which method you use really doesn't matter. I prefer hex from habit, but am starting to use RGB more so that I can start getting used to extending it to RGBa.

D_N
is rgba a new addition? http://www.imventurer.com/2007/09/24/css-color-codes/
metal-gear-solid
Yep. Part of CSS3 (next big thing and all that). Good article: http://24ways.org/2009/working-with-rgba-colour Specification: http://www.w3.org/TR/css3-color/#rgba-color
D_N
so should we use RFBa over hex?
metal-gear-solid
No, only use RGBa when you need a partially transparent color. You *might* want to start using RGB so you are familiar with it, but you can't rely on RGBa in older browsers, so always define a fallback color--in RGB or hex (your choice).
D_N