CSSCSS26 min read

CSS Width and Height

Learn how width and height really work, including percentages, max-width, and why fixed sizes break layouts.

David Miller
December 25, 2025
3.1k146

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