Performance: Linking to sections using IDs
This affects page load speed slightly by enabling quick navigation and impacts visual stability during jumps.
<a href="#section1" aria-label="Go to Section 1">Go to Section 1</a> ... <section id="section1" style="min-height: 20rem;">Content</section>
<a href="#section1">Go to Section 1</a> ... <section id="section1">Content</section>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Linking to ID without reserved space | Minimal | Multiple if content resizes after scroll | Medium due to repaint after shift | [X] Bad |
| Linking to ID with reserved space | Minimal | Single reflow on load | Low paint cost | [OK] Good |
id attribute in HTML when linking to sections?id attributeid attribute uniquely identifies an element on the page.idhref="#id" jump directly to the element with that id.id marks section for linking [OK]id to name sections for direct links [OK]id changes style automaticallyid with classid creates new pagesid="contact"?idhref="#id" where id is the target's identifier.<a href="#contact">Contact</a> uses href="#contact", which is correct. Others miss the # or use wrong attributes.<a href="#about">About Us</a> ... <section id="about"> <h2>About Our Company</h2> <p>We build websites.</p> </section>
href="#about", which targets the element with id="about".id, showing the 'About Our Company' section.<a href="#services">Our Services</a> ... <section id="service"> <h2>Services Offered</h2> </section>
href="#services" but the section has id="service" (missing 's').href must exactly match the target element's id.id in the section does not match the href value. -> Option Dhref="#home", href="#about", and href="#contact" which is correct syntax to link to IDs.id="home", id="about", and id="contact" exactly matching the href targets.Pass the test and this pattern moves unknown