WDD 130: Web Fundamentals

CSS: Values and 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 is not relative to anything else and is typically the same size on most devices. Relative length is dependent on other items including the parent, sibling, or the size of the viewport.

"Every property used in CSS has a value type defining the set of values that are allowed for that property."
"The numeric type you will come across most frequently is the length (or unit of measurement). For example, 10px (pixels) or 30em. There are two types of lengths used in CSS — relative and absolute. It's important to know the difference in order to understand how big things will become." - MDN

Prepare

"There are many ways to specify color in CSS, some of which are more recently implemented than others. The same color values can be used everywhere in CSS, whether you are specifying text color, background color, or whatever else." - MDN

Activity Instructions

In this activity, answer the following questions about CSS value units/lengths.

  1. 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)

  2. Which CSS relative length unit is based upon the font size of the root element?
    Check Your Understanding

    rem

  3. 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