Test your skills: Values and units
The aim of this skill test is to assess whether you understand different types of values and units used in CSS properties.
Note: Click "Play" in the code blocks below to edit the examples in the MDN Playground. You can also copy the code (click the clipboard icon) and paste it into an online editor such as CodePen, JSFiddle, or Glitch. If you get stuck, you can reach out to us in one of our communication channels.
Task 1
In this task, the first list item has been given a background color using a hex color code. Your task is to complete the CSS using the same color in different formats, plus a final list item where you should make the background semi-opaque.
- The second list item should use RGB color.
- The third should use HSL color.
- The fourth should use RGB color but with the alpha channel set to
0.6
.
You can convert the hex color at convertingcolors.com. You need to figure out how to use the values in CSS. Your final result should look like the image below:
Try to update the code below to recreate the finished example:
<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>
.hex {
background-color: #86defa;
}
/* Add styles here */
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:
.hex {
background-color: #86defa;
}
.rgb {
background-color: rgb(134 222 250);
}
.hsl {
background-color: hsl(194 92% 75%);
}
.transparency {
background-color: rgb(134 222 250 / 60%);
}
Task 2
In this task, we want you to set the size of various items of text, as described below:
- The
<h1>
element should be 50 pixels. - The
<h2>
element should be 2em. - All
<p>
elements should be 16 pixels. - A
<p>
element that is directly after an<h1>
should be 120%.
Your final result should look like the image below:
Try to update the code below to recreate the finished example:
<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>
h1 {
}
h2 {
}
p {
}
h1 + p {
}
Click here to show the solution
You can use the following length values:
h1 {
font-size: 50px;
}
h2 {
font-size: 2em;
}
p {
font-size: 16px;
}
h1 + p {
font-size: 120%;
}
Task 3
In this task, we want you to move the background image so that it is centered horizontally and is 20% from the top of the box.
Your final result should look like the image below:
Try to update the code below to recreate the finished example:
<div class="box"></div>
.box {
background-image: url(https://mdn.github.io/shared-assets/images/examples/purple-star.png);
background-repeat: no-repeat;
}
Click here to show the solution
Use background-position
with ther center
keyword and a percentage:
.box {
background-image: url(https://mdn.github.io/shared-assets/images/examples/purple-star.png);
background-repeat: no-repeat;
background-position: center 20%;
}