liveBook · Manning

Block-level element

As explained in CSS in Depth, Second Edition

A block-level element generates block-level content that starts on its own line and normally fills the available width of its container.

A block-level element appears on its own line in normal document flow and normally fills the available width of its container. Unlike an inline element, it has a line break above and below it—even if you reduce its width. Paragraphs, divs, and headers get this behavior from the browser’s default stylesheet. section 3.1

Width and height behave differently in this flow. A parent’s width constrains its children, whose contents wrap as needed; the children’s heights, in turn, determine the parent’s height. This is why a full-width block does not need a fixed height to contain several lines of text. section 3.1

Turn links into stacked buttons

Set `.button-link { display: block; }` to put each link on its own line and make it fill its container. For spacing, `.button-link + .button-link { margin-block-start: 1.5em; }` adds a margin only between adjacent buttons. Giving every button a top margin would also add unwanted space beside the container’s top padding. section 3.6

Check the element you are styling before relying on automatic width. A form input set to `display: block` appears on its own line, but its width is still influenced by its `size` attribute. Set `inline-size: 100%` when it needs to fill the available width. section 4.3.2

Listing 3.13 Using an adjacent sibling combinator to apply a margin between buttons
.button-link {
  display: block;
  padding: 0.5em;
  color: #fff;
  background-color: var(--brand-color);
  text-align: center;
  text-decoration: none;
  text-transform: uppercase;
}
.button-link + .button-link {    #1
  margin-block-start: 1.5em;     #1
}                                #1

The listing shows block-level links and an adjacent-sibling rule that spaces the links without adding a margin before the first one. section 3.6

How CSS in Depth, Second Edition covers it

How deep it goes
Defines default flow and works through spacing and input-width exceptions, without detailing browser layout internals.
Examples
Shows paragraphs and headers in a one-column page, stacked sidebar links, and block-displayed login inputs.
What it assumes
Assumes familiarity with basic HTML elements and CSS rules while defining normal document flow from the inline–block distinction.
What you can do after
Apply it via CSS `display: block` to stack links or inputs, then adjust spacing or width where needed.
How it connects
Connects block-level elements to inline elements, normal document flow, container width, padding, and margins.

Also explained in

Compare how 2 books explain block-level element →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of CSS in Depth, Second Edition. The section links point to the parts of the book it draws on.