HTML Block Elements

Bookmark
Learn about different types of block tag elements like div, span.

HTML Tag elements can be classified into two broad categories namely block level elements and inline elements.

HTML Block Tag Elements

HTML block level tag elements have a predefined margin before and after it. Content enclosed by block level elements do not follow its previous element on the same line, but takes its own line. Similarly content that follows them appears on a new line. Following are some of the block level elements.

  • <p> - paragraph tag
  • <h1>, <h2> to <h6> - heading tags
  • <ul>, <ol>, <dl> - list tags
  • <pre> - pre tag
  • <hr> - horizontal separator line

Inline Tag Elements

Inline tag elements are opposite to the block level tag elements. Inline tags appear in sequence on the same line of display. Following are some of the example of inline tag elements.

  • <strong>, <b>, <i>, <u>, <big>, <small> - formatting tags
  • <em>, <cite>, <sup>, <sub> - formatting super and subscript tags
  • <ins>, <del> - formatting tags
  • <code>, <kbd>, <var> - code, keyboard input, variable tags.

HTML Group Elements

HTML tags can be grouped to create a layout and format it using CSS styles. We can do the grouping using <div> and <span> tags.

HTML Div Tag

<div> tag defines a division / section in a HTML document. Block level elements can be grouped by <div> tag and formatted using CSS.

<div style="color:#00FF00">
  <h3>First Group: </h3>
  <p>This is a paragraph 1.</p>
  <p>This is a paragraph 2.</p>
</div>
<div style="color:#FF0000">
  <h3>Second Group: </h3>
  <p>This is a paragraph 3.</p>
  <p>This is a paragraph 4.</p>
</div>

Example Output

First Group:

This is a paragraph 1.

This is a paragraph 2.

Second Group:

This is a paragraph 3.

This is a paragraph 4.

Three block level elements are grouped together and style is applied using div tag. We can create efficient HTML layouts using the div tag.

HTML Span Tag

<span> tag can be used to group inline tag elements. This does not create any division or sections. This just creating a group to apply CSS styles.

<p>Lion is a <span style="color:#0000FF"><strong>wild</strong> <u>animal</u></span>.</p>

Example Output

Lion is a wild animal.

In the above Span tag example, we have grouped couple of inline tags and applied a CSS style.

Exception Occured:

TypeErrorException
Messageerror_log(app.log): Failed to open stream: Permission denied
File/home/dh_czz6eb/tutorialwalk.com/common/error.php
Line36
Trace#0 (): log_error(2, 'error_log(app.log): Failed to open stream: Permission denied', '/home/dh_czz6eb/tutorialwalk.com/common/error.php', 36)
#1 /home/dh_czz6eb/tutorialwalk.com/common/error.php(36): error_log('21-12-2024 17:04:20 pm (IST),/home/dh_czz6eb/tutorialwalk.com/common/common.php,193,0,ErrorException,Optional parameter $per_page declared before required parameter $href is implicitly treated as a required parameter,/html/html-block-elements.html,#0 /home/dh_czz6eb/tutorialwalk.com/common/error.php(115): log_error(8192, 'Optional parame...', '/home/dh_czz6eb...', 193)
#1 [internal function]: check_for_fatal()
#2 {main}
', 3, 'app.log')
#2 /home/dh_czz6eb/tutorialwalk.com/common/error.php(8): log_exception(ErrorException)
#3 /home/dh_czz6eb/tutorialwalk.com/common/error.php(115): log_error(8192, 'Optional parameter $per_page declared before required parameter $href is implicitly treated as a required parameter', '/home/dh_czz6eb/tutorialwalk.com/common/common.php', 193)
#4 (): check_for_fatal()
REQUEST_URI/html/html-block-elements.html