Understanding Divs and Spans in HTML
Divs:
Divs, or division elements, are used in HTML to group together other elements, creating a division or a section in the document. They are commonly used for structuring and organizing content on a webpage.
Spans:
Spans are inline-level elements used for applying styles to specific parts of the text without affecting the entire block. They are often used for inline styling or wrapping inline elements.
Practical Example:
Let's consider a simple webpage with a header, main content, and footer sections. We can use divs to separate and structure these sections:
<div id="header">
<h1>Welcome to My Website</h1>
</div>
<div id="main-content">
<p>This is the main content of my webpage.</p>
</div>
<div id="footer">
<p>© 2024 My Website. All rights reserved.</p>
</div>
This structure helps organize the webpage's content and enhances its readability for both users and search engines.