← Back to HTML Course | Chapter 4: Semantics & Entities | Lesson 1 of 10

HTML Semantics

सोचिए आप किसी supermarket में जा रहे हैं जहां हर item एक plain white box में बिना किसी label के packed है। दूध या cereal ढूंढने के लिए आपको हर एक box खोलना पड़ेगा। Semantic HTML आपके page content को स्पष्ट रूप से label करके इसे हल करता है। सब कुछ div tags जैसे generic boxes में wrap करने के बजाय, आप semantic tags का उपयोग करते हैं जो browser, search engines, और screen readers को बताते हैं कि वह content ठीक-ठीक किस काम के लिए है। अपने layout components को label करके, आप अपनी website को accessible, Google पर index करने में आसान, और दूसरे developers के लिए बेहद organized बनाते हैं।
Syntax
markup
<header>...</header>
<nav>...</nav>
<main>
  <article>...</article>
  <section>...</section>
</main>
<footer>...</footer>

Semantic बनाम Non-Semantic Elements

Non-semantic elements (जैसे div और span) अपने content के बारे में कोई अर्थ नहीं बताते। Semantic elements (जैसे header, article, और footer) browsers और developers दोनों को अपना अर्थ स्पष्ट रूप से बताते हैं।

Note: styling या grouping के लिए ही generic div elements इस्तेमाल करें, और असली content structure define करने के लिए semantic tags इस्तेमाल करें।
Warning: semantic tags की जगह plain div tags का ज्यादा उपयोग आपकी search engine ranking और website accessibility score को नुकसान पहुंचाता है।

उदाहरण: Semantic vs. Non-Semantic Elements

markup
<div>Generic container, no meaning</div>
<header>Semantic container, describes its role</header>

section और article से Content को Section में बांटना

section tag content की एक thematic grouping define करता है, आमतौर पर एक heading के साथ। article tag पूरी तरह independent, self-contained content का एक टुकड़ा represent करता है जिसे दूसरी sites पर भी distribute किया जा सकता है।

Note: अगर किसी content को newsletter या social media पर share किया जा सकता है और वह अकेले भी पूरा अर्थ रखता है, तो उसे article tag में wrap करें।
Warning: section tags का उपयोग सिर्फ visual CSS styling के लिए न करें; non-content boxes के लिए standard div tags का उपयोग करें।

उदाहरण: Sectioning Content with section and article

markup
<article>
  <section>Standalone blog post content</section>
</article>

Navigation और Headers

nav element खासतौर पर मुख्य navigation menus के लिए reserved है। अपने header और nav elements को जोड़ने से एक स्पष्ट layout hierarchy बनती है जिसे screen readers तुरंत parse कर सकते हैं।

Note: अपनी site की मुख्य menus nav elements के अंदर रखें, लेकिन secondary footer terms of service routes को standard lists में ही छोड़ें।
Warning: अपने page के हर single link को nav elements में wrap न करें, क्योंकि इससे screen reader की efficiency घट जाती है।

उदाहरण: Navigation and Headers

markup
<header>
  <nav>Main site navigation</nav>
</header>

Footers और Sidebars

footer element आपके page या section के closing section को define करता है, जिसमें meta information होती है। aside tag उस content को wrap करता है जो main page flow से थोड़ा-बहुत related है, जैसे advertisements या sidebars।

Note: trending tools या quick instructional tips दिखाने वाली sidebars के लिए aside containers इस्तेमाल करें।
Warning: सुनिश्चित करें कि aside elements में critical page-flow actions न हों, क्योंकि screen-reader users उन्हें bypass कर सकते हैं।

उदाहरण: Footers and Sidebars

markup
<footer>Contact info</footer>
<aside>Related links</aside>

Inline Text Semantics

Semantic layout सिर्फ बड़े structural columns के बारे में नहीं है। time (machine-readable dates के लिए) और mark (search query highlighters के लिए) जैसे inline text tags आपके शब्दों में समृद्ध context जोड़ते हैं।

Note: अपने time tag में हमेशा datetime attribute तय करें, ताकि search crawlers आपकी publication dates को सही तरीके से पढ़ सकें।
Warning: मनमाने numbers या non-date texts के लिए time tags का उपयोग न करें, क्योंकि इससे page index validation खराब हो जाता है।

उदाहरण: Inline Text Semantics

markup
<p>Posted <time datetime="2024-01-15">January 15</time>, results for <mark>HTML</mark>.</p>

Article बनाम Section बनाम Div

यह HTML semantics के सबसे उलझाने वाले हिस्सों में से एक है। Article उस self-contained content के लिए है जो अकेले भी अर्थपूर्ण हो, जैसे कोई blog post। Section content की thematic grouping के लिए है। Div बिना किसी semantic अर्थ वाले layout के लिए है।

