Div Tag in HTML
1. Div Tag (<div>
)
The <div>
tag is a block-level container used to group content. It is primarily used for structuring a webpage and applying styles or scripts to multiple elements as a single unit.
Attributes:
id
: Assigns a unique identifier to the<div>
for styling or scripting.class
: Groups multiple<div>
elements under a shared class for styling.style
: Inline styling for the<div>
element.
Example:
<div id="main-container" class="content-box" style="background-color: lightblue; padding: 20px;">
<h1>Welcome to My Website</h1>
<p>This is a paragraph inside a div container.</p>
</div>
Explanation:
- The
id="main-container"
uniquely identifies this<div>
. - The
class="content-box"
allows shared styles with other elements. - The
style
attribute applies inline CSS (e.g., background color and padding).
Comments
Post a Comment