In HTML, you can create bookmarks or anchor links that allow users to navigate to specific sections within the same page. By using the id
attribute to mark the target section and adding an anchor link with the href
attribute set to the corresponding id
, you can create bookmarks. Here’s how you can create bookmarks in HTML:
- Create a Target Section:
Assign anid
attribute to the section you want to create a bookmark for.
Example:
<h2 id="section1">Section 1</h2>
<p>This is the content of section 1.</p>
- Create an Anchor Link:
Create a link with thehref
attribute set to#
followed by theid
value of the target section.
Example:
<a href="#section1">Go to Section 1</a>
The href
value #section1
corresponds to the id
attribute value of the target section. When users click the link, the browser will scroll to the section with the specified id
on the same page.
You can create multiple bookmarks and anchor links within the same page by following the same pattern. Just make sure that the id
values and the href
values match.
Here’s a complete example with multiple sections and bookmarks:
<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>
<h2 id="section3">Section 3</h2>
<p>This is the content of section 3.</p>
<a href="#section1">Go to Section 1</a>
<a href="#section2">Go to Section 2</a>
<a href="#section3">Go to Section 3</a>
When users click on the “Go to Section X” links, the browser will scroll to the respective sections on the same page.
Using bookmarks or anchor links within a page can be helpful for long content, table of contents, or creating navigation within a single-page website.