Display and normal flow

Drop three paragraphs and a couple of links into a page with no CSS at all, and they still lay themselves out: the paragraphs stack down the page, the links sit inside the text where you wrote them. Nobody told the browser to do that. Before you write a single layout rule, there is already a layout, and every technique you reach for later is a change to it rather than a start from nothing. This chapter is about that starting point and the one property that governs it.
Normal flow
When a browser lays out a page with no layout CSS of your own, it uses normal flow: the default way elements arrange themselves. Block things like paragraphs and headings stack from the top down, each on its own line. Text and links run along inside a line, left to right, wrapping to the next line when they run out of room.
You have already met the pieces that flow around: this chapter builds on the box model, because it is those boxes that flow. Normal flow is worth naming because everything else in layout is defined against it. Flexbox, grid, and positioning are all ways of saying "arrange these differently from the default", so knowing the default is what makes the changes make sense.
Block boxes and inline boxes
Elements come in two main flavours in normal flow. A block box takes up the whole width of its container and stacks on its own line, pushing the next element below it. A paragraph <p>, a heading <h1>, and a <div> are all blocks, which is why they line up one under another.
An inline box is different. It sits inside a line of text and takes only as much room as its content needs, so several can share a line. A <span> or a link <a> is inline, which is why a link inside a sentence stays in the flow of the words rather than jumping to its own line.
<p>This paragraph is a block, so it sits on its own line.</p>
<p>Read the <a href="/css/box-model">box model</a> for more.</p>
<!-- the link is inline, so it stays inside the sentence --><p> and <div> take the full width and stack on their own lines. Inline boxes like <span> and <a> sit inside a line and take only the room they need. That is why a link stays inside your sentence instead of breaking onto its own row. The display property
Every element has a default kind, block or inline, but you are not stuck with it. The display property lets you change which one an element behaves like. Set display: block on a link and it now takes its own line; set display: inline on a list item and it sits in a row.
There is a third value that solves a common problem: display: inline-block. It flows in the line like an inline box, but it accepts a width, a height, and vertical padding like a block. That is what you want for something like a button or a nav pill that should sit next to its neighbours yet still take a set size.
.nav-link {
display: inline-block; /* flows in the line, but accepts width and padding */
padding: 8px 16px; /* vertical padding now works, unlike plain inline */
}display property changes whether an element behaves as a block or as an inline box. block takes its own line, inline sits in the text line. The handy middle option is inline-block, which flows in the line yet still accepts a width and padding, so it is what you want for buttons and nav links. Hiding things: display none versus visibility hidden
Sometimes you need an element to not show. There are two ways, and they behave differently. display: none removes the element completely: it disappears and leaves no gap, as if it were not in the page at all. visibility: hidden makes it invisible but keeps its space, so there is an empty hole where it used to be.
Which one you want depends on whether you want the space back. Use display: none to drop something out entirely, like a menu that is closed. Use visibility: hidden when you want to hide something without the layout jumping, because its box stays reserved.
.closed-menu {
display: none; /* gone, and no gap left behind */
}
.placeholder {
visibility: hidden; /* invisible, but still takes up its space */
}display: none removes the element and leaves no gap, visibility: hidden makes it invisible but keeps its space. Pick display: none when you want the space gone too, like a closed menu. Pick visibility: hidden when you do not want the layout to jump. How display changes the inner layout
You have seen display switch an element between block and inline. It does more than that at the deeper end. The same property is what turns a container into a flexbox or a grid, which are the two modern tools for arranging children in rows and columns. For now, the thing to hold on to is that display is the one dial that decides how a box lays out and how its children lay out inside it.
Layout is not one big switch you flip once. You change display on the specific containers that need a different arrangement, and everything you leave alone stays in normal flow. The flexbox and positioning chapters pick up from here.
display property that switches block and inline is also what turns a container into a flexbox or a grid for arranging children. Layout is not one switch you flip once; you change display on the containers that need it and leave the rest in normal flow. The flexbox and positioning chapters carry on from here. 
