Tsallaka zuwa abun ciki
Justice Tech School

Absolute and Relative Units

px is fixed. em follows the parent font size, rem follows the root size, % follows the parent, and vw and vh follow the viewport. Prefer rem for text so user settings are respected.

Example
<style>
.a { font-size: 1.25rem } .b { width: 50%; background: #134e4a } .c { height: 10vh; background: #0f766e }
</style>
<p class="a">1.25rem text</p><div class="b">50% wide</div><div class="c">10vh tall</div>

Exercise

Root relative unit.

font-size: 1.5;

Quiz Test

Which unit follows the viewport width?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.