How to pick CSS sizing units for responsive design

TL;DR
Pixels are the baseline unit and remain useful, while viewport units (vw, vh) adapt to screen size for responsive layouts. EM and REM scale text relative to parent or root font size, helping maintain proportional typography. Use Vmin and Vmax for flexible dimensions across different viewports.
Transcript
In CSS, you will get to see different types of sizing units. Sometimes you will get to see pixels, sometimes you will get to see VH, sometimes you will get to see VW, sometimes you will get to see RAM, you will get to see M. Which unit do you want to use? Which is the best among them? Which one do you want to avoid? And what do these units mean? Th... Read More
Key Insights
- Pixels are a universal unit for exact sizing
- Viewport units (vw, vh) relate to the visible screen area
- Vmin and vmax adapt to the smaller or larger viewport dimension
- EM scales with the parent’s font size and inherits
- REM scales with the root font size and remains constant across descendants
- Box sizing with border box helps prevent unexpected overflow
- Margin auto centers block level elements horizontally
- Using responsive units prevents layout breakage on different devices
Install to Summarize YouTube Videos and Get Transcripts
Explore YouTube Video Summarizer or Get YouTube Transcript Extractor
Questions & Answers
Q: How do pixels differ from viewport units in CSS sizing?
Pixels specify an exact size regardless of screen dimensions, which can cause layout issues on smaller devices. Viewport units tie element size to the visible area of the device, helping maintain proportional layouts and reducing horizontal scrolling as the screen size changes.
Q: What is the role of EM in CSS typography sizing?
EM scales relative to the font size of the parent element, so changing the parent's size changes all descendants proportionally. It is useful for responsive typography where local scaling needs to propagate through nested elements.
Q: What is the role of REM in CSS typography sizing?
REM scales relative to the root element font size, providing consistent typography across the document. Unlike EM, REM does not cascade from parent elements, making it easier to predict final font sizes in nested elements.
Q: When should Vmin and Vmax be used in CSS?
Vmin and Vmax adapt to the smaller or larger dimension of the viewport, enabling flexible sizing rules that respond to device orientation and size changes. They help keep elements within usable bounds on a wide range of screens.
Q: Why would using 100vw cause horizontal scrolling, and how can it be mitigated?
Using 100vw sets width to the full viewport width, which can include scrollbars and borders, causing overflow. Mitigation includes using box-sizing to border box, or combining with max-width and responsive container widths to prevent overflow.
Q: How does margin auto help center a box in CSS?
Margin auto distributes remaining horizontal space equally on both sides of a block level element, effectively centering it. This works best for elements with defined width and display as a block level element.
Q: What is the benefit of border box in CSS box sizing?
Border box makes the element width and height include padding and border, which prevents the element from becoming wider than expected when borders or padding are added. This stabilizes layouts and reduces overflow.
Q: How can you ensure typography scales predictably with EM and REM?
Use a defined root font size for REM calculations and set base font sizes on containers with EM carefully to maintain proportional scaling. This approach ensures nested elements scale consistently and remain readable across devices.
Summary & Key Takeaways
-
This video introduces multiple CSS sizing units including px, viewport units, rem, em, vmin and vmax, and explains when each unit is appropriate. It demonstrates how a box can use different units to achieve responsive width and height and discusses centering and scalable typography. Practical examples show how viewport width preserves layout on various devices.
-
The content emphasizes that Pixel units are universal but viewport units help with responsive design, while REM and EM control typographic scale. It covers how to compare 80vw vs 100vw and how to center elements with margin auto, plus how inheritance affects font sizes when using em and rem.
-
The lesson also explains common pitfalls such as horizontal scrolling with full viewport widths and how box sizing interacts with borders. It concludes with a reminder to practice with real devices or responsive tools to see how units behave across viewports.
Read in Other Languages (beta)
Share This Summary 📚
Summarize YouTube Videos and Get Video Transcripts with 1-Click
Try YouTube Summary with ChatGPT & Claude or YouTube Transcript Generator
Explore More Summaries from CodeWithHarry 📚






Summarize YouTube Videos and Get Video Transcripts with 1-Click
Try YouTube Summary with ChatGPT & Claude or YouTube Transcript Generator