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

HTML Link Colors

Default रूप से, browsers links को blue color देते हैं और visited होने पर उन्हें purple कर देते हैं, यह एक convention है जो web के शुरुआती दिनों से चली आ रही है। Link pseudo-classes आपको उन defaults को override करने देती हैं और link के life cycle के हर stage को अलग-अलग style करने देती हैं: इसकी resting state, mouse का उस पर hover करना, click होने का पल, और क्या यह पहले visited हो चुका है।
Syntax
markup
<style>
  a:link { color: colorvalue; }
  a:visited { color: colorvalue; }
  a:hover { color: colorvalue; }
  a:active { color: colorvalue; }
</style>

Default Unvisited Link

:link pseudo-class उस anchor element को target करता है जिसे user ने अभी तक visit नहीं किया है, और यह वह state है जिसमें ज़्यादातर links default रूप से होते हैं।

anchor tag को सीधे style करने के बजाय :link का उपयोग करने से आप सिर्फ unvisited links को visited links से अलग target कर सकते हैं।

Note: :link को plain a selector जैसा ही style करें, जब तक आप specifically यह न चाहें कि unvisited links visited links से अलग दिखें।
Warning: :link केवल href attribute वाले anchors पर लागू होता है; scroll target के रूप में उपयोग होने वाले plain anchor tag की कोई link state नहीं होती जिसे style किया जा सके।

उदाहरण: The Default Unvisited Link

In this preview, the link hasn't been visited, so it renders in the color set by a:link (blue by default) until it's clicked.

markup
<style>
  a:link {
    color: blue;
  }
</style>
<a href="page.html">Unvisited link</a>

Visited Links को Mark करना

:visited उन links को target करता है जिन्हें ब्राउज़र पहचानता है कि user पहले click कर चुका है, जिससे आप "read" links को "unread" वालों से अलग कर सकते हैं, आमतौर पर visited search results या wiki links को gray out करने के लिए उपयोग होता है।

Note: :visited links के लिए थोड़ा muted color उपयोग करें ताकि users एक नज़र में बता सकें कि वे कौन से pages पहले ही explore कर चुके हैं।
Warning: Browsers जानबूझकर :visited को color जैसी कुछ safe properties तक सीमित रखते हैं, ताकि कोई page किसी user की browsing history को जांच न सके।

उदाहरण: Marking Visited Links

This purple color only appears after a link has actually been clicked and visited — in a fresh preview like this one, the link still shows its unvisited (:link) color until you click it.

markup
<style>
  a:visited {
    color: purple;
  }
</style>
<a href="page.html">Visited link</a>

Hover पर Highlight करना

:hover उस पल styles apply करता है जब mouse pointer किसी link के ऊपर जाता है, और pointer के हटते ही यह गायब हो जाता है, जिससे users को click करने से पहले ही तुरंत visual feedback मिलता है कि कोई element interactive है।

Note: hover transitions को छोटा (100-200ms) रखें ताकि color बदलाव सुस्त की बजाय responsive महसूस हो।
Warning: :hover का touchscreens पर कोई equivalent effect नहीं होता, क्योंकि hover करने के लिए कोई mouse pointer नहीं होता, इसलिए कभी भी सिर्फ इस पर भरोसा न करें critical information बताने के लिए।

उदाहरण: Highlighting on Hover

markup
<style>
  a:hover {
    color: red;
  }
</style>
<a href="page.html">Hover over me</a>

Active Click Moment को Style करना

:active सिर्फ उस छोटे पल के दौरान apply होता है जब किसी link को actively दबाया जा रहा होता है, mouse-down और mouse-up के बीच, जो एक physical button की तरह ही यह tactile visual feedback देता है कि click register हो गया।

Note: :active को :hover से काफी अलग, ज़्यादा punchy color दें ताकि users को एक स्पष्ट "click confirmed" वाला moment महसूस हो।
Warning: Touchscreens पर, :active अक्सर सिर्फ बहुत संक्षेप में flash होता है, इसलिए इसकी styling को ऐसी information न दें जिसे पढ़ने के लिए users को समय चाहिए।

उदाहरण: Styling the Active Click Moment

markup
<style>
  a:active {
    color: orange;
  }
</style>
<a href="page.html">Click and hold me</a>

Custom Link Themes

चारों pseudo-classes को combine करके आप एक पूरी तरह custom link theme बना सकते हैं जो ब्राउज़र की default blue-purple scheme पर निर्भर रहने के बजाय आपकी site के design से मेल खाती है, और साथ ही users की अपेक्षित underlying behavioral feedback को भी बनाए रखती है।

Note: colors को पूरी तरह customize करते समय भी, accessibility के लिए links और plain text के बीच (जैसे underline) कोई visual अंतर बनाए रखें।
Warning: एक custom link theme जो surrounding text से सारे color और underline differences हटा देती है, links को users के लिए effectively invisible बना सकती है।

उदाहरण: Custom Link Themes

markup
<style>
  a:link { color: teal; }
  a:visited { color: gray; }
  a:hover { color: coral; }
  a:active { color: darkred; }
</style>
<a href="page.html">Themed link</a>
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.