HTML Div Tag

HTML Div Tag

The div tag defines some division in the HTML document. You can think of the div as a container holding some other HTML elements. It is used to group some content so that it can be easily styled. Other than this, it does not have any other special meaning.

Here is an example for understanding the div tag→

<!DOCTYPE html>
<html lang=”en”>
<meta charset=”UTF-8″>
<meta http-equiv=”X-UA-Compatible” content=”IE=edge”>
<meta name=”viewport” content=”width=device-width, initial-scale=1.0″>
<title>Some heading…</title>
<div>Hello… I am a div</div>
<div>Hello… I am another div</div>

If we try to open the file in the browser, we can find the output to be something like this –

As you can see, there are two containers here. The thing is that the div is a block element. Due to this, it is displayed with a newline before and after, and also it takes up the whole available horizontal space, and the vertical space according to the height of the content. You can explore more about the block-level elements.