CSS Width and Height
Learn how width and height really work, including percentages, max-width, and why fixed sizes break layouts.
David Miller
Dec 24, 2025
33.8k1,283
Width and height control element size.
Fixed width (danger)
.box {
width: 500px;
}
Breaks on mobile.
Flexible width (best)
.box {
width: 100%;
max-width: 500px;
}
Height
Avoid fixed height unless necessary.
Real world advice
- Let content decide height
- Control width carefully
Remember
- max-width saves responsive layout
- Fixed sizes cause problems
#CSS#Beginner