Problem Statement
How do you create a link to a specific section on the same page?
Explanation
To create a link to a specific section on the same page, you use the anchor tag with href equals hash symbol followed by the ID of the target element. This is called a bookmark link or anchor link. For example, href equals hash section1 will jump to the element with id equals section1. The target element can be any HTML element with an ID attribute, such as a heading, div, or section tag. When users click the link, the page scrolls to bring that element into view. Bookmark links are useful for creating tables of contents, back to top buttons, or navigating long pages. They improve user experience by allowing quick navigation within a page.
Code Solution
SolutionRead Only
<!-- Link to section --> <a href="#about">Go to About Section</a> <a href="#contact">Go to Contact Section</a> <a href="#top">Back to Top</a> <!-- Target sections with IDs --> <section id="about"> <h2>About Us</h2> <p>Content here...</p> </section> <section id="contact"> <h2>Contact</h2> <p>Contact information...</p> </section> <div id="top"> <h1>Page Title</h1> </div>
