Kumail.pk is a Free Platform of

Create Div with HTML CSS

The div tag is known as Division tag. The div tag is used in HTML to make divisions of content in the web page like (text, images, header, footer, navigation bar, etc). Div tag has both open() and closing () tag and it is mandatory to close the tag. The Div is the most usable tag in web development because it helps us to separate out data in the web page and we can create a particular section for particular data or function in the web pages.

Create Div with HTML CSS

Create Div with HTML CSS

HTML <div> Tag

 

Example

A <div> section in a document that is styled with CSS:

<html>
<head>
<style>
.myDiv {
  border: 5px outset red;
  background-color: lightblue;
  text-align: center;
}
</style>
</head>
<body>

<div class=”myDiv”>
  <h2>This is a heading in a div element</h2>
  <p>This is some text in a div element.</p>
</div>

</body>
</html>
Try it Yourself »

More “Try it Yourself” examples below.


Definition and Usage

The <div> tag defines a division or a section in an HTML document.

The <div> tag is used as a container for HTML elements – which is then styled with CSS or manipulated with JavaScript.

The <div> tag is easily styled by using the class or id attribute.

Any sort of content can be put inside the <div> tag! 

Note: By default, browsers always place a line break before and after the <div> element.

Global Attributes

The <div> tag also supports the Global Attributes in HTML.


Event Attributes

The <div> tag also supports the Event Attributes in HTML.


Related Pages

HTML tutorial: HTML Block and Inline Elements

HTML tutorial: HTML Layout

HTML DOM reference: Div Object


Default CSS Settings

Most browsers will display the <div> element with the following default values:

Example

div {
  display: block;
}

About Us

Kumail.pk is a Free Platform of Education initiated by Syed Kumail Hassan Shah (Director GIT Education)

E-Certification