📌 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
  1. Basic Features :

  2. It has no required attributes
  3. Most commonly used attributes :
  4. class
  5. id
  6. style
  7. It can contain both block-level and inline elements>
  8. With CSS, you can easily apply :
  9. width
  10. height
  11. background
  12. border
  13. padding
  14. 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>
                
  1. 👉 In this example :

  2. <div> acts as a container
  3. Background color and padding create a box-like appearance
  4. 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>.