CSS Basic Tutorial
CSS Flexbox
In CSS, units are used to define the size of elements such as fonts, margins, padding, borders, and other properties. There are two types of units: relative units and absolute units.
Absolute units are fixed and don’t change based on other elements. These units are typically used when you need precise control over sizing.
The most commonly used unit. 1px equals one dot on the screen.
These are physical measurements, mostly used for print styles, not for screens.
Used in typography, where 1pt = 1/72 of an inch.
1 pica equals 12 points.
Relative units are more flexible and scalable. They change in relation to other measurements (such as the viewport size or a parent element’s size).
Defines size as a percentage of the parent element’s size.
Relative to the font-size of the element itself or its parent. For example, if the parent element’s font-size is 16px, 2em would be 32px.
Similar to em
, but relative to the font-size of the root element (usually the <
html
>
tag).
Try it yourself
vw
and vh
.vw
and vh
.Try it yourself
Relative to the width of the 0
character of the element’s font.