spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / programming / css_color / 1 current pageTo page 2To page 3
[next]

A (CSS) Horse of a Different Color - Part 1

Senior Lotus Notes Developer
AMS Staffing Solutions
US-MD-Baltimore

Justtechjobs.com Post A Job | Post A Resume
Developer News
Google Chrome Playing Catch-Up on Extensions
Open Solutions Alliance Gets New Leadership
Red Hat Spacewalk Expands Linux Management

Currently, the World Wide Web Consortium (W3C) is working on enhancements and improvements to CSS with the forthcoming CSS3 specification. Unlike the previous specs, the W3C is working on creating a new spec in a piecemeal fashion, focusing on individual “modules” dealing with a specific issue, like fonts, backgrounds, borders and so on. The idea is to not only make the process of change more public and visible (by posting changes and updates to their Web site), but also to give browser developers a chance to work on future developments prior to them being made official.

One of the CSS3 modules deals with color, and if it is fully adopted, it promises to introduce a number of changes in the ways you can set colors on a Web page.

HSL Color Values

A wholly new way of setting color that has been proposed is to use HSL color values. HSL is short for “Hue, Saturation and Lightness”, and it is arguably a more intuitive way of specifying color values than using either hexadecimal code or RGB decimal values. HSL describes color values in terms of its placement on a color circle, how “deep” a color is, and how light or dark it is. The first value of HSL is described by a color circle with values ranging from 0 to 360. Red colors lie about 0 degrees, greens at around 120 degrees and blues around 240 degrees. Both saturation and lightness are represented by percentage values: 100% saturation is the “full” value for a given color, whereas 0% represents the grayest value for that color. Then there is the “light” value: 100% lightness is bright, sometimes near-white, 50% is “normal” and 0% lightness is very dark, sometimes near-black depending on the color. The following code snippet shows how “full” red, green and blue values would be represented using HSL:

{color: hsl(0deg, 100%, 50%)} /* red - equivalent to #FF0000 */
{color: hsl(120deg, 100%, 50%)} /* green - equivalent to #00FF00 */
{color: hsl(240deg, 100%, 50%)} /* blue - equivalent to #0000FF */

Once you know where a color value lies on the color wheel, it is a relatively easy thing to tweak the value; making a color more green or blue, for example, de-saturating it, or making it darker or brighter as needed. So, for example, if you wanted to make a particular green lighter or darker, you just have to play with the final value until you get what you want, as you can see in the following code snippet:

{color: hsl(120deg, 100%, 50%)} /* ‘normal’ green */
{color: hsl(120deg, 100%, 25%)} /* a lighter green */
{color: hsl(120deg, 100%, 75%)} /* a darker green */
{color: hsl(120deg, 100%, 100%)} /* lime */

If you change the middle, saturation values, you get lighter or darker pastel-like colors, as you can see from the following code snippet:

{color: hsl(240deg, 3% ,100%)} /* ghost white */
{color: hsl(240deg, 8%, 98%)} /* lavender */
{color: hsl(240deg,78% ,44%)} /* midnight blue */

The prime advantage HSL has over hexadecimal and decimal RGB values is that they more intuitively show how close one color is related to another. For example, the hexadecimal color value for the color name “PowderBlue” is #B0E0E6. The only slightly lighter “LightBlue” color is #ADD8E6. Doing this type of conversion in your head using hexadecimal is almost impossible. Decimal values are slightly better at showing the small difference between these two colors, which are 176,224,230 and 173,216,230 respectively. But you are still trying to mix different values of red and green in order to tweak the type of blue you want. But the HSL values for them – 187deg, 23%, 90% and 195deg, 25%, 90% respectively – best show just how slight the difference is between them, and also provides a better hint as to how to make a given color more or less blue, and how to change its brightness. You are no longer dealing with red and green values, just playing around with different shades of blue, which makes things much easier.

A final word about this: keep in mind that the use of HSL in CSS color properties has not as yet been finalized. Things may end up being different in the final specification, so just consider this a “head’s up” as how you may be able to set HSL color values in the near future.


home / programming / css_color / 1 current pageTo page 2To page 3
[next]

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP · Working with the DOM Stylesheets Collection
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
MS Access and MySQL · Cisco AutoQoS: VoIP QoS for Mere Mortals · While VoIP Adoption Explodes in Enterprise, Carrier Spending Lags

Created: March 27, 2003
Revised: June 17, 2003

URL: http://webreference.com/programming/css_color/1