Introduction
Linking to sections using IDs helps users jump directly to important parts of a webpage quickly and easily.
<a href="#sectionID">Link text</a> ... <section id="sectionID">Content here</section>
id attribute must be unique on the page.href uses a hash (#) followed by the exact id value.<a href="#about">About Us</a> ... <section id="about"> <h2>About Us</h2> <p>Information about our company.</p> </section>
<nav> <a href="#contact">Contact</a> <a href="#services">Services</a> </nav> <section id="services"> <h2>Our Services</h2> </section> <section id="contact"> <h2>Contact Us</h2> </section>
tabindex="-1" to allow keyboard focus after jumping.<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Linking to Sections Example</title> <style> body { font-family: Arial, sans-serif; line-height: 1.5; padding: 1rem; } nav { background-color: #f0f0f0; padding: 1rem; margin-bottom: 2rem; border-radius: 0.5rem; } nav a { margin-right: 1.5rem; color: #0066cc; text-decoration: none; font-weight: 600; } nav a:hover, nav a:focus { text-decoration: underline; outline: none; } section { margin-bottom: 3rem; } h2 { color: #333; } </style> </head> <body> <nav aria-label="Main navigation"> <a href="#intro">Introduction</a> <a href="#features">Features</a> <a href="#contact">Contact</a> </nav> <section id="intro" tabindex="-1"> <h2>Introduction</h2> <p>Welcome to our website. Use the links above to jump to different sections.</p> </section> <section id="features" tabindex="-1"> <h2>Features</h2> <ul> <li>Easy navigation</li> <li>Fast access to content</li> <li>Improved user experience</li> </ul> </section> <section id="contact" tabindex="-1"> <h2>Contact</h2> <p>You can reach us at <a href="mailto:info@example.com">info@example.com</a>.</p> </section> </body> </html>
tabindex="-1" to sections helps keyboard users focus on the section after jumping.id attribute to mark sections you want to link to.<a href="#id"> to create links that jump to those sections.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