![]() ![]() If this becomes an issue for random color selection, example 2 shows one way to compensate. Black text on a blue background - or blue over black - is harder to read in comparison to other colors. The human eye is least sensitive to the color blue. Output (note that the output is not consistent due to the randomness): You can set a random background color for a div element. And then, you can concatenate them into a string with commas and parentheses. A lightness value of 0% creates black no matter what the hue and saturation values are. To generate a random RGB color in JavaScript, you need to create three random integers between 0 and 255 using the Math.random () function. A saturation value of 0% creates a grey-scale tone based on lightness alone.Ĭolors blend with black as lightness decreases below 50%. A lightness value of 100% creates white regardless of what the values of hue and saturation are.Ĭolors blend with grey as the saturation decreases and become more washed out depending on how low the saturation gets. ![]() In HSL color space, bright colors are represented by a hue based on their position on the color wheel with 100% saturation and a lightness value of 50%:Ĭolors blend with white - and become more "pastel" as lightness increases above 50%. "Bright" colors refer to the colors of an RGB color wheel formed by starting at red and then blending pure red into green, pure green into blue, and finally pure blue back into red again. Where hue is in range 0-360 (without a unit marker when using degrees), and both saturation and lightness are percentages 0-100 with a trailing % sign. This is a tutorial and code for building a random color generator that displays the hex color code of the current document background color. HSL color values are specified in CSS as hsl( hue, saturation%, lightness%) Using HSL Colors colors may be the easiest. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |