Home

How to Use HSL Color for Your HTML5 and CSS3 Based Web Pages

|
Updated:  
2016-03-26 13:17:24
|
HTML5 and CSS3 All-in-One For Dummies
Explore Book
Buy On Amazon

You can assign an HSL value wherever you use colors on your HTML5 and CSS3 web page. The code for HSLcolors shows how the HSL scheme can be used on your page:

<!DOCTYPE html>
<html lang = "en-US">
 <head>
 <meta charset = "UTF-8">
 <title>HSLcolors.html</title>
 <style type = "text/css">
  body {
  background-color: HSL(180, 75%, 75%);
  }
  h1 {
  color: HSL(180, 75%, 25%);
  background-color: HSL(180, 75%, 90%);
  }
  p {
  color: HSL(0, 75%, 25%);
  }
 </style>
 </head>
 <body>
 <h1>This is a headline</h1>
 <p>
  This is a paragraph
 </p>
 </body>
</html>

To specify a color using the HSL scheme, do this:

  1. Set up your selectors as usual.

    In the CSS, set up a selector for each element you wish to color.

  2. Add the color rule.

    Apply one or both to each selector.

  3. Use the HSL function.

    Using HSL followed by parentheses indicates you wish to calculate the color using the HSL technique.

  4. Indicate the hue.

    Imagine a color wheel with red at the top. The hue is the angle (in degrees) of the color you want to pick. Hue should have a value between 0 and 360.

  5. Determine the saturation.

    Saturation is measured as a percentage. Saturation of 0% indicates a grayscale (somewhere between black and white) whereas Saturation of 100% is a fully saturated color with no grayscale. You need to include the percent sign as part of the saturation value.

  6. Specify the lightness.

    Lightness is also indicated as a percentage, with 0% being completely black and 100% being completely white. A lightness value of 50% will determine a balanced color between white and black. Lightness values should also include the percent sign.

The HSL model is a relatively recent addition to CSS, so it may not work with older browsers, but it can be extremely helpful. HSL makes it easier to predict whether colors will look good together. If you keep any two of the HSL values the same and change the third, the two colors are likely to fit together well.

About This Article

This article is from the book: 

About the book author:

Andy Harris earned a degree in Special Education from Indiana University/Purdue University–Indianapolis (IUPUI). He taught young adults with severe disabilities for several years. He also taught himself enough computer programming to support his teaching habit with freelance programming.
Those were the exciting days when computers started to have hard drives, and some computers connected to each other with arcane protocols. He taught programming in those days because it was fun.
Eventually, Andy decided to teach computer science full time, and he still teaches at IUPUI. He lectures in the applied computing program and runs the streaming media lab. He also teaches classes in whatever programming language is in demand at the time. He has developed a large number of online video-based courses and international distance education projects.
Andy has written several books on various computing topics and languages including Java, C#, mobile computing, JavaScript, and PHP/MySQL.
Andy welcomes comments and suggestions about his books. He can be reached at [email protected].