HTML Nav Element: नेविगेशन और एक्सेसिबिलिटी के लिए सीमेंटिक मार्कअप

 

HTML Nav Element: नेविगेशन और एक्सेसिबिलिटी के लिए सीमेंटिक मार्कअप

HTML5 का <nav> एलिमेंट वेब पेज के मुख्य नेविगेशन सेक्शन को परिभाषित करने के लिए डिज़ाइन किया गया है। यह एक सीमेंटिक एलिमेंट है जो ब्राउज़र और असिस्टिव टेक्नोलॉजी दोनों को स्पष्ट रूप से बताता है कि यह सेक्शन साइट नेविगेशन के लिए है।dhiwise+2

Nav एलिमेंट के मुख्य फायदे:

  • एक्सेसिबिलिटी: स्क्रीन रीडर्स और अन्य असिस्टिव डिवाइसेस इसे आसानी से पहचान सकती हैंalessiopuppi

  • SEO लाभ: सर्च इंजन nav एलिमेंट को एक महत्वपूर्ण सेक्शन मानते हैंaccessibilitychecker

  • सीमेंटिक मीनिंग: कोड को समझना और maintain करना आसान हो जाता हैaccessibility.uark

Comparison of non-semantic versus semantic HTML structure showing the use of the nav element for marking navigation sections
Comparison of non-semantic versus semantic HTML structure showing the use of the nav element for marking navigation sections techgurudehradun

कब इस्तेमाल करें

Nav एलिमेंट का इस्तेमाल सिर्फ मुख्य नेविगेशन ब्लॉक्स के लिए करना चाहिए। हर लिंक को nav में रैप करना ज़रूरी नहीं है - इसका उपयोग तब करें जब:dhiwise+1

  • मुख्य साइट मेन्यू हो

  • टेबल ऑफ कंटेंट्स हो

  • साइट के मुख्य सेक्शन्स के लिंक्स होंstackoverflow

कब इस्तेमाल न करें

Footer में मौजूद लिंक्स या छोटे लिंक समूहों के लिए nav एलिमेंट की ज़रूरत नहीं है।css-tricks+1

ARIA Roles और Accessibility Enhancement

Role="Navigation" का उपयोग

Nav एलिमेंट में role="navigation" जोड़ना एक बेहतरीन प्रैक्टिस है:alessiopuppi+1

xml
<nav role="navigation" aria-label="Header menu"> <ul> <li><a href="/">Home</a></li> <li><a href="/about">About</a></li> <li><a href="/services">Services</a></li> <li><a href="/contact">Contact</a></li> </ul> </nav>

ARIA-Label का महत्व

जब एक पेज पर कई nav एलिमेंट्स हों, तो aria-label का उपयोग करना ज़रूरी है:developer.mozilla+1

  • Primary Navigation: aria-label="Main menu"

  • User Menu: aria-label="User account"

  • Footer Links: aria-label="Footer navigation"developer.mozilla

यह स्क्रीन रीडर यूज़र्स को अलग-अलग नेविगेशन सेक्शन्स के बीच अंतर समझने में मदद करता है।aditus+1

Diagram showing ARIA landmark roles for webpage sections such as banner, navigation, main content, complementary, and content info
Diagram showing ARIA landmark roles for webpage sections such as banner, navigation, main content, complementary, and content info a11y-collective

CSS स्टाइलिंग vs HTML Structure

HTML5 का nav एलिमेंट सिर्फ डिफ़ॉल्ट स्टाइलिंग प्रदान नहीं करता - यह सीमेंटिक मीनिंग देता है। विज़ुअल अपीयरेंस के लिए CSS की ज़रूरत होती है:dhiwise

