In HTML, inline elements are those which only occupy the space bounded by the tags defining the element, instead of breaking the flow of the content. In this article, we'll examine HTML inline elements and how they differ from block-level elements.
An inline element does not start on a new line and only takes up as much width as necessary.
This is most easily demonstrated with a simple example. First, some simple CSS that we'll be using:
.highlight { background-color:#ee3; }
First, let's look at the following example which demonstrates an inline element:
<p>The following span is an <span class="highlight">inline element</span>; its background has been colored to display both the beginning and end of the inline element's influence.</p>
In this example, the <p>
(Paragraph) block-level element contains some text. Within that text is a <span>
element, which is an inline element. Because the <span>
element is inline, the paragraph correctly renders as a single, unbroken text flow, like this:
Now let's change that <span>
into a block-level element, such as <div>
:
<p>The following div is an <div class="highlight">block-level element;</div> its background has been colored to display both the beginning and end of the block-level element's influence.</p>
Rendered using the same CSS as before, we get:
See the difference? The <div>
element totally changes the layout of the text, splitting it into three segments: the text before the <div>
, then the <div>
's text, and finally the text following the <div>
.
You can change an element's level using the CSS display
property. Inline blocks, by changing the value of display
from "inline"
to "block"
, you can tell the browser to render the inline element in a block box rather than an inline box. It won't necessarily make the element render exactly as if it were originally an inline block, so be sure to take a look at the results.
In brief, here are the basic conceptual differences between inline and block-level elements:
The following elements are inline by default:
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/HTML/Inline_elements