Working of ‹div› Tag in HTML

1.1 Introduction

The HTML ‹div› tag is used for defining a section of your document. With the div tag, you can group large sections of HTML elements together and format them with CSS.

The difference between the div tag and the span tag is that the div tag is used with blocklevel elements whilst the span tag is used with inline elements.

  • Div tag is Block level tag.
  • It is a generic container tag.
  • It is used to the group of various tags of HTML so that sections can be created and style can be applied to them.

1.2 Syntax

‹div attribute="property1:values;property2:values;"›Content‹/div›

‹div style="background-color:lightblue;width:100px;height:100px;"›Virtual Labs‹/div›

1.3 Attributes of ‹div› tag

Attribute Value Description
align left, right, center used to align the content inside a ‹div› tag. This attribute is not supported in HTML5.
CSS text-align property is used instead.

Note: The ‹div› tag also supports the Global attributes and the Event Attributes.