Hackforge Academy

Category: html_css

units in css

Published on 29 Jun 2026

Explanation

CSS provides different units to define sizes. Modern units like rem, em, %, vw, vh, and fr help create responsive layouts.

Code:

.box {
  width: 50%;
  height: 200px;
}

Explanation

The rem unit is relative to the root font size, making it ideal for consistent typography across a website.

Code:

h1 {
  font-size: 2rem;
}

Explanation

Viewport units (vw and vh) size elements relative to the browser window.

Code:

.hero {
  width: 100vw;
  height: 100vh;
}

Explanation

The fr unit is used in CSS Grid to distribute available space evenly among columns or rows.

Code:

.container {
  display: grid;
  grid-template-columns: 1fr 2fr;
}

Explanation

Percentage units (%) allow elements to resize relative to their parent container, improving responsiveness.

Code:

.card {
  width: 80%;
}

๐Ÿš€ Learn Spring Boot with real-world projects

๐Ÿ’ก Build REST APIs step by step

๐Ÿง  Improve backend development skills

๐ŸŽฏ Get career-ready practical training

Join Our Free WhatsApp Community

Direct access to niche-specific mentors and peers on WhatsApp.

๐Ÿ

Python Community

Discuss Django, FastAPI, AI integration, and automation scripts with 15k+ developers.

Join Python Community
โš›๏ธ

React Community

Master Next.js, Framer Motion, and State Management. Share your latest UI components.

Join React Community
โ˜•

Java Community

Deep dives into Spring Boot, Microservices architecture, and high-performance backend ops.

Join Java Community