← Back to HTML Course | Chapter 2: Text, Formatting & Media | Lesson 15 of 26

HTML Link Bookmarks

अगर किसी reader को manually scroll करके एक specific section ढूंढना पड़े, तो एक लंबा article या documentation page navigate करना मुश्किल हो सकता है। HTML bookmark links link के click होते ही page पर (या यहां तक कि किसी दूसरे page पर) एक specific point पर सीधे जाने देकर इस समस्या को हल करते हैं, destination marker के रूप में एक id attribute का उपयोग करके।
Syntax
markup
<a href="#id">Jump link</a>

<tagname id="id">Target element</tagname>

id से Destination Mark करना

किसी भी HTML element को एक unique id attribute देकर एक bookmark destination बनाया जा सकता है -- इसके लिए कोई special anchor tag ज़रूरी नहीं है; एक heading, एक div, या एक paragraph, ये सभी jump target का काम कर सकते हैं जब तक उनका id page पर unique हो।

Note: major sections को generic ids (जैसे id="section3") के बजाय descriptive, readable ids (जैसे id="pricing") दें, ताकि maintain करना आसान रहे।
Warning: page पर हर id value unique होनी चाहिए; दो elements पर एक ही id reuse करने से bookmark navigation अप्रत्याशित रूप से व्यवहार करता है।

उदाहरण: Marking a Destination with id

markup
<h2 id="pricing">Pricing</h2>

उसी Page पर किसी Destination से Link करना

कोई link अपने href को # symbol और target id के साथ सेट करके current page पर किसी destination पर jump करता है -- href="#pricing" ब्राउज़र को सीधे id="pricing" वाले element पर scroll कराता है, बिना कभी current page छोड़े या reload किए।

Note: लंबे articles के ऊपर एक "table of contents" में यही same-page bookmark links जोड़ें ताकि readers सीधे किसी section पर jump कर सकें।
Warning: id से पहले # छोड़ देने से href एक बिल्कुल अलग page के लिए request बन जाता है जिसका नाम id के नाम पर होता है, जो 404 देगा।

उदाहरण: Linking to a Destination on the Same Page

markup
<a href="#pricing">Jump to Pricing</a>
<h2 id="pricing">Pricing</h2>

किसी दूसरे Page पर Destination से Link करना

एक bookmark link एक normal file path या URL को #id fragment के साथ combine करके पूरी तरह अलग page के किसी section की ओर भी इशारा कर सकता है -- href="article.html#conclusion" article.html लोड करता है और फिर तुरंत id="conclusion" वाले element पर scroll करता है।

Note: Cross-page bookmark links किसी बाहरी site से सीधे किसी specific FAQ answer या documentation heading से link करने के लिए खासतौर पर उपयोगी हैं।
Warning: अगर target id destination page पर मौजूद नहीं है, तो browser बिना कोई error दिखाए, बस page को normally top पर load कर देता है।

उदाहरण: Linking to a Destination on Another Page

markup
<a href="article.html#conclusion">Read the conclusion</a>

Bookmarks के लिए Smooth Scrolling

By default, bookmark navigation बिना किसी animation के तुरंत destination पर snap हो जाता है।

html element में scroll-behavior: smooth जोड़ने से ब्राउज़र इसके बजाय scroll को smoothly animate करता है, जिससे readers को teleport होने के बजाय page में आगे बढ़ने का स्पष्ट एहसास होता है।

Note: individual links पर नहीं, बल्कि html selector पर एक बार globally scroll-behavior: smooth apply करें, ताकि सभी bookmark jumps consistently animate हों।
Warning: बहुत बड़े scroll distance वाले बहुत लंबे pages पर smooth scrolling sluggish महसूस हो सकती है, इसलिए अपने actual content की length पर perceived speed को test करें।

उदाहरण: Smooth Scrolling to Bookmarks

markup
<style>
  html {
    scroll-behavior: smooth;
  }
</style>
<a href="#pricing">Jump to Pricing</a>
<h2 id="pricing">Pricing</h2>

Bookmarks को Navigation Menus के साथ Combine करना

Bookmark links को अक्सर page के ऊपर एक sticky navigation menu में combine किया जाता है, जिससे visitors पूरा page reload trigger किए बिना major sections (जैसे Home, Features, Pricing, Contact) के बीच jump कर सकते हैं, जो browsing experience को तेज़ और app-like बनाए रखता है।

Note: एक ज़्यादा polished single-page navigation feel के लिए scroll position सुनने वाले JavaScript का उपयोग करके current section के nav link को active highlight करें।
Warning: एक sticky nav bar bookmark jump के ठीक बाद किसी section के top को visually cover कर सकती है; इसकी भरपाई के लिए section पर scroll-margin-top के साथ जोड़ें।

उदाहरण: Combining Bookmarks with Navigation Menus

markup
<nav>
  <a href="#home">Home</a>
  <a href="#features">Features</a>
  <a href="#pricing">Pricing</a>
</nav>
Live Example
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.