How to create links to sections within the same page in HTML ? (original) (raw)
Last Updated : 30 Apr, 2025
**Creating links that allow users to jump to different sections of a **webpage can significantly **improve navigation. This is especially helpful for long pages with a lot of **content, as it helps users save time and find the information they need **more quickly.
**Syntax
<a>
: The anchor tag is used to define a hyperlink.href="#section1"
: Thehref
attribute specifies the target of the link. In this case, it points to a sectionid="section1"
on the same page.Section 1
: The clickable text that appears for the user. When clicked, it will scroll to the section withid="section1"
.
Approach
- **Use the Anchor Tag : In HTML, use the tag to create links within the same page.
- **Assign Unique IDs: Assign unique IDs to different sections of the webpage using the id attribute.
- **Set the href Attribute: Set the href attribute of the anchor tag to “#section1” (replace “section1” with the desired ID) to link to a specific section.
- **Avoid Using Class Names in href: Class names are not unique identifiers and should not be used in the href attribute for internal linking.
**Example: Below is an example where we divide the webpage into sections using
, assign unique IDs to each section, and use tags in the navigation section with href=”#section1″ to enable users to navigate to specific sections with a click.
HTML `