Open original
Info
Demo 1.3

Block vs. Inline Elements

Every element is either a block or an inline element, and that decides how it behaves before you write a single line of CSS.

Block elements

A block takes the full width available and starts on a new line. Headings, paragraphs, lists and <div> are all blocks. Put two next to each other and they stack.

Inline elements

An inline element is only as wide as its content and stays in the flow of the text around it. Links, <strong>, <em> and <span> are inline. Put two next to each other and they share a line.

Why it matters

Inline elements go inside block elements, not the other way around. A <strong> inside a <p> is right. A <p> inside a <strong> is not, and the browser will quietly rearrange your page to fix it, which is a fun thing to debug at midnight.

If a layout is behaving strangely and you can’t work out why, this is usually the reason.

Next demoTypography
Keyboard Shortcuts
⌘ Z / ⌘ ⇧ ZCtrl Z / Ctrl ⇧ Z Undo / redo
Tab / ⇧ TabTab / ⇧ Tab Indent / unindent selection
⌘ ] / ⌘ [Ctrl ] / Ctrl [ Indent / unindent lines
⌘ ACtrl A Select all
⌘ DCtrl D Select next occurrence of selection
⌘ /Ctrl / Comment / uncomment lines
Ctrl SpaceCtrl Space Autocomplete
Ctrl EnterCtrl Enter Reset layout
⌘ ⌥ [ / ⌘ ⌥ ]Ctrl ⇧ [ / Ctrl ⇧ ] Fold / unfold block
Code
The editor didn't load — try refreshing the page. Navigation, shortcuts and the info panel still work in the meantime.
Preview
Dimensions0 × 0
Delay
Console