In HTML, you can create bookmarks or anchor links that allow users to jump to specific sections of a web page. To create a bookmark, you need to use the id
attribute to give the section a unique identifier, and then create a link to that identifier using the href
attribute.
Here’s an example:
<h2 id="section1">Section 1</h2>
<p>This is the content of section 1.</p>
<h2 id="section2">Section 2</h2>
<p>This is the content of section 2.</p>
<a href="#section1">Jump to Section 1</a>
<a href="#section2">Jump to Section 2</a>
In this example, we have created two sections with unique identifiers using the id
attribute. We then created two links that use the href
attribute to point to the section identifiers. When the user clicks on one of the links, the browser will scroll to the corresponding section of the page.
Note that the id
attribute must be unique within the web page. If you have multiple elements with the same id
, the bookmarks will not work correctly.
You can also use bookmarks to create a table of contents for your web page. Simply create links to each section of the page and format them as a list:
<h1>My Web Page</h1>
<ul>
<li><a href="#section1">Section 1</a></li>
<li><a href="#section2">Section 2</a></li>
</ul>
<h2 id="section1">Section 1</h2>
<p>This is the content of section 1.</p>
<h2 id="section2">Section 2</h2>
<p>This is the content of section 2.</p>
In this example, we have created a table of contents as an unordered list, with links to each section of the page. When the user clicks on one of the links, the browser will scroll to the corresponding section of the page.