<header> <img src="/static/imghw/default1.png" data-src="logo.png" class="lazy" alt="Stop Overusing Divs! A Practical Guide to Semantic HTML Best Practices"> <nav> <ul> <li><a href="/">Home</a></li> <li><a href="/about">About</a></li> </ul> </nav> </header> <main> <h2>About Us</h2> <p>Lorem ipsum...</p> <h2>How It Works</h2> <p>Lorem ipsum...</p> <aside>Sidebar content...</aside> </main> <footer> <p>Terms & Conditions</p> </footer>
<header>
: Contains the logo and primary navigation.<nav>
: Houses the main navigation links.<main>
: Encloses the primary content of the page.<h2>
and <p>
: Structure the main content logically.<aside>
: Represents secondary content, like a sidebar.<footer>
: Includes less crucial information, such as terms and conditions.<main> <h1>JavaScript Guide</h1> <p>Learn JavaScript...</p> <nav> <ul> <li><a href="#toc">Table of Contents</a></li> </ul> </nav> </main>
<main>
element clearly defines the core content. It's self-contained and reusable.<main>
section as it's crucial to the guide's usability.<div> <p>Why a div here? The info-bar groups unrelated elements (breadcrumbs and a button) purely for layout; they lack a shared semantic purpose.</p> <h2>Summary</h2> <p>Use semantic tags when:</p> <ul> <li>Content is related (<article>).</li> <li>It's self-contained (<article>).</li> <li>It's critical navigation (<nav>).</li> <li>It's secondary content (<aside>).</li> </ul> <p>Use divs when: You need a container solely for styling.</p> <p>If you found this helpful, please like and follow! Thanks for reading!</p> <p>Connect with me on:</p> <p><strong>LinkedIn</strong> | <strong>Medium</strong> | <strong>Bluesky</strong></p> </div>
The above is the detailed content of Stop Overusing Divs! A Practical Guide to Semantic HTML Best Practices. For more information, please follow other related articles on the PHP Chinese website!