In this example we have two block-level container elements, each one with three inline children. Below that, we have a select menu that allows you to apply different display
values to the containers, allowing you to compare and contrast how the different values affect the element's layout, and that of their children.
We have included padding
and background-color
on the containers and their children, so that it is easier to see the effect the display values are having.
HTML
<article class="container">
<span>First</span>
<span>Second</span>
<span>Third</span>
</article>
<article class="container">
<span>First</span>
<span>Second</span>
<span>Third</span>
</article>
<div>
<label for="display">Choose a display value:</label>
<select id="display">
<option selected>block</option>
<option>block flow</option>
<option>inline</option>
<option>inline flow</option>
<option>flow</option>
<option>flow-root</option>
<option>block flow-root</option>
<option>table</option>
<option>block table</option>
<option>flex</option>
<option>block flex</option>
<option>grid</option>
<option>block grid</option>
<option>list-item</option>
<option>block flow list-item</option>
<option>inline flow list-item</option>
<option>block flow-root list-item</option>
<option>inline flow-root list-item</option>
<option>contents</option>
<option>none</option>
<option>inline-block</option>
<option>inline flow-root</option>
<option>inline-table</option>
<option>inline table</option>
<option>inline-flex</option>
<option>inline flex</option>
<option>inline-grid</option>
<option>inline grid</option>
</select>
</div>
CSS
html {
font-family: helvetica, arial, sans-serif;
letter-spacing: 1px;
padding-top: 10px;
}
article {
background-color: red;
}
article span {
background-color: black;
color: white;
margin: 1px;
}
article,
span {
padding: 10px;
border-radius: 7px;
}
article,
div {
margin: 20px;
}
JavaScript
const articles = document.querySelectorAll(".container");
const select = document.querySelector("select");
function updateDisplay() {
articles.forEach((article) => {
article.style.display = select.value;
});
}
select.addEventListener("change", updateDisplay);
updateDisplay();
Result
Note that some multi-keyword values are added for illustration which have the following equivalents:
-
block
= block flow
-
inline
= inline flow
-
flow
= block flow
-
flow-root
= block flow-root
-
table
= block table
-
flex
= block flex
-
grid
= block grid
-
list-item
= block flow list-item
-
inline-block
= inline flow-root
-
inline-table
= inline table
-
inline-flex
= inline flex
-
inline-grid
= inline grid
You can find more examples in the pages for each separate display type under Grouped values.