Units: px, %, rem, em, vh, vw
Choose sizing units that scale correctly for text, spacing, viewport sections, and responsive layouts.
Last reviewed: June 2026
🔍 What Is It?
Different CSS units solve different problems. px is fixed, rem scales from the root, em scales from the current context, percentages respond to parent size, and viewport units respond to the screen.
🎯 Why Do We Need It?
Wrong unit choices create cramped text, layout bugs, inaccessible scaling behavior, and components that respond poorly across devices.
Why interviewers ask about this:
- →They want to know whether you understand browser behavior, not only syntax
- →Strong answers connect markup or styling choices to accessibility, maintainability, and production quality
- →Senior candidates explain the trade-offs, not only the definition
🏗️ What Happens in Real Projects?
Units appear in typography, spacing, widths, heights, cards, hero sections, modal sizing, and sticky layout offsets.
⚙️ How It Works
Pick units based on what should stay fixed, what should scale, and what depends on parent or viewport dimensions.
💻 Example
Mixed-unit component sizing — A practical example of units: px, %, rem, em, vh, vw in a real frontend workflow.
🤔 Common Confusions
❓ Is Units: px, %, rem, em, vh, vw only a beginner topic?
No. Units: px, %, rem, em, vh, vw keeps affecting accessibility, layout resilience, and frontend maintainability long after a developer moves beyond the basics.
❓ What makes Units: px, %, rem, em, vh, vw hard in real projects?
The difficulty usually appears when real content, different browsers, mobile constraints, or reusable component rules expose assumptions that looked fine in a tiny demo.
❓ How should I answer Units: px, %, rem, em, vh, vw in interviews?
Explain the core behavior, then connect it to one real frontend scenario and one production failure mode. That shows deeper understanding than a raw definition alone.
🚨 Common Production Issues
Everything is hardcoded in px and becomes unfriendly to user scaling or accessibility settings.
Viewport units create mobile-height bugs when browser chrome changes.
Nested em usage becomes confusing because component context is not understood.
✅ Best Practices
Use rem for scalable typography and many spacing tokens.
Be deliberate with viewport units on mobile surfaces.
Understand what the percentage is relative to before using it.
Choose units based on behavior, not only familiarity.
🏛️ Architect's Note
Units: px, %, rem, em, vh, vw should be treated as part of the frontend system, not as an isolated trick. The architecture conversation is about clarity, resilience, accessibility, and whether multiple teams can keep using the pattern safely.
💬 Frequently Asked Questions
🎯 Key Takeaways
🔗 Related Topics
🎯 Practice this topic in interviews
↗ Where this topic fits
HTML & CSS Technology Guide
Return to the HTML & CSS learning hub.
WordPress Developer Career Path
A practical route through WordPress fundamentals, theming, plugins, content modeling, Gutenberg, API integration, WooCommerce basics, production troubleshooting, and interview preparation.
Sources
Sources / References
Use these HTML & CSS references to verify the concept in official docs and continue into the most relevant SplashRide pages.
Official documentation
Related SplashRide pages
SplashRide HTML & CSS learning path
Browse the full HTML & CSS topic collection and learning order on SplashRide.
HTML & CSS Interview Prep
Practice HTML & CSS interview questions and scenario-based answers.
WordPress Developer Career Path
A practical route through WordPress fundamentals, theming, plugins, content modeling, Gutenberg, API integration, WooCommerce basics, production troubleshooting, and interview preparation.
Box Model
Understand how content, padding, border, and margin determine the real space an element uses.
Responsive Breakpoints
Choose breakpoints based on content behavior, not only on popular device sizes.
Mobile-First CSS
Start from the smallest practical experience and progressively enhance for larger screens.