css
nav ul { list-style-type: none; margin: 0; padding: 0; background-color: #333; } nav a { display: inline-block; color: white; padding: 10px 20px; text-decoration: none; } nav a:hover { background-color: #555; }
Semantic HTML5 layout showing header, navigation, main content, aside, and footer sections with distinct colors illustrating webpage landmarks
Semantic HTML5 layout showing header, navigation, main content, aside, and footer sections with distinct colors illustrating webpage landmarks a11y-101

Ordered List का उपयोग

Breadcrumb navigation के लिए ordered list (<ol>) का उपयोग करना चाहिए क्योंकि इसमें क्रम महत्वपूर्ण है:afixt+2

xml
<nav aria-label="Breadcrumb"> <ol> <li><a href="/">Home</a></li> <li><a href="/category">Category</a></li> <li><a href="/subcategory">Subcategory</a></li> <li aria-current="page">Current Page</li> </ol> </nav>

Breadcrumb में ARIA Attributes

  • aria-label="Breadcrumb": नेविगेशन के प्रकार को स्पष्ट करता हैafixt

  • aria-current="page": वर्तमान पेज को इंडिकेट करता हैafixt

  • Primary navigation के लिए role="navigation" की ज़रूरत नहीं क्योंकि breadcrumb secondary navigation हैdev

Examples of styled breadcrumb navigation showing various CSS and icon customizations to enhance visual cues and usability
Examples of styled breadcrumb navigation showing various CSS and icon customizations to enhance visual cues and usability codehim

Multiple Navigation Elements

एक पेज पर कई nav एलिमेंट्स हो सकते हैं:stackoverflow+1

xml
<!-- Main Navigation --> <nav role="navigation" aria-label="Primary"> <ul> <li><a href="/">Home</a></li> <li><a href="/products">Products</a></li> </ul> </nav> <!-- Breadcrumb Navigation --> <nav aria-label="Breadcrumb"> <ol> <li><a href="/">Home</a></li> <li>Current Section</li> </ol> </nav> <!-- In-page Navigation --> <nav aria-label="Table of contents"> <ul> <li><a href="#section1">Section 1</a></li> <li><a href="#section2">Section 2</a></li> </ul> </nav>

हर nav एलिमेंट को unique aria-label देना ज़रूरी है ताकि स्क्रीन रीडर यूज़र्स अंतर कर सकें।developer.mozilla+1

Example of multiple <nav> landmarks marking navigational sections including breadcrumb and menu items for better accessibility and screen reader support
Example of multiple <nav> landmarks marking navigational sections including breadcrumb and menu items for better accessibility and screen reader support aditus

Modern Accessibility Standards

WCAG Guidelines के अनुसार

Nav एलिमेंट और ARIA roles WCAG (Web Content Accessibility Guidelines) के तीनों सिद्धांतों को support करते हैं:alessiopuppi

  1. Perceivable: स्क्रीन रीडर्स नेविगेशन को पहचान सकते हैं

  2. Operable: Keyboard navigation में सुधार होता है

  3. Understandable: साइट structure स्पष्ट हो जाता है

Schema.org Markup

Breadcrumbs के लिए structured data भी जोड़ सकते हैं:developer.mozilla

xml
<nav aria-label="Breadcrumb"> <ol itemscope itemtype="https://schema.org/BreadcrumbList"> <li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/category"> <span itemprop="name">Category</span> </a> <meta itemprop="position" content="1" /> </li> </ol> </nav>

Nav एलिमेंट का सही उपयोग सिर्फ एक्सेसिबिलिटी के लिए नहीं, बल्कि बेहतर यूज़र एक्सपीरियंस और SEO के लिए भी महत्वपूर्ण है। सीमेंटिक HTML का सही इस्तेमाल करके हम सभी यूज़र्स के लिए inclusive वेब बना सकते हैं।

  1. https://www.dhiwise.com/post/maximizing-usability-best-practices-for-html-navigation-lists
  2. https://www.accessibilitychecker.org/blog/aria-accessibility/
  3. https://stackoverflow.com/questions/8060106/what-semantic-html-markup-should-be-used-to-create-breadcrumbs
  4. https://alessiopuppi.blog/2024/03/19/nav-tag/
  5. https://accessibility.uark.edu/accessible-technology/developing-accessible-websites/aria-landmark-roles.php
  6. https://css-tricks.com/markup-for-breadcrumbs/
  7. https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/nav
  8. https://afixt.com/using-aria-landmarks-for-better-navigation/
  9. https://www.aditus.io/patterns/breadcrumbs/
  10. https://stackoverflow.com/questions/34588679/html5-multi-nav-tag-best-practices
  11. https://deliciousbrains.com/using-aria-roles-for-accessibility-in-wordpress/
  12. https://dev.to/keshav_kumar/semantic-html-and-accessibility-best-practices-how-to-write-accessible-and-semantic-code-45gk
  13. https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Roles/navigation_role
  14. https://developer.mozilla.org/en-US/docs/Learn_web_development/Core/Accessibility/HTML
  15. https://schema.org/BreadcrumbList
  16. https://www.browserstack.com/guide/what-are-aria-labels
  17. https://accessiblyapp.com/blog/semantic-html/
  18. https://design.umassp.edu/components/breadcrumb-navigation
  19. https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Roles
  20. https://www.accessibilitychecker.org/blog/semantic-html/

Comments