Home Python C Language C ++ HTML 5 CSS Javascript Java Kotlin SQL DJango Bootstrap React.js R C# PHP ASP.Net Numpy Dart Pandas Digital Marketing

Anchor Links and Bookmarks


Anchor links, also known as bookmarks, are used in HTML to navigate to specific sections within the same webpage or to other sections of a website. They are particularly useful for lengthy pages where quick navigation between sections improves user experience. Anchor links are created using the <a> tag with href attributes that target specific id attributes within the page.

Creating Anchor Links

To create an anchor link, you need two parts:

  1. A target element with an id attribute, which acts as the destination for the link.
  2. An <a> tag with an href attribute pointing to the target id.

Here is a basic example:

In this example, clicking the "Go to Section 1" link will scroll the page to the element with id="section1".

Using Anchor Links for Page Navigation

Anchor links are often used to create navigation menus that quickly move to different sections on a page. Here’s an example of a simple navigation menu using anchor links:

This code creates links that jump to specific sections on the same page. The id attributes act as bookmarks, and the href values point to them.

Creating Bookmarks for External Links

You can link to a specific section on another page by using the URL of that page followed by #id of the target section. For example:

This link will open page.html on example.com and scroll to the section with id="section2" if it exists on that page.

Smooth Scrolling

Modern browsers often support smooth scrolling behavior for anchor links by default, but you can also enable smooth scrolling with CSS:

With this CSS, the page will smoothly scroll to the anchor link’s target location.

Best Practices for Using Anchor Links and Bookmarks

Conclusion

Anchor links and bookmarks in HTML allow for smooth navigation within a single page or between pages, creating a better user experience, especially for long or complex web pages. By using the <a> tag with href attributes linked to id attributes, you can create efficient navigation paths, enhancing readability and accessibility for users.



Advertisement





Q3 Schools : India


Online Complier

HTML 5

Python

java

C++

C

JavaScript

Website Development

HTML

CSS

JavaScript

Python

SQL

Campus Learning

C

C#

java