How to use class In HTML
We can use class on that particular div and apply CSS either inside a <style> tag or linking an external CSS file.
Example : This is the example with respect to above approach by using class.
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="color.css">
<title>
HTML Div Tag
</title>
</head>
<body>
<center>
<div class="color">
<!--open tag of Div!-->
<caption>
<h1>w3wiki</h1>
</caption>
<h1>Inline CSS is not USED in THIS method.
</h1>
</div>
<!--closing tag of Div!-->
</center>
</body>
</html>
.color {
height: 400px;
width: 600px;
border: 1px solid;
background-color: 009900;
}
Output:
HTML Div Tag
The HTML <div> tag defines sections in HTML documents, serving as containers styled with CSS or controlled with JavaScript. It’s easily customized using class or id attributes and can contain various content.
Note: Browsers add line breaks before and after <div> elements by default.