HTML Inline Elements: Tags, Behavior, and CSS

Hi! In this guide, we look at how inline HTML elements are commonly used in modern website layouts, in line with current W3C and WHATWG standards.

Core Inline Elements in HTML

Inline elements are used to style parts of text, create links, and add interactive controls without disrupting the document’s normal flow.

HTML tagPurpose
<a>A hyperlink to another resource or an in-page anchor
<abbr>An abbreviation or acronym (its expansion can be provided with the title attribute)
<b>Stylistically offsets text in bold without adding semantic importance
<bdo>Overrides the text display direction (Bidirectional Text Override)
<br>Forces a line break within text
<button>An interactive button (inline-block by default)
<cite>A citation of a source or the title of a work, book, or article
<code>A fragment of computer code
<dfn>Marks a term being defined in the text
<em>Emphasized text (semantic stress, displayed in italics by default)
<i>Text in an alternate voice or mood (for example, technical terms, foreign words, or icons)
<img>An image (a replaced inline element according to the specification)
<input>A form input field (inline-block by default)
<kbd>Text entered by the user via a keyboard
<label>A text label for a form control
<q>A short inline quotation (browsers usually add quotation marks automatically)
<s>Text that is no longer accurate (rendered with a strikethrough)
<samp>Sample output from a computer program or system
<select>A drop-down list in a form (inline-block)
<small>Fine print (disclaimers, copyright notices, and legal caveats)
<span>A generic, non-semantic container for inline elements or text fragments
<strong>Important text with strong semantic significance (bold by default)
<sub>Subscript text (for chemical formulas and mathematical expressions)
<sup>Superscript text (for exponents and footnotes)
<textarea>A multiline text input field (inline-block)
<u>Text with a visual underline (for example, to mark spelling errors or proper names)
<var>A mathematical or programming variable

How Inline Elements Behave

Flow and occupied width

Inline elements do not start on a new line. They take up only as much space as their content requires and flow horizontally, one after another, as long as there is room in the parent container.

Nesting rules (an important HTML5 exception)

As a general rule, block-level elements cannot be placed inside inline elements. However, modern HTML5 standards make an exception for the <a> tag: a link can wrap entire block-level elements (such as <div> or <article>), acting as a container for the whole block.

Why width and height Have No Direct Effect

For ordinary inline elements (display: inline), the width and height properties do not apply and are ignored by the browser. An element’s dimensions are determined by its content and the line-height and font-size values.

Note on replaced elements: The width and height properties work on <img>, <input>, <button>, <textarea>, and <select> because these are replaced elements or have display: inline-block by default.

Margins, Padding, and Borders

  • Horizontal spacing: margin-left, margin-right, padding-left, padding-right, and side borders work as expected, shifting adjacent inline elements horizontally.
  • Vertical spacing: margin-top and margin-bottom are completely ignored. padding-top, padding-bottom, and vertical borders are visually added to the element, but do not affect the line box height or move neighboring content vertically; they can overlap adjacent text.

Whitespace in HTML Source (Inline Spacing)

In HTML source code, any line break or whitespace between inline elements is rendered by the browser as a single space (about 4px wide, depending on the font).

  • To remove unwanted spacing between inline elements, modern CSS offers these options:
    • Use a parent container with display: flex or display: grid.
    • Set font-size: 0 on the parent element, then restore the font size for its children.
  • To prevent text from wrapping inside an inline element, use the CSS property white-space: nowrap.
Mykhailo Petrov
Mykhailo Petrov

Full-cycle WordPress website development, improvements, new features, bug fixes, maintenance, updates and migration to another domain or hosting.