block
Starts on a new line and takes available inline space by default.
display controls how an element participates in layout. It decides whether a box behaves like a block, inline content, flex container, grid container or disappears entirely.
.nav { display: flex; gap: 1rem; }
Box Model
HTML elements have default display behavior. A paragraph is block by default. A link is inline by default. A div is block by default. CSS can change that behavior.
display is often the bridge between the box model and real layout. Once an element becomes flex or grid, its children enter a new layout system.
Changing display can also affect accessibility and document flow. display: none removes content visually and from the accessibility tree.
Starts on a new line and takes available inline space by default.
Flows with text. Width and height do not behave like block boxes.
Flows inline but accepts width, height, padding and margin more like a box.
Creates a layout context for children. This is where modern layout begins.
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.
Page sections, paragraphs and cards stack in normal flow.
Links and text-level elements flow inside a line.
One-dimensional alignment for rows or columns.
Two-dimensional placement for rows and columns.
Examples
.nav-list { display: flex; gap: 1rem; } .card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); }
.nav a { display: block; margin-left: 43px; } .cards article { display: inline; width: 300px; } .error { display: none; /* message is gone */ }
CSS quick reference
Use these patterns when you need the syntax quickly. Each example has its own anchor, so search engines and readers can land directly on the exact pattern instead of only at the top of the lesson.
A clean version of the pattern from this lesson. Use it as the first place to check syntax and structure.
.nav-list { display: flex; gap: 1rem; } .card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); }
A readable pattern you can adapt without copying a weak shortcut.
The smallest useful version of the topic. This is the quick reminder when you only need the shape of the code.
.nav { display: flex; gap: 1rem; }
A compact syntax reference for scanning, searching and reuse.
The CSS from the live lab. Change one declaration at a time and watch how the interface responds.
body { margin: 0; min-height: 100vh; display: grid; place-items: center; background: #07111f; font-family: Inter, system-ui, sans-serif; } .nav { display: flex; gap: 12px; padding: 16px; border-radius: 999px; background: #101827; border: 1px solid #263247; } .nav a { display: inline-flex; min-height: 44px; align-items: center; padding-inline: 18px; border-radius: 999px; background: #162033; color: white; font-weight: 900; }
A practical starter block for experimentation.
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.
Do not change display before understanding what the element already does.
Major layout areas usually behave as blocks.
Links and emphasis usually belong in text flow.
Flex is excellent for alignment in rows or columns.
Grid is stronger when rows and columns both matter.
It removes content from visual layout and accessibility exposure.
Production thinking
display is the first serious layout switch. Choose it well and the rest of the CSS becomes simpler.
display: none hides content from assistive technologies. Use it only when content should genuinely be unavailable.
Document display decisions in components. A button, navigation list and card grid should not rely on accidental defaults.
Important content should not be hidden with display: none as a content strategy.
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
When an element has display: none, it is not visible and is generally removed from the accessibility tree.
display: none is right for inactive views or closed panels, not for text screen readers still need.
Use a visually-hidden utility when content should remain available to assistive tech.
Changing display also changes how children participate in layout.
Chapter project
Use sizing, padding, borders, overflow and display choices to keep cards stable with real content.
three pricing cards that survive long text and narrow screens
Does the layout still work when one card has twice as much text?