Questions tagged [hsl]

HSV is cylindrical color model that determines colors by hue (0°-360°), saturation (color intensity) and lightness (from black over the color to white).

The HSL model describes colors in terms of hue, saturation, and lightness (also called luminance). (Note: the definition of saturation in HSL is substantially different from HSV) The model has two prominent properties:

  • The transition from black to a hue to white is symmetric and is controlled solely by increasing lightness

    • Shading and tinting are controlled by a single value, lightness
  • Decreasing saturation transitions to a shade of gray dependent on the lightness, thus keeping the overall intensity relatively constant

    • Tones are controlled by a single value, saturation

The properties mentioned above have led to the wide use of HSL, in particular, in the CSS3 color model. As in HSV, hue corresponds directly to the concept of hue in the Color Basics section. The advantages of using hue are

  • The relationship between tones around the color circle is easily identified
  • Shades, tints, and tones can be generated easily without affecting the hue

http://xahlee.info/js/i/HSL_color_model.png

Lightness combines the concepts of shading and tinting from the Color Basics section. Assuming full saturation, lightness is neutral at the midpoint value, for example 50%, and the hue displays unaltered. As lightness decreases below the midpoint, it has the effect of shading. Zero lightness produces black. As lightness increases above 50%, it has the effect of tinting, and full lightness produces white.

At zero saturation, lightness controls the resulting shade of gray. A value of zero still produces black, and full lightness still produces white. The midpoint value results in the "middle" shade of gray, with an RGB value of (128,128,128).

As saturation decreases, it produces tones of the reference hue that converge on a shade of gray that is determined by the lightness. This keeps the total intensity relatively constant.


Note that the physical nature of additive color prevents the scheme from working exactly except for hues halfway between the primary and secondary hues. However, the total intensity of the tones resulting from decreasing saturation are much closer than tinting alone, as in HSV.

265 questions
10
votes
3 answers

RGB to HSL and back, calculation problems

I'm trying to convert RGB to HSL and I also want to convert from HSL to RGB, I have written a class for it but if I do RGB->HSL->RGB to try if it works I get a different value. Example case: if you create a HSLColor object by doing HSLColor…
Mervin
  • 1,103
  • 4
  • 18
  • 26
10
votes
1 answer

Does the .Net Color struct use an HSB or HSL colour space?

As I understand it HSL and HSB colour spaces are very similar, both use the same 0-360 colour wheel for hue and the same 0-1 value for saturation. The one difference between them is that in the HSB model you have brightness, where 0 is black and 1…
Keith
  • 150,284
  • 78
  • 298
  • 434
8
votes
4 answers

RGB value to HSL converter

Google maps api v3 allows "styles" to be applied to the map, including setting the color of various features. However, the color format it uses is HSL (or what seems like it): hue (an RGB hex string) lightness (a floating point value between -100…
aeq
  • 10,377
  • 15
  • 45
  • 46
8
votes
2 answers

Averaging circular values (particularly Hues in HSL color scheme)

So I was trying to puzzle out how to calculate the average hue of a number of objects whose colors are represented by HSL values. Thankfully, I stumbled across this Stack Overflow post, and set to work implementing the algorithm provided in the top…
GarrickW
  • 2,181
  • 5
  • 31
  • 38
7
votes
3 answers

In CSS, can HSL values be floats?

The CSS3 spec only specifies that: The format of an HSLA color value in the functional notation is ‘hsla(’ followed by the hue in degrees, saturation and lightness as a percentage, and an , followed by ‘)’. So am I to understand that these values…
Michael Heilemann
  • 2,627
  • 4
  • 23
  • 28
7
votes
5 answers

How to set same (constant) hue value for every pixel's of an image by using ColorMatrix?

I am trying to set a constant hue value for entire image with using ColorMatrix. My goal is to make entire image look with same color without loosing brightness of any area. I found a way to shift the hue values of an image by using ColorMatrix but…
Tony
  • 1,603
  • 3
  • 21
  • 40
7
votes
2 answers

0 as saturation and lightness doesn't work but 0% does in hsl/hsla?

I was trying a simple demo where I gave colors to elements in hsl. From all my experience I know that 0(ZERO) in CSS is unitless. If you want to specify 0 as a value, you may leave the unit. This however doesn't seem to be the case with hsl/hsla. On…
Praveen Puglia
  • 5,577
  • 5
  • 34
  • 68
7
votes
2 answers

C# setHue (or alternatively, convert HSL to RGB and set RGB)

C# has a very convenient getHue method, but I can't find a setHue method. Is there one? If not, I think the best way to define a color after changing the hue would be to convert the HSL value to RGB, and then set the RGB value. I know there are…
AARRGGHHH
  • 127
  • 4
  • 9
6
votes
2 answers

Converting image array to RGB to HSL/HSV and back?

I read in colored jpg images using readJPEG() from the jpeg package. Now I have my images as three-dimensional arrays (width, height, channels) in R. I want to convert these image arrays into the HSL or HSV color space, mutate the images and save…
Zoe
  • 906
  • 4
  • 15
6
votes
4 answers

Converting from RGB to HSL with Objective C

I'm quite new to objective c but have been programming for a while. I started creating a function that would convert from RGB to HSL and back again but I get a feeling it is way too long and headed in the wrong direction. Does anyone know of a…
treeba
  • 469
  • 5
  • 10
6
votes
2 answers

Calculate the apparent difference in color between two HSI color values

I have two color values in HSI (Hue Saturation and Intensity) and I want a number which represents the visual difference between the two colors. Hue is a number between 0 and 360 inclusive. Saturation is 0 to 1 and Intensity is 0 to 1. Lets consider…
Phil
  • 46,436
  • 33
  • 110
  • 175
6
votes
1 answer

Incorrect saturation calculation in RGB to HSL function

Does anybody know the correct formula to get the saturation level from an RGB color? I already have a function that does it. I've tried loads of them posted on the internet but only this one seemed to work (first-time) for me, apart from the…
TheCarver
  • 19,391
  • 25
  • 99
  • 149
5
votes
1 answer

CSS variable calculation of HSL values

I want to have a basic HSL color value which I want to implement as a gradient as follows: :root { --hue: 201; --saturation: 31; --lightness: 40; --mainColor: hsl(var(--hue),var(--saturation),var(--lightness)); --difference:…
Viktor
  • 153
  • 1
  • 13
5
votes
1 answer

Convert from relative luminance to HSL

Given a certain color in HSL (let's say hsl(74,64%,59%)), I want to calculate what darker shade (with the same h and s values) gives me enough contrast to satisfy W3C color contrast requirements. There are formulas to convert HSL to RGB (for example…
Peter
  • 2,874
  • 2
  • 31
  • 42
5
votes
1 answer

CSS: Why does converting a hex color to hsl and then back to hex lead to a different value

Strange thing that I discovered. When converting #579f2f to hsl, I arrive at hsl(99, 54%, 40%);. When converting this back to hex I get #559d2f. I used various online tools to test this. I guess the reason is that hsl describes the colors as hue…
Ole Spaarmann
  • 15,845
  • 27
  • 98
  • 160
1
2
3
17 18