width
Sets the inline size in normal horizontal writing mode. Use carefully on mobile.
Width and height define size, but professional CSS relies just as much on min-width, max-width, min-height, max-height and logical sizing.
.panel {
width: min(100%, 42rem);
min-height: 16rem;
}
Box Model
A width value can make an element clear and stable. A bad width value can make it overflow a mobile screen. A height value can create balance, but it can also clip real content.
Modern CSS often uses max-width, min-height, clamp(), min(), max() and logical properties to create flexible boundaries instead of rigid boxes.
The goal is not to avoid dimensions. The goal is to choose dimensions that respect content, layout context and screen size.
Sets the inline size in normal horizontal writing mode. Use carefully on mobile.
Limits how wide something can become while still allowing it to shrink.
Creates a minimum visual area without clipping taller content.
Sets a flexible value with a minimum, preferred value and maximum.
Visual model
Layout debugging becomes much easier when you can point to the exact part of the box that creates the visual result: inner space, outer space, edge, size or overflow behavior.
The box should not become smaller than usable content.
The box can breathe with viewport or container space.
The box should stop growing before lines become too long.
Examples
.article-card {
width: min(100%, 42rem);
min-height: 16rem;
padding: clamp(1rem, 3vw, 2rem);
}
.article-card {
width: 760px;
height: 260px;
padding: 36px;
overflow: hidden;
}
Rules that matter
Box model CSS should make the interface easier to reason about. When a value cannot be explained, it usually becomes a future layout bug.
Long lines become hard to read. Limit text containers.
Minimums create structure while allowing content to grow.
min(), max() and clamp() reduce breakpoint noise.
Images and video need max-width: 100% and sensible aspect handling.
A desktop width can become a mobile overflow bug.
overflow: hidden should not be used to mask bad height decisions.
Production thinking
Dimensions are where design intent meets real content. Good constraints make layouts calm; bad constraints make them brittle.
Users may zoom text or use larger default fonts. Flexible dimensions keep content readable when text grows.
Use dimensions as guardrails. Let content and layout systems do the rest whenever possible.
Readable line length and stable responsive sizing improve the page experience for human readers.
Live code lab
The preview runs in an isolated iframe. Links and forms stay inside the practice area, so you can experiment without leaving the lesson.
Mini assignment
Practice assignment
Try it yourself
Self-check
Answer these questions before moving on. If the answer is vague, change the lab CSS and inspect the box again.
Senior audit upgrade
width and height are only the start. min-content, max-content and fit-content help the browser size elements from their content.
The smallest size content can shrink to without avoidable overflow.
The natural size if content does not wrap.
A useful middle ground: fit content, but respect available space.