What are DIV tags? (23 characters)

Print anything with Printful



DIV tags define sections in HTML documents without applying meaning to content. They indicate a block of code belongs together and can be used with other code to apply attributes. DIV tags should not substitute for P tags and should be used judiciously to avoid confusion.

DIV tags are codes that define a section in a HyperText Markup Language (HTML) document. A section in HTML can also be described as a “division”, which is the origin of the abbreviation used for the DIV tag name.

DIV tags, like SPAN tags, do not apply meaning to content as is the case with most HTML. For example, “P” creates a paragraph, “B” creates a bold, and “H” creates a heading. DIV doesn’t actually do anything by itself; it simply defines a block of content on the page to which other attributes can be globally applied. DIV tags indicate that a block of code belongs together.

A leading DIV tag specifies that “this section of code starts here” and the trailing DIV tag states “this section of code ends here”. Defining sections of a web page into clearly delineated sections makes it much easier to manage and manipulate your code. DIV tags can be used in conjunction with other code, such as STYLE code, to apply an attribute to an entire section. For example:

***
This is black text, preceding the following section of the burgundy text DIV tag.

This is a paragraph in this div section, which will not only appear in burgundy text, but also in bold text.

This is another black text, which appears after the burgundy text section.
***

Another common use of the DIV tag is to align entire blocks of content on a web page to the left, right, or center of the page. Besides “align”, other frequently used attributes assigned by a DIV tag are: id, class, title, style, dir and lang. For novice web page authors, it’s important to remember that the DIV tag should not be used as a substitute for the P (paragraph) tag. The P tag should only be used for individual paragraphs, while the DIV tag should be used to define larger, more general sections or divisions of a document.
DIV tags can be nested, which means you can have a starting and ending set of DIV tags inside another set. Care must be taken to ensure that any encoding you add is placed within the correct set of DIV tags. It’s also important to note that web browsers usually insert a line break before and after a DIV element when viewing a web page containing it. This must be taken into consideration when designing the surrounding code.
Experienced website authors recommend judicious use of the DIV tag when coding HTML, otherwise it tends to cause you to lose what the tag was meant to create: clarity. Care must be taken not to let “divitis,” as experienced programmers call the excessive use of DIV tags, confuse and overcomplicate web page coding.




Protect your devices with Threat Protection by NordVPN


Skip to content