HTML & CSS Interview Question #69
What CSS units are commonly used?
CSS Fundamentals, Selectors, Cascade, Specificity, Box Model, Units & Typography Mid-Level Intermediate
Quick Interview Answer
Common CSS units include absolute units such as px and relative units such as %, em, rem, vw, vh, and newer viewport variants. CSS also provides physical units such as in, cm, and pt, although they are less common for ordinary screen layouts.
Detailed Explanation
Common CSS units include absolute units such as px and relative units such as %, em, rem, vw, vh, and newer viewport variants. CSS also provides physical units such as in, cm, and pt, although they are less common for ordinary screen layouts.
The best unit depends on the property and design goal. rem is useful for scalable spacing and typography, percentages for relative sizing, and viewport or container-related units for responsive designs.
Code Example
.page {
width: 90%;
max-width: 75rem;
}
.title {
font-size: 2rem;
}
.hero {
min-height: 60vh;
}