What Is The HTML <div> Tag?

What Is The HTML Div Tag

Date First Published: 27th February 2023

Topic: Web Design & Development

Subtopic: Web Development

Article Type: Computer Terms & Definitions

Difficulty: Medium

Difficulty Level: 5/10

Learn more about what the HTML <div> tag is in this article.

In HTML, the <div> tag is used to define a division in a document. This tag separates and groups data in a webpage, such as text, images, videos, headers, footers, and other types of content, and is used as a container for HTML elements. The <div> tag can then be styled by specifying a name on the class id or name attribute and then using CSS to apply the style to an element with that name or id. It can also be manipulated using client-side scripting, such as JavaScript and server-side scripting, such as PHP. This tag is supported by all major web browsers.

This tag is a non-semantic tag. Even though it is useful for styling and formatting webpages, it tells nothing about the purpose of the content. Website owners use id and class attributes to specify the meaning of the non-semantic elements and semantic tags, such as <article> and <footer> were introduced in HTML5. What these semantic tags define is very obvious.

Note: Info Icon

Browsers automatically place a line break before and after the <div> element as <div> is a block-level element.


Note: Info Icon

The <div> element cannot be placed within a <p> tag as this will cause the paragraph to break.

Example Of The <div> Tag

An example of the <div> tag that is styled with CSS along with the output can be seen below:

<html> <head> <style> .container { border: 5px outset red; background-color: lightblue; text-align: center; } </style> </head> <body> <div class="container"> <h1>Main heading</h2> <h2>Second heading</h2> <p>Text</p> </div> </body> </html>

Output:

HTML Div Tag Output

Attributes

The <div> tag only contains one attribute that has been deprecated.

Attribute Description
Align Used to align the content in a div tag. Not supported in HTM5. Instead, the CSS text-align property should be used for alignment.


Feedback

  • Is there anything that you disagree with on this page?
  • Are there any spelling, grammatical, or punctuation errors on this page?
  • Are there any broken links or design errors on this page?

If so, it is important that you tell me as soon as possible on this page.


Comments