Block and inline layout
Definition and purpose
Normal flow places boxes according to their formatting context. In a horizontal block context, ordinary block boxes stack vertically; inline boxes participate in lines of text.
Two blocks
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; } #a, #b { display: block; height: 30px; width: 100px; } </style> </head> <body> <div id="a">Sample A</div> <div id="b">Sample B</div> </body></html>B starts below the 30px-tall A.
Syntax and mental model
display: block and display: inline describe different participation in flow. A non-replaced inline box does not take an ordinary width or height declaration as its box size. Inline content can wrap into several fragments.
Inline participation
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style>#a, #b { display: inline; width: 200px; }</style> </head> <body> <div id="a">Sample A</div> <div id="b">Sample B</div> </body></html>The words share a line when space permits; width does not size these ordinary inline boxes.
Common mistakes
Do not assume every block fills its parent: explicit width, margins and sizing constraints matter. Do not use display changes as replacements for semantic markup.
Practice and next steps
After trying the examples, complete the linked coding exercise and review questions. Predict the result before running your code. Prerequisite: Aspect ratio and replaced elements. Next lesson: Inner and outer display types.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Block and inline layout — knowledge check
Five questions on block and inline layout.
In horizontal block flow, where does the next ordinary block begin?
What happens to width on an ordinary non-replaced inline?
Can inline content span several lines?
What controls a block with explicit width?
Which preserves semantic heading meaning?