banner



How To Check The Rgb Of A Color

The CSS Podcast - 006: Colour Part 1

An audio version of this module

Color is an important function of whatsoever website and in CSS there are many options for color types, functions and treatments.

How do you decide which color type to use? How do you brand your colors semi-transparent? In this lesson, you're going to learn which options you have to help y'all brand the right decisions for your project and team.

CSS has various dissimilar data types, such as strings and numbers. Color is one of these types and uses other types, such as numbers for its own definitions.

Numeric colors #

It is very likely that your first exposure to colors in CSS is via numeric colors. Nosotros tin can work with numerical color values in a few dissimilar forms.

Hex colors #

                          h1              {              
color : #b71540;
}

Hexadecimal notation (often shortened to hex) is a shorthand syntax for RGB, which assigns a numeric value to red green and blue, which are the iii primary colors.

The hexadecimal ranges are 0-9 and A-F. When used in a six digit sequence, they are translated to the RGB numerical ranges which are 0-255 which represent to the reddish, dark-green, and blue color channels respectively.

You can also define an alpha value with any numerical colors. An blastoff value is a percentage of transparency. In hex code, y'all add together another ii digits to the six digit sequence, making an viii digit sequence. For example, to fix black in hex code, write #000000. To add a 50% transparency, modify it to #00000080.

Because the hex scale is 0-ix and A-F, the transparency values are probably non quite what you'd expect them to be. Here are some primal, mutual values added to the black hex code, #000000:

  • 0% alpha—which is fully transparent—is 00: #00000000
  • fifty% alpha is 80: #00000080
  • 75% blastoff is BF: #000000BF

To convert a two digit hex to a decimal, accept the beginning digit and multiply information technology by sixteen (because hex is base 16), and then add the 2nd digit. Using BF as an instance for 75% alpha:

  1. B is equal to 11, which when multiplied by sixteen equals 176
  2. F is equal to 15
  3. 176 + 15 = 191
  4. The alpha value is 191—75% of 255

RGB (Ruddy, Greenish, Blue) #

                          h1              {              
color : rgb (183, 21, 64) ;
}

RGB colors are defined with the rgb() color function, using either numbers or percentages as parameters. The numbers need to be within the 0-255 range and the percentages are between 0% and 100%‌. RGB works on the 0-255 scale, so 255 would be equivalent to 100%, and 0 to 0%.

To set up black in RGB, define it as rgb(0 0 0), which is zero red, null greenish and zero blue. Blackness can also be divers equally rgb(0%, 0%, 0%). White is the verbal opposite: rgb(255, 255, 255) or rgb(100%, 100%, 100%).

An alpha is ready in rgb() in ane of two ways. Either add a / after the red, dark-green and blue parameters, or use the rgba() function. The alpha can exist divers with a per centum or a decimal between 0 and one. For example, to set a 50% alpha blackness in modernistic browsers, write: rgb(0 0 0 / 50%) or rgb(0 0 0 / 0.v). For wider support, using the rgba() role, write: rgba(0, 0, 0, fifty%) or rgba(0, 0, 0, 0.5).

HSL (Hue, Saturation, Lightness) #

                          h1              {              
color : hsl (344, 79%, 40%) ;
}

HSL stands for hue, saturation and lightness. Hue describes the value on the color wheel, from 0 to 360 degrees, starting with red (being both 0 and 360). A hue of 180, or 50% would exist in the blueish range. Information technology'southward the origin of the color that we see.

A color wheel with labels for degree values in 60 degree increments to help visuals what each angle value represents

Saturation is how vibrant the selected hue is. A fully desaturated color (with a saturation of 0%) volition appear grayscale. And finally, lightness is the parameter which describes the calibration from white to black of added calorie-free. A lightness of 100% volition e'er requite yous white.

Using the hsl() color function, you define a truthful black past writing hsl(0 0% 0%), or fifty-fifty hsl(0deg 0% 0%). This is because the hue parameter defines the caste on the color bike, which if you utilise the number type, is 0-360. You tin can also use the bending blazon, which is (0deg) or (0turn). Both saturation and lightness are defined with percentages.

The HSL color function broken down visually. The hue uses the color wheel. The saturation shows grey blending into teal. The lightness shows black into white.

Alpha is defined in hsl(), in the same way as rgb() by adding a / after the hue, saturation and lightness parameters or by using the hsla() function. The alpha tin can exist divers with a percentage or a decimal between 0 and one. For example, to gear up a 50% alpha black, use: hsl(0 0% 0% / 50%) or hsl(0 0% 0% / 0.5). Using the hsla() part, write: hsla(0, 0%, 0%, 50%) or hsla(0, 0%, 0%, 0.five).

Color Keywords #

There are 148 named colors in CSS. These are obviously English language names such as regal, tomato and goldenrod. Some of the most popular names, co-ordinate to the Spider web Almanac, are black, white, reddish, blue and grayness. Our favorites include goldenrod, aliceblue, and hotpink.

Bated from standard colors, there are also special keywords bachelor:

  • transparent is a fully transparent color. Information technology is also the initial value of background-colour
  • currentColor is the contextual computed dynamic value of the color property. If you have a text colour of reddish so gear up the border-color to be currentColor, it will also exist red. If the chemical element that you define currentColor on doesn't have a value for color defined, currentColor will be computed by the cascade instead

Where to use color in CSS rules #

If a CSS holding accepts the <color> data type as a value, it volition have any of the higher up methods of expressing color. For styling text, use the color, text-shadow and text-decoration-colour backdrop which all accept color as the value or color as part of the value.

For backgrounds, you can set a color as the value for background or groundwork-color. Colors tin besides be used in gradients, such as linear-gradient. Gradients are a type of image that can be programmatically divers in CSS. Gradients accept two or more colors in any combination of color format, such every bit hex, rgb or hsl.

Finally, border-color, and outline-color set the colour for borders and outlines on your boxes. The box-shadow property besides accepts color as 1 of the values.

Test your noesis of color

Which of the following are valid colors?

rbga(400 0 ane) #0f08 #OOFZ2 rgb(255, 0, 0) hsl(180deg 50% 50%) hotpink

rbga is a typo of rgba and 400 is larger than it would accept anyway, making it invalid.

🎉

This is not a hex value, it'due south only 5 numbers and includes an Z, making it invalid.

🎉

🎉

🎉

Spot the invalid hsl colour.

hsl(v, 0%, 90%) hsl(.5turn 40% sixty%) hsl(0, 0, 0) hsl(2rad l% l%) hsl(0 0% 0% / xx%)

This is a valid hsl value.

This is a valid hsl value.

🎉 You institute it, the 2nd and 3rd values should exist percentages.

This is a valid hsl value.

This is a valid hsl value.

Resources #

  • A handy demo showing how you can use angles with HSL
  • A comprehensive guide on colour
  • [video] An explainer on how to read hex codes
  • How hexadecimal codes piece of work

Source: https://web.dev/learn/css/color/

Posted by: goodmanfavy1957.blogspot.com

0 Response to "How To Check The Rgb Of A Color"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel