HTML
📌 HTML Div
General Definition
The <div> tag (short for "division") is commonly used in HTML to create a box, section, or container.
- It is a block-level element by default
- This means it starts on a new line and takes up the full width of its container
- It has no semantic meaning on its own (unlike tags such as
<header>or<footer>) - It is mainly used for layout, styling, and JavaScript control
Basic Features :
- It has no required attributes
- Most commonly used attributes :
- class
- id
- style
- It can contain both block-level and inline elements>
- With CSS, you can easily apply :
- width
- height
- background
- border
- padding
- margin
🧪 Example 1: Basic <div> Usage
HTML
<div style="background-color: lightyellow; padding: 10px;">
<h2>London</h2>
<p>London is the capital city of England.</p>
<p>London has over 9 million inhabitants.</p>
</div>
👉 In this example :
-
<div>acts as a container - Background color and padding create a box-like appearance
- The heading and paragraphs inside are neatly grouped
🛠️ Use Cases of
<div>- Web pages are usually divided into sections:
- header (top section)
- content (main area)
- sidebar (side section)
- footer (bottom section)
- 👉 These sections are often created using
<div>.
