HTML Tutorial



HTML Div tag


HTML <div> Tag

The <div> tag is a block-level element that is used to group content together for styling or structuring purposes. It is one of the most commonly used elements in HTML and can help in organizing the layout of a webpage.


When to Use <div>?

Use <div> when you need to group multiple elements together and apply styling or JavaScript functions to them collectively. It does not have any semantic meaning on its own, but it’s useful for layout purposes.


Syntax

<div>
  <h2>Heading inside div</h2>
  <p>This is some content within the div element.</p>
</div>
  

Example

<!DOCTYPE html>
<html>
  <head>
    <title>Div Example</title>
  </head>
  <body>

    <div style="background-color: #f0f0f0; padding: 20px; border-radius: 6px;">
      <h2>Welcome to Our Website</h2>
      <p>Here, we use the div tag to group elements and apply style.

  

Best Practices

  • Use <div> primarily for styling and layout purposes
  • Don’t use <div> for purely semantic content; use other semantic tags like <header>, <footer>, or <article>
  • Group related content together to improve the structure of the webpage

Conclusion

The <div> tag is a flexible and essential element used for grouping content, making it easier to apply styles or JavaScript actions to multiple elements at once.


🌟 Enjoyed Learning with Us?

Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!

Leave a Google Review