Distinguish an element’s place among its neighbors from the layout it gives its children.
When you read a heading followed by a paragraph, the heading usually occupies a line of its own. A link inside the paragraph follows the surrounding words. The browser lays out these boxes according to their display type.
In ordinary horizontal text, a block-level box such as a paragraph starts a new block below the previous one. With automatic width, an ordinary block generally fills the available width. An inline box such as a link fits into the current line. If its words reach the edge of the paragraph, the link can continue on the next line.
Suppose a sentence contains two short links with room for both. As inline elements they can share a line with the surrounding text. Change each link’s display to block and each begins a separate block. Both are still links that can be followed with the keyboard. Display changes the layout boxes the browser generates.
An element also establishes a layout for its children. For example, display: flex ordinarily gives the container a block-level place among its neighbors and arranges its children using Flexbox. With inline-flex, the children still use Flexbox, while the container itself can sit alongside text.
display: none suppresses the boxes for the element and its descendants. The surrounding content closes the gap, and hidden controls are ordinarily unavailable to keyboard and assistive-technology users.
Try it yourself
HTML + CSS