CSS_Units_Report
CSS_Units_Report
1. Introduction
CSS units are used to define the size, spacing, and layout of elements in a web page. They allow
developers to create responsive designs that adapt to different screen sizes and resolutions.
CSS units can be broadly classified into two categories: Absolute and Relative.
Absolute units have a fixed size and are not affected by the parent element or viewport size. They
are ideal for print layouts but less flexible for responsive design.
|------|-------------------------------------|---------|------------|
Relative units are more flexible as they depend on the size of other elements, making them ideal for
responsive design.
| Unit | Description | Example | Reference Element |
|------|---------------------------------------|----------|-------------------|
| rem | Relative to the root element's font size | 1.5rem | Root element |
3. Usage Examples
h1 {
font-size: 24px;
body {
font-size: 16px;
p{
.container {
4. Best Practices
- Use rem for font sizes to maintain consistent scaling across the entire page.
- Use viewport units (vw, vh) for creating fluid layouts that adapt to screen size.
- Avoid absolute units (px, cm, etc.) for web designs unless necessary.
5. Conclusion
Choosing the right CSS unit is essential for creating scalable, responsive, and accessible web
designs. Relative units like em, rem, and viewport units are generally recommended for modern web
development.