← Back to HTML Course | Chapter 1: Introduction & Basics | Lesson 5 of 11

HTML Attributes

कल्पना कीजिए अमित एक parcel दिल्ली से मुज़फ्फरपुर भेज रहा है। parcel खुद आपका HTML tag है। लेकिन address, weight, और delivery instructions वाला shipping label? वे attributes हैं। Attributes आपके opening HTML tag के अंदर रहते हैं और browser को वे जरूरी extra details देते हैं। इनके बिना, आपके tags बस खाली boxes हैं जो post office में इंतजार कर रहे हैं। इन्हें उस खास अदरक और इलायची की तरह सोचें जो प्रिया अपनी रोज़ की chai में डालती है ताकि उसमें extra kick आए।
Syntax
markup
<tagname attribute="value">content</tagname>

href Attribute

यह attribute आपके link को बताता है कि उसे बिल्कुल कहां जाना है। यह वैसा ही है जैसे Rahul किसी Patna auto-driver को अपनी destination बता रहा हो ताकि वह गलत कॉलोनी में न पहुंच जाए।

href attribute भूल जाना anchor tag को एक dead link बना देता है जो click करने पर कुछ नहीं करता।

Note:
  • external sites को link करते समय हमेशा https से शुरू होने वाला secure address उपयोग करें।
  • Accepted attributes:
  • href — absolute URL | relative path | #fragment | mailto:address | tel:number
  • a, area और link elements पर valid
  • target — _self | _blank | _parent | _top
  • rel — noopener | noreferrer | nofollow ...
Warning: अगर आप इसे खाली छोड़ देंगे, तो आपके users एक broken page पर फंस जाएंगे।

उदाहरण: The href Attribute

markup
<a href="https://example.com">Visit our site</a>

src Attribute

Images जादुई रूप से screen पर नहीं आ सकतीं। src attribute एक home address की तरह काम करता है, जो ब्राउज़र को बताता है कि image file असल में कहां रखी है। एक broken src path लाइव साइट पर images के display न होने का सबसे आम कारणों में से एक है।

Note:
  • अपने project को व्यवस्थित रखने के लिए सभी images को assets नाम के एक folder में रखें।
  • Accepted attributes:
  • src — resource का URL (absolute या relative path)
  • img, script, iframe, video, audio, source, track, embed और input type=image पर valid
  • srcset — width (w) या density (x) descriptors के साथ comma-separated image URLs की list
Warning: आपके image path में एक छोटी सी spelling की गलती एक broken image icon दिखाएगी।

उदाहरण: The src Attribute

markup
<img src="images/photo.jpg">

alt Attribute

कभी-कभी Muzaffarpur में internet साथ नहीं देता, या कोई screen reader Priya को page पढ़ने में मदद कर रहा होता है। alt attribute image लोड न होने पर एक text backup देता है।

Alt text SEO के लिए भी मायने रखता है, क्योंकि search engines किसी image को 'देख' नहीं सकते और उसके content को समझने के लिए इस text पर निर्भर रहते हैं।

Note:
  • banner जैसे सामान्य शब्दों के बजाय छोटे, मददगार descriptions लिखें।
  • Accepted attributes:
  • alt — image का वर्णन करने वाला छोटा text
  • alt="" — empty value एक विशुद्ध decorative image दर्शाता है
  • img, area और input type=image पर valid
Warning: इस attribute को छोड़ देने से आपकी website visually impaired visitors के लिए उपयोग करना मुश्किल हो जाता है।

उदाहरण: The alt Attribute

markup
<img src="photo.jpg" alt="A red bicycle leaning against a wall">

title Attribute

किसी के mouse hover करने पर एक छोटा tooltip दिखाना चाहते हैं? title attribute वैसा ही है जैसे Amit user के कान में एक छोटा सा hint फुसफुसा रहा हो।

जरूरी जानकारी के लिए title attribute का अत्यधिक उपयोग करना एक बुरा विचार है, क्योंकि यह hover के बिना touch devices पर अदृश्य रहता है।

Note:
  • इस text को संक्षिप्त और सीधा रखें।
  • Accepted values:
  • title — कोई भी advisory text, आमतौर पर hover पर tooltip के रूप में दिखता है
  • Global attribute: हर element पर valid
  • alt या visible label का विकल्प नहीं है
Warning: Mobile users hover नहीं कर सकते, इसलिए इस attribute के अंदर जरूरी instructions न डालें।

उदाहरण: The title Attribute

markup
<p title="Hover to see this tooltip">Hover over this text</p>

Global Attributes: class और id

class और id लगभग हर HTML element पर उपलब्ध global attributes हैं -- class कई elements को एक ही styling या behavior share करने के लिए group करता है, जबकि id page पर बिल्कुल एक element को CSS, JavaScript, या in-page links के लिए uniquely identify करता है।

Note:
  • Accepted attributes:
  • class — class names की space-separated list
  • id — document के अंदर unique identifier (कोई spaces नहीं)
  • दोनों global attributes हैं जो हर element पर valid हैं

उदाहरण: Global Attributes: class and id

markup
<p class="highlight">First paragraph</p>
<p class="highlight">Second paragraph</p>
<p id="intro">Unique paragraph</p>
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. #}
🔒

Chapter Quiz — Complete all 11 topics to unlock

0/11 topics done

Complete these topics first:

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.