BlogsDope image BlogsDope

HTML block-level and inline elements

Oct. 24, 2017 HTML CSS EXAMPLE 3545

HTML elements can be classified into two categories - block-level and inline elements. Let's have a look at both.

Block-level elements

A block-level element occupies the entire space of its parent element that is available to it. These are the ones which always start from a new line and covers the entire width available to them.

These can contain other block-level or inline elements. It accepts width and height values. The characteristics of block-level elements are demonstrated in the following example.

HTML

<p style="background-color: #A3D65C;">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer interdum mauris id volutpat dapibus. Mauris nec diam at metus sagittis luctus.</p>
<p style="background-color: #EC734A;">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer interdum mauris id volutpat dapibus. Mauris nec diam at metus sagittis luctus.</p>

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer interdum mauris id volutpat dapibus. Mauris nec diam at metus sagittis luctus.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer interdum mauris id volutpat dapibus. Mauris nec diam at metus sagittis luctus.

p is a block-level element and thus it always starts from a new line. Notice that both the elements cover the entire width available to them, as can be seen by the area covered by their background colors.

Following is a list of block-level elements.

pdiv, heading tags (h1h2, h3h4, h5h6), olul, preaddress, blockquote, fieldsetform, hr, table, dlnoscriptnavpre

Some other block-level elements which are newly added in HTML5 are given below.

articlefigureoutput, canvasheader, footer, section, asidehgroup, figcaption, video

Inline elements

An inline element only occupies the space that is necessary, and not the whole width. It may or may not start from a new line. It does not accept width and height values.

Look at the following example.

HTML

<p>There is an <span style="background-color: #A3D65C;">inline element</span> in this sentence.</p>

There is an inline element in this sentence.

span is an inline element and thus it only covers the space that is sufficient for its content. In the above example, the background color given to the span is just behind the content of the span and not covering the entire width.

Some of the examples of inline elements are given below.

a, b, big, ittsmallsmallabbracronym, codeciteemkbd, dfnstrongsamptimevarbdo, mapimgobjectbutton, supsubspan, qscriptinput, label, selecttextarea


Liked the post?
Inquisitive and passionate Front-end Developer and Web Designer and Co-Founder of CodesDope.
Editor's Picks
0 COMMENT

Please login to view or add comment(s).