Test your skills: Values and units

The aim of this skill test is to help you assess whether you understand different types of values and units used in CSS properties.

Note: To get help, read our Test your skills usage guide. You can also reach out to us using one of our communication channels.

Values and units 1

In this task, the first list item has been given a background color using a hex color code. Complete the CSS using the same color in different formats, plus a final list item where you should make the background semi-opaque.

You can convert the hex color using convertingcolors.com. You need to figure out how to use the values in CSS.

The starting point of the task looks like this:

Here's the underlying code for this starting point:

html
<ul>
  <li class="hex">hex color</li>
  <li class="rgb">RGB color</li>
  <li class="hsl">HSL color</li>
  <li class="transparency">Alpha value 0.6</li>
</ul>
css
body {
  font: 1.2em / 1.5 sans-serif;
}
ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

li {
  margin: 1em;
  padding: 0.5em;
}

.hex {
  background-color: #86defa;
}

/* Add styles here */

The updated styling should look like this:

Click here to show the solution

By using a color conversion tool, you should be equipped to use different color functions to define the same color in different ways:

css
.rgb {
  background-color: rgb(134 222 250);
}

.hsl {
  background-color: hsl(194 92% 75%);
}

.transparency {
  background-color: rgb(134 222 250 / 60%);
}

Values and units 2

In this task, we want you to set the font size of various items of text:

The starting point of the task looks like this:

Here's the underlying code for this starting point:

html
<h1>Level 1 heading</h1>
<p>
  Veggies es bonus vobis, proinde vos postulo essum magis kohlrabi welsh onion
  daikon amaranth tatsoi tomatillo melon azuki bean garlic.
</p>
<h2>Level 2 heading</h2>
<p>
  Gumbo beet greens corn soko endive gumbo gourd. Parsley shallot courgette
  tatsoi pea sprouts fava bean collard greens dandelion okra wakame tomato.
  Dandelion cucumber earthnut pea peanut soko zucchini.
</p>
css
body {
  font: 1.2em / 1.5 sans-serif;
}

h1 {
  /* Add styles here */
}

h2 {
  /* Add styles here */
}

p {
  /* Add styles here */
}

h1 + p {
  /* Add styles here */
}

The updated styling should look like this:

Click here to show the solution

You can use the following length values:

css
h1 {
  font-size: 50px;
}

h2 {
  font-size: 2em;
}

p {
  font-size: 16px;
}

h1 + p {
  font-size: 120%;
}

Values and units 3

To complete the task, update the CSS to move the background image so that it is centered horizontally and is 20% from the top of the box.

The starting point of the task looks like this:

Here's the underlying code for this starting point:

html
<div class="box"></div>
css
.box {
  border: 5px solid black;
  height: 350px;
}

.box {
  background-image: url("https://mdn.github.io/shared-assets/images/examples/purple-star.png");
  background-repeat: no-repeat;
}

The updated styling should look like this:

Click here to show the solution

Use background-position with the center keyword and a percentage:

css
.box {
  background-image: url("https://mdn.github.io/shared-assets/images/examples/purple-star.png");
  background-repeat: no-repeat;
  background-position: center 20%;
}