CSS Display: Block, Inline, Flex, Grid and None
The CSS display property controls how an element's box participates in layout. Learn the basic flow values, how Flexbox and Grid use display, and the difference between hiding with display: none and visibility: hidden.
Block, inline and inline-block
display: block starts an element on a new line and, when its width is automatic, fills the available space. display: inline lets an element flow with text; width and height generally do not apply in the same way. display: inline-block flows alongside text but lets you set a width and height.
.notice {
display: block;
margin-block: 1rem;
}
.tag {
display: inline-block;
padding: 0.25rem 0.6rem;
}
CSS can change an element's visual display without changing its HTML meaning. Choose HTML elements for what their content means, then use CSS for presentation.
Use Flexbox or Grid for layout
Set display: flex when you want to arrange and align items along a row or column. Set display: grid when a layout needs rows and columns. These values establish layout contexts for an element's direct children.
.toolbar {
display: flex;
align-items: center;
gap: 1rem;
}
.card-list {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 1rem;
}
Continue with the Flexbox lesson for alignment and wrapping, or the CSS Grid lesson for two-dimensional layouts.
Hide an element with CSS
display: none hides an element and removes its box from the layout, so following content can move into its place. visibility: hidden hides the element but keeps its space in the layout.
.notice--closed {
display: none;
}
.notice--reserved-space {
visibility: hidden;
}
Use these values only when that visibility behavior is intended. If an interface control hides important content, also make sure the control communicates its state and that users can reach the content when needed.
Common display questions
Does display: none leave an empty gap?
No. Its box is removed from layout. Use visibility: hidden when the space should remain reserved.
Does display: block change an element's meaning?
No. It changes the visual layout behavior, not the element's semantic role in HTML.