Summary -

In this topic, we described about the <div> tag along with detailed example.

<div> is mostly used to create block-level elements. In other words, <div> tag used to define a section in HTML documents. Except <div>, all other have its own display.

The tag can be coded like <div></div> with its contents/other HTML tags inserted between the opening and closing tags. <div> also acts as block-level element that is used as container for other HTML elements. The <div> element has no additional attributes by default.

style and class are commonly provided with DIV element. When <div> element used together with CSS, the style blocks can be used together. All browsers always place a line break before and after the <div> tag by default.

Syntax -

<div>.....</div>

Example -

<!DOCTYPE html>
<html>
	<head>
		<title>div tag text example.. </title>
	</head>
	<body>
		<div style="background-color:green;">
			<h2>Heading</h2>
			<p>This is paragraph</p>
		</div> 
	</body>
</html>

Output -

Heading

This is paragraph