W02 Learning Activity: CSS Units of Measurement
Overview
In CSS, property length values are needed to provide layout and presentation control. There are two main types - absolute and relative. The absolute length, like 10px (pixels), is not relative to anything else and is typically the same size on most devices. Relative lengths, like 90%, are dependent on other items including the parent, sibling, or the size of the viewport.
Prepare
- Video Demonstration: ▶️ CSS: Units of Measurement – [ 4:47 minutes, 📄 Transcript ]
- CSS color values for text, backgrounds, and wherever applicable can be coded by the following methods:
- keyword:
antiquewhite
,burlywood
,yellow
,lightyellow
, etc - hexadecimal RGB (red, green, blue):
#faebd7
where the first two characters are the red value, the next two are the green value, and the last two are the blue value in hexadecimal (base16) format (0 to F) - RGB or RGBA:
rgb(250, 235, 215)
orrgb(250 235 215 / 1)
wherer
is a red value ranging from 0 to 255,g
is a green value ranging from 0 to 255,b
is a blue value ranging from 0 to 255, and the last value is the alpha value ranging from 0 to 1 (0% to 100%) - HSLA:
hsla(34, 78%, 91%, 1)
whereh
is the hue (0 to 360),s
is the saturation (0% to 100%),l
is the lightness (0% to 100%), anda
is the alpha value (0 to 1)
- keyword:
Activity Instructions
In this activity, answer the following questions about CSS value units/lengths.
- What is the most common absolute length unit for screens?
Help – Scroll down to Absolute length units to find the answer.
Check Your Understanding
px (pixels)
- Which CSS relative length unit is based upon the font size of the
root element?
Check Your Understanding
rem
- Given a hexadecimal (base16) color value of #0e421c,
what value is the Green level?
Check Your Understanding
42
There are two hexadecimal values per color. First red, then green, and then blue. That is why there are six total characters with values in hex (0 to F).
Optional Resources
- CSS Values and Units – MDN
- Color Section – MDN
- Named Colors / Keywords – MDN