🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Expert Masterclasses.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
REFERENCEcss

css Documentation

LOADING ENGINE...

CSS Screen Dimensions

Master the layout. Learn how to control size with pixels, percentages, viewport units, and constraints.

style.css
.container {
width: 100%;
max-width: 1200px;
min-height: 100vh;
}
width: 75%Responsive
styles.css
1 / 8
📏

Tutor:The 'width' and 'height' properties control the size of an element. By default, block elements take up 100% of the width.


Dimensions Tree

Unlock nodes by mastering Width, Height, and Viewport units.

Concept 1: Width & Height

The fundamental properties for sizing. Using px creates rigid, absolute dimensions that do not adapt to screen changes.

System Check

Which unit creates a fixed, non-responsive size?


Community Blueprints

Share Layouts

Created a perfect grid or responsive card? Share your dimension patterns.

Enjoying this guide?

Codesyllabus is 100% free and open-source. Support our mission, pay for server infrastructure, and fuel new tutorials by buying us a coffee!

CSS Screen Dimensions

Author

Pascual Vila

Frontend Instructor.

Controlling the dimensions of elements is fundamental to web layout. The width and height properties determine the size of the content box. Understanding the different units available is key to creating responsive designs.

Types of Units

  • Pixels (px): Absolute units. 200px will always be 200 physical pixels on the screen (normalized). Good for borders or fixed icons, but rigid for main layouts.
  • Percentages (%): Relative to the parent element. width: 50% means the element takes up half the width of its container. Essential for fluid grids.
  • Viewport Units (vw/vh): Relative to the browser window size. 100vh equals 100% of the viewport height. Great for hero sections.

Constraints: Min and Max

To prevent layouts from breaking, we often use constraint properties. max-width stops an element from getting too wide on large screens, while min-height ensures a section is tall enough even if it has little content.

The Box Model Context

Remember that by default, padding and border are added outside the defined width and height. Use box-sizing: border-box to include padding and border within the total size.

Dimensions Glossary

Viewport (vw / vh)
The visible area of the web page. 1vw is 1% of the viewport width; 1vh is 1% of the viewport height.
Relative Units (%)
Units that scale based on another value, typically the dimensions of the parent element.
Absolute Units (px)
Fixed units that do not change based on the screen size or parent container.
Max-Width
A property that sets the maximum width an element can reach. If the viewport is smaller, the element will shrink.