Block elements start on a new line and stretch to fill the width of their container, while inline elements sit inside a line of text and take only as much width as their content needs. A <div> or <p> is block, and a <span> or <a> is inline. Understanding block vs inline elements in HTML explains most beginner layout surprises, such as why width does not work on a link.
The differences are about default display behaviour, so CSS can change them with the display property.
A block-level element begins on a new line, and by default stretches to the full available width of its parent. Elements before and after it are pushed to separate lines. You can set width, height, margin and padding on all four sides and they all behave as expected.
Common block elements:
<p>, <h1> to <h6>, <blockquote>, <pre><div>, <section>, <article>, <header>, <footer>, <main>, <nav>, <aside><ul>, <ol>, <li>, <dl><form>, <table>, <hr>, <figure>Each of these three elements occupies its own row, no matter how short the text is.
An inline element does not start a new line. It flows with the surrounding text, wrapping across lines when needed, and takes up only the space of its content.
Common inline elements: <span>, <a>, <strong>, <em>, <code>, <img>, <abbr>, <small>, <label>, <br>.
Inline elements have limits:
width and height have no effect on them (replaced elements like <img> are the exception).margin has no effect. Horizontal margin and padding work.| Behaviour | Block | Inline |
|---|---|---|
| Starts on a new line | Yes | No |
| Default width | Full width of the container | Width of its content |
| Width and height properties | Respected | Ignored |
| Top and bottom margin | Respected | Ignored |
| Can contain | Block and inline elements | Mostly other inline elements and text |
| Examples | <div>, <p>, <ul> | <span>, <a>, <em> |
Whether an element is block or inline is its default, set by the browser stylesheet. You can override it:
The three <span> elements stay on one row but accept a width, because inline-block combines both models. The links in the <nav> become full-width rows, which makes them easier to tap on a phone.
The three most-used values:
display: block: new line, full width.display: inline: flows in text.display: inline-block: flows in text, but accepts width, height and vertical margin.Modern layouts also use display: flex and display: grid on a container, which controls how its children are arranged.
HTML defines which elements may contain which. The old rule of thumb is that inline elements should not contain block elements. For example, a <span> should not wrap a <div>, and a <p> cannot contain another <p>.
The modern specification describes this using content categories such as flow content and phrasing content, not block and inline. The notable exception is the <a> element, which is allowed to wrap block-level content in HTML5, so a whole card can be a link.
Wrongly nested markup, such as a <div> inside a <p>, makes the parser close the paragraph early, and the DOM no longer matches what you wrote.
It is inline by default, but it is a replaced element, so it accepts width and height. A small gap can appear under it because it sits on the text baseline. Setting display: block removes the gap.
Block. <div> is a generic block container with no meaning of its own. Its inline counterpart is <span>.
Links are inline by default, and inline elements ignore width and height. Set display: inline-block or display: block on the link.
HTML5 replaced them as content categories with flow and phrasing content, but browsers still apply block and inline display by default, so the terms are still useful in CSS.
Block elements take a full row and respect all box properties. Inline elements flow with text and ignore width, height and vertical margins. Use <div> and <p> for blocks, <span> and <a> for inline parts, and the CSS display property to change the default, using inline-block when you need both behaviours.