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

HTML Lists

कल्पना कीजिए बिना structured recipe के खाना बनाना, या instructions को एक विशाल, disorganized block of text में print करके cabinet बनाना। आप गलतियां करेंगे और steps skip कर देंगे। HTML lists आपको information को साफ bullet points या numbered sequences में organize करने देती हैं, जैसे कोई grocery list या step-by-step instructions। वे related information को एक साथ group करती हैं ताकि आपका webpage text structured, scannable, और readers के लिए digest करना बेहद आसान बने।
Syntax
markup
<ul>
  <li>Item</li>
</ul>

<ol>
  <li>Item</li>
</ol>

Unordered Lists (ul और li)

Unordered lists का उपयोग तब किया जाता है जब listed items का क्रम मायने नहीं रखता। ब्राउज़र इन्हें bullet points के रूप में display करता है। list container ul tag का उपयोग करता है, और हर list item li tag के अंदर लपेटा जाता है।

Note: Unordered lists आमतौर पर modern website navigation menus बनाने के लिए उपयोग की जाती हैं।
Warning: text को कभी सीधे ul tag के अंदर न रखें; सारे list items li tags के अंदर रहने चाहिए।

उदाहरण: Unordered Lists (ul and li)

markup
<ul>
  <li>Milk</li>
  <li>Bread</li>
</ul>

Ordered Lists (ol और li)

अगर आप instructions या list rankings का कोई सेट code कर रहे हैं, तो items का क्रम महत्वपूर्ण होता है। Ordered lists मुख्य container के रूप में ol tag का उपयोग करती हैं, और ब्राउज़र स्वचालित रूप से हर nested li item को क्रमानुसार numbered करता है।

Note:
  • readers को कोई process चलाना या steps follow करना सिखाते समय ordered lists का उपयोग करें।
  • Accepted attributes:
  • type — 1 | a | A | i | I
  • start — शुरुआती integer number
  • reversed — boolean; उल्टे क्रम में count करता है
  • li value — उस item के लिए integer number
Warning: अपने list items के अंदर manually numbers type न करें; browser उन्हें अपने आप generate करता है।

उदाहरण: Ordered Lists (ol and li)

markup
<ol>
  <li>Preheat oven</li>
  <li>Mix ingredients</li>
</ol>

List Markers को Customize करना (type और start)

By default, ordered lists numbers (1, 2, 3) का उपयोग करती हैं, और unordered lists ठोस circular bullets का उपयोग करती हैं।

आप इन lists को attributes का उपयोग करके customize कर सकते हैं: type attribute numbering style बदलता है (जैसे Roman numerals या letters), और start attribute एक custom शुरुआती number सेट करता है।

Note:
  • clean और varied sub-steps के लिए alphabetical steps display करने के लिए type attribute का उपयोग करें।
  • Accepted attributes:
  • type — 1 | a | A | i | I (ol पर)
  • start — integer (ol पर)
  • li value — integer (ol के अंदर li पर)
  • ul पर type (disc | circle | square) obsolete है; list-style-type का उपयोग करें
Warning: सुनिश्चित करें कि आप valid attribute values का उपयोग करें ताकि list standard numbering पर fallback न हो।

उदाहरण: Customizing List Markers (type and start)

markup
<ol type="I" start="3">
  <li>Third</li>
  <li>Fourth</li>
</ol>

Lists के अंदर Lists Nest करना

complex directories या sub-categories को represent करने के लिए, आप एक list को सीधे दूसरे के अंदर nest कर सकते हैं। ऐसा करने के लिए, आप secondary list container को अपनी primary list के किसी specific li item के अंदर रखते हैं।

Note: अपने code को पढ़ना और maintain करना बहुत आसान बनाने के लिए अपने code editor में nested lists को indent करें।
Warning: सुनिश्चित करें कि आपकी nested list पूरी तरह एक li tag के अंदर wrap हो; इसे सीधे li tags के बीच रखना invalid HTML है।

उदाहरण: Nesting Lists Inside Lists

markup
<ul>
  <li>Fruits
    <ul>
      <li>Apple</li>
      <li>Banana</li>
    </ul>
  </li>
</ul>

Description Lists (dl, dt, dd)

किसी dictionary, glossary, या product specifications list को code करते समय, standard bullets सबसे अच्छा format नहीं होते।

Description lists terms और descriptions को तीन tags का उपयोग करके group करती हैं: dl (description list), dt (definition term), और dd (definition description)।

Note: Description lists आपके articles के लिए semantic metadata details code करने के लिए बेहतरीन हैं।
Warning: ul या li जैसे list tags को description list container के अंदर न रखें।

उदाहरण: Description Lists (dl, dt, dd)

markup
<dl>
  <dt>HTML</dt>
  <dd>HyperText Markup Language</dd>
</dl>

reversed Attribute

किसी ordered list पर reversed attribute numbering को ऊपर की बजाय नीचे की ओर count कराता है, बिना HTML में list items के असल क्रम को बदले।

यह countdowns या ranked lists के लिए उपयोगी है जहां सबसे महत्वपूर्ण item markup में सबसे आखिर में दिखना चाहिए लेकिन फिर भी सबसे बड़ा number दिखाना चाहिए, या इसके उलट।

Note:
  • किसी भी specific संख्या से countdown करने के लिए reversed को एक custom start value के साथ combine करें।
  • Accepted values:
  • reversed — boolean attribute (present या reversed="")
  • सिर्फ ol के साथ काम करता है
  • पहला number set करने के लिए start के साथ combine करें
Warning: reversed सिर्फ display किए गए numbers को बदलता है — यह list items को visually reorder नहीं करता।

उदाहरण: The reversed Attribute

markup
<ol reversed start="3">
  <li>Third</li>
  <li>Second</li>
  <li>First</li>
</ol>

सही List Type चुनना

जब items का क्रम सच में मायने न रखे, जैसे features का एक सेट, तब unordered list का उपयोग करें। जब क्रम मायने रखे, जैसे step-by-step instructions, तब ordered list का उपयोग करें।

जब आप terms को उनकी definitions या explanations के साथ जोड़ रहे हों, जैसे कोई glossary या FAQ, तब description list का उपयोग करें।

Note: अगर items को दोबारा व्यवस्थित करने से content का अर्थ बदल जाता है, तो हमेशा ordered list का उपयोग करें, unordered का नहीं।
Warning: एक असली ol element की जगह text के रूप में manually type किए गए numbers के साथ एक div का उपयोग करना lists द्वारा दिए जाने वाले semantic और accessibility फायदों को खो देता है।

उदाहरण: Choosing the Right List Type

markup
<ul>
  <li>Fast shipping</li>
</ul>
<ol>
  <li>Add to cart</li>
</ol>
<dl>
  <dt>SKU</dt>
  <dd>Product code</dd>
</dl>
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.