Blog Journeys of a Lifelong Learner
Subscribe
Color Keywords or Hexadecimal Codes? January 26, 2010
Colors used in HTML and CSS can be identified through color keywords and hexadecimal values. I was recently asked which approach is better, and here is my response.
First, style information should not be embedded in (X)HTML markup, as it is intended to describe information, not formatting. CSS stylesheets should be used to control the appearance of page elements.
Second, color keywords and hexadecimal codes are not identical. A color code is a reference to a color description, and a hexadecimal (such as #000000, #FF0000, or #CDCDCD)is a direct reference to a color. The use of a color keyword (such as black, blue, green, or white)Â requires the browser to interpret the color code and render a suitable color based on the browser-identified replacement for the color code. A hexadecimal code specification identifies precisely the desired color and is simply invoked by the browser; no secondary interpretation is required for rendering a hexadecimal code.
Browser interpretations for particular color keywords can vary; hexadecimal codes are universal.
Use hexadecimal codes.