Layout
display
display sets whether an element is a block that starts on its own line or sits within a line (outside), and how its contents are laid out (inside).
Syntax
[ <display-outside> || <display-inside> ] | <display-listitem> | <display-internal> | <display-box> | <display-legacy>Preview
Text 123 and more text.
Presets
Drag the bottom-right corner to resize
Code
.box > :nth-child(2) {
display: flex;
}Controls
displayflex
Text 123 and more text.
About
Values
inline: the initial value. The element sits within a line, like the letters of the text.widthandheighthave no effect, and verticalpaddingandborderare drawn without pushing the lines apart.block: the element starts on its own line and stretches to the full width.inline-block: a single solid box that sits within a line.width,height, and vertical spacing all take effect.flex/inline-flex: a block (or a box within a line) that lays out its children with flexbox. By default they sit in one row, and children without a set height stretch to the height of the row.grid/inline-grid: a block (or a box within a line) that lays out its children on a grid. Without columns, they stack in a single column, and children without a set width stretch to the width of the cell.flow-root: a block that starts a new block formatting context. Floats inside no longer stick out of the bottom, and the verticalmarginof its children stays inside. In this page’s sample it looks the same asblock.contents: the element’s own box disappears and its contents are laid out as if they sat directly in the parent. The element’s border and background are not drawn.none: neither the element nor its contents are shown, and they take up no space (unlikevisibility: hidden, no gap is left).
When to use it
- Use
flexorgridto line children up in a row or on a grid. - Use
inline-blockto give a link or button a size while keeping it within a line of text. - Use
noneto hide an element.
Things to watch
- Flex and grid items, floats, and elements with
position: absoluteorfixedare treated as blocks even withinlineand the like (inline-flexbecomesflex, andinline-gridbecomesgrid). - You can also give the outside and inside as two words, as in
display: inline flex, which all major browsers support. There are alsolist-item, which adds a list marker, and table parts such astableandtable-cell. The control on this page only offers the main single-word values. - Elements with
noneare hidden from screen readers too. - On buttons, headings, lists and tables,
contentscan make some browsers drop the element's role (that it is a button, for example) for screen readers. Use it on plain wrappers such as adivwhen you only want to change how the contents are laid out.
In the preview, the value applies to the container placed in the middle of the text (the second child, with the dashed blue border). It holds three tags of different heights (display: inline-block).