Note:
  • खुद से पूछें: अगर इस content को दूसरी website पर कॉपी किया जाए, तो क्या यह फिर भी अर्थ रखेगा?
  • अगर हाँ, तो article इस्तेमाल करें।
  • अगर नहीं, तो section या div इस्तेमाल करें।
Warning: हर चीज़ के लिए div का उपयोग करना आपके HTML को screen readers और search engines के लिए समझना नामुमकिन बना देता है।

उदाहरण: Article vs Section vs Div

markup
<article>Self-contained blog post</article>
<section>Thematic grouping of related content</section>
<div>Generic layout wrapper</div>

main Element

main element page के एक ही, केंद्रीय content को wrap करता है — वह content जो उस page के लिए unique है, header, footer, और sidebars जैसी दोहराई जाने वाली चीज़ों को छोड़कर।

हर page में सिर्फ एक ही दिखने वाला main element होना चाहिए, और screen readers इसे एक landmark के रूप में इस्तेमाल करते हैं ताकि users सीधे मुख्य content पर जा सकें।

Note: main को id="main-content" जैसी एक id दें, ताकि यह skip navigation link के target के रूप में भी काम कर सके।
Warning: navigation menus या copyright footers जैसे content के लिए, जो हर page पर दोहराया जाता है, main का उपयोग न करें — यह इसके पूरे उद्देश्य को खत्म कर देता है।

उदाहरण: The main Element

markup
<main id="main-content">
  Unique page content
</main>

Figure और Figcaption

figure element किसी image, diagram, या code snippet को उसके caption के साथ figcaption के जरिए group करता है। इससे visual content और उसकी व्याख्या semantically जुड़ी रहती है, भले ही figure को बाद में layout द्वारा page पर कहीं और move कर दिया जाए।

Note: जब भी किसी image को caption की जरूरत हो, figure इस्तेमाल करें — यह img के पास सिर्फ p tag रखने से कहीं ज्यादा सार्थक है।
Warning: figcaption को figure का direct child होना चाहिए — इसे कहीं और रखने से semantic relationship चुपचाप टूट जाता है।

उदाहरण: Figure and Figcaption

markup
<figure>
  <img src="diagram.jpg" alt="Diagram">
  <figcaption>System architecture diagram</figcaption>
</figure>

time Element

time element dates और times को इस तरह mark up करता है कि इंसान और machine दोनों उन्हें समझ सकें।

datetime attribute में एक machine-readable format होता है, जबकि दिखने वाला text readers के लिए जितना सहज हो, उतने तरीके से लिखा जा सकता है, जैसे 'पिछले मंगलवार' या '3 दिन पहले'।

Note:
  • Search engines और browser extensions time elements को पहचान सकते हैं और उन्हें calendar reminders में बदल सकते हैं या आने वाले events को highlight कर सकते हैं।
  • Accepted attributes:
  • datetime — valid date/time string, जैसे 2026-01-15 | 2026-01-15T10:30 | PT2H | 2026
Warning: datetime attribute को YYYY-MM-DD जैसे strict format का पालन करना चाहिए — उस attribute में 'next Friday' जैसे free text को machines समझ नहीं पाएंगी।

उदाहरण: The time Element

markup
<p>Published <time datetime="2024-03-05">last Tuesday</time></p>

address Element

address element किसी page या article के लेखक की contact information, जैसे email address, phone number, या physical mailing address को mark up करता है।

यह खासतौर पर contact details के लिए है, content में दिखने वाले किसी भी random postal address के लिए नहीं।

Note: किसी site की official contact details को styled और semantically सार्थक दोनों तरीके से mark up करने के लिए footer के अंदर address इस्तेमाल करें।
Warning: ऐसे address को mark up करने के लिए address का उपयोग न करें जो page के author से contact करने से संबंधित न हो, जैसे किसी article के अंदर mention किया गया restaurant का address।

उदाहरण: The address Element

markup
<footer>
  <address>Contact: [email protected]</address>
</footer>

Mark और Abbr Elements

mark element text को मौजूदा context के हिसाब से relevant होने के लिए highlight करता है, जैसे किसी query से मेल खाते search results, और browsers इसे default रूप से yellow background के साथ render करते हैं।

abbr element किसी abbreviation या acronym को mark up करता है, और उसका title attribute hover करने पर एक tooltip की तरह पूरा विस्तारित अर्थ बताता है।

Note: search terms या ज़रूरी phrases को highlight करने के लिए खासतौर पर mark इस्तेमाल करें — इसका semantic अर्थ है, सिर्फ span पर background color जोड़ने के विपरीत।
Warning: हर abbr के पास एक title attribute होना चाहिए, वरना screen readers पूरा expanded meaning announce करने के बजाय सिर्फ letters ज़ोर से पढ़ देते हैं।

उदाहरण: Mark and Abbr Elements

markup
<p>Results for <mark>HTML</mark> and <abbr title="Cascading Style Sheets">CSS</abbr>.</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 10 topics to unlock

0/10 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.