← Back to HTML Course | Chapter 9: Reference & Advanced | Lesson 3 of 9

HTML ग्लोबल एट्रिब्यूट्स

फ़र्ज़ करें आप कोई school चला रहे हैं। हर student की अपनी class (जैसे 'Class 5' या 'Class 6') के आधार पर unique properties होती हैं। लेकिन कुछ rules ऐसे भी होते हैं जो school के हर किसी पर लागू होते हैं, जैसे name badge पहनना, uniform पहनना, या school schedule follow करना। HTML global attributes वही universal rules हैं। ज़्यादातर HTML attributes सिर्फ specific tags पर काम करते हैं, लेकिन global attributes आपके webpage के किसी भी HTML element पर लगाए जा सकते हैं। इनकी मदद से आप IDs assign कर सकते हैं, styling classes लगा सकते हैं, tooltips लिख सकते हैं, या पूरे page पर element visibility को universally control कर सकते हैं।
Syntax
markup
<tagname id="value" class="value" style="value" title="value" hidden>content</tagname>

class और id एट्रिब्यूट्स

class attribute group styling के लिए कई elements को एक साथ जोड़ता है, जबकि id attribute page पर किसी एक specific element को एक पूरी तरह unique identifier देता है।

Note:
  • हर ID आपके पूरे HTML page structure में पूरी तरह unique होनी चाहिए।
  • Accepted attributes:
  • class — space-separated class names
  • id — unique identifier, no spaces
Warning: एक ही ID कई elements को assign करने से आपके JavaScript selectors टूट जाएंगे।

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

markup
<p class="highlight">Grouped</p>
<p id="intro">Unique</p>

style एट्रिब्यूट

style attribute किसी एक element पर सीधे inline CSS styles लागू करता है। इसकी specificity काफी ज़्यादा होती है, यानी यह external stylesheets के rules को override कर देता है।

Note:
  • quick testing के लिए inline styles का इस्तेमाल करें, लेकिन बड़े projects में कोड साफ रखने के लिए external stylesheets पर शिफ्ट करें।
  • Accepted values:
  • style — semicolon-separated CSS declarations, e.g. color: red; margin: 0
Warning: Inline styles आपके कोड को cluttered बना सकते हैं और site बढ़ने पर maintain करना मुश्किल कर सकते हैं।

उदाहरण: The style Attribute

markup
<p style="color: blue;">Inline styled text</p>

title एट्रिब्यूट

title attribute किसी element के बारे में कुछ अतिरिक्त जानकारी देता है। ज़्यादातर desktop browsers में, यह जानकारी element पर mouse hover करने पर एक छोटे tooltip के रूप में दिखती है।

Note:
  • title tooltips को छोटा और मददगार रखें।
  • Accepted values:
  • title — advisory text, usually shown as a tooltip
Warning: Mobile users hover नहीं कर सकते, इसलिए title attribute के अंदर critical instructions न डालें।

उदाहरण: The title Attribute

markup
<p title="Extra information">Hover over me</p>

lang और dir एट्रिब्यूट्स

lang attribute आपके content की भाषा बताता है, और dir attribute text की direction (ltr यानी left-to-right, या rtl यानी right-to-left) तय करता है, जो accessibility और search engine optimization दोनों के लिए ज़रूरी है।

Note:
  • अपने opening html tag के अंदर हमेशा page की primary language डिक्लेयर करें।
  • Accepted attributes:
  • lang — BCP 47 language code, e.g. en | fr | ar | zh-CN
  • dir — ltr | rtl | auto
Warning: सही language tags सेट न करने से screen readers आपका text गलत उच्चारण के साथ पढ़ सकते हैं।

उदाहरण: The lang and dir Attributes

markup
<html lang="ar" dir="rtl">
</html>

hidden और tabindex एट्रिब्यूट्स

hidden attribute किसी element को पूरी तरह page layout से छिपा देता है। tabindex attribute elements को page के keyboard tab navigation sequence में शामिल या बाहर रखता है।

Note:
  • custom, styled elements को keyboard से focusable बनाने के लिए tabindex="0" सेट करें।
  • Accepted attributes:
  • hidden — boolean | until-found
  • tabindex — 0 (focusable, in order) | -1 (focusable by script only) | positive integer (avoid)
Warning: 0 से बड़े tabindex values इस्तेमाल न करें, क्योंकि यह logical tab navigation flow को बिगाड़ सकता है।

उदाहरण: The hidden and tabindex Attributes

markup
<p hidden>You cannot see this</p>
<div tabindex="0">Focusable div</div>
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.