views:

333

answers:

4

Doing CSS throughout the last couple years, I eventually learned that the standard way to represent a gray color shade (or any color which repeated its first three characters) was to use only three characters instead of six, I assume for terseness:

  • #555 instead of #555555
  • #eee instead of #eeeeee

In XAML, however, I often see the opposite:

  • #555555 instead of #555
  • #eeeeee instead of #eee

Are there any situations in XAML when one will work and not the other, or one consumes more memory, etc., or is this just a long/short notation issue and has no practical ramifications?

+2  A: 

In either CSS or XAML both forms (plus more) are valid..

Matthew Flaschen
+1  A: 

Technically speaking I would say that the full six characters is more correct in any case as the abbreviated version is just expanded to a six. Two bytes per RGB.

I also prefer the 6 digit as I am then able to keep things consistent looking.

Brian
From the W3 CSS link above: "The three-digit RGB notation (#rgb) is converted into six-digit form (#rrggbb) by replicating digits, not by adding zeros. For example, #fb0 expands to #ffbb00." Even though it's 8 bit vs 16bit, they're still the same color, and it's quite unusual to see 8bit desktop screens nowdays.
Hugo
To correct myself, /in XAML/, the 3-char version is 8-bit, while the 6-char is 16-bit. Hugo's right that with CSS it's just replicating digits. Either way, of course that doesn't mean it's really going on an 8-bit screen.
Matthew Flaschen
Plus some tools (e.g. color pickers) generate only the #rrggbb. Keeping it all in #rrggbb makes interoperability a mite easier.
Anirvan
A: 

edit whoops, completely skipped over the XAML bit. The stuff below still relates to CSS though. Sorry mate


According to the W3C, they've been the same since CSS1. I've not met a browser yet that'll display #abc any different to #aabbcc.

gray color shade (or any color which repeated its first three characters)

I may be misreading your question, but you can do more than just gray. The hext notations are #rgb, or #rrggbb. So, #123 = #112233, not #123123 :-)

Dan F
+3  A: 

Neither notation is truly more correct than the other. It's largely just a matter of preference.

The 3-digit format, or #rgb, is simply a short-hand format that expands to #rrggbb, giving you an option to leave out a few repeated characters.

#555 => #555555
#abc => #aabbcc

The exception is in specifics -- e.g., #e5a9bc can not be accurately described in or abbreviated to only 3 digits.


I would guess the common preference for not using 3-digit notation in XAML is be based in the fact that not all markup languages support them -- HTML.

Jonathan Lonowski