HTML List क्या है?
HTML में Lists का इस्तेमाल एक जैसे या related items को व्यवस्थित तरीके से दिखाने के लिए किया जाता है। Lists की मदद से information को पढ़ना और समझना आसान हो जाता है। HTML में मुख्य रूप से तीन प्रकार की lists होती हैं — Ordered List, Unordered List और Description List।
इसके अलावा <li> tag का इस्तेमाल list के individual items के लिए किया जाता है और एक list के अंदर दूसरी list बनाकर Nested List भी बनाई जा सकती है।
Ordered List (<ol>)
Ordered List का इस्तेमाल उन items के लिए किया जाता है जिनका कोई sequence, order या numbering हो। इसमें browser सामान्यतः items के आगे numbers दिखाता है, जैसे 1, 2, 3 आदि।
Ordered List बनाने के लिए <ol> tag और उसके अंदर प्रत्येक item के लिए <li> tag का इस्तेमाल किया जाता है।
Ordered List का Basic Example
इस example में <ol> पूरी ordered list को define करता है, जबकि प्रत्येक <li> एक individual list item को represent करता है। Browser इन items को default रूप से 1, 2 और 3 की numbering के साथ दिखाएगा।
Ordered List में Sequence
Ordered List तब ज्यादा useful होती है जब items का order important हो। उदाहरण के लिए किसी process के steps, instructions, ranking या किसी procedure के अलग-अलग steps को ordered list में दिखाया जा सकता है।
जैसे:
- HTML सीखें
- CSS सीखें
- JavaScript सीखें
यहाँ items का sequence एक logical order को represent करता है।
Unordered List (<ul>)
Unordered List का इस्तेमाल उन items के लिए किया जाता है जिनका कोई specific sequence या numbering जरूरी नहीं है। इसमें browser सामान्यतः items के आगे bullet points दिखाता है।
Unordered List बनाने के लिए <ul> tag और प्रत्येक item के लिए <li> tag का इस्तेमाल किया जाता है।
Unordered List का Basic Example
इस example में browser items को bullet points के साथ display करेगा। यहाँ items का order important नहीं है, इसलिए <ul> का इस्तेमाल किया गया है।
Unordered List का इस्तेमाल कहाँ होता है?
Unordered Lists का इस्तेमाल website navigation items, features, product lists, ingredients, related topics और ऐसे कई content sections में किया जा सकता है जहाँ items को किसी particular order में दिखाना जरूरी नहीं होता।
Description List (<dl>)
Description List का इस्तेमाल किसी term के साथ उसकी definition, description या additional information दिखाने के लिए किया जाता है। यह dictionary या glossary जैसी information के लिए useful होती है।
Description List में मुख्य रूप से तीन tags इस्तेमाल होते हैं:
<dl>— पूरी Description List को define करता है।<dt>— Definition Term यानी term या नाम को define करता है।<dd>— Definition Description यानी उस term की description या meaning को define करता है।
Description List का Example
ऊपर के example में <dl> पूरी description list है। <dt> में term और <dd> में उस term की description दी गई है।
List Item (<li>)
<li> का मतलब List Item होता है। इसका इस्तेमाल list के प्रत्येक individual item को define करने के लिए किया जाता है।
<li> को सामान्यतः <ol> या <ul> के अंदर इस्तेमाल किया जाता है। Description List में <dt> और <dd> का इस्तेमाल होता है, इसलिए वहाँ <li> की आवश्यकता नहीं होती।
उदाहरण:
इस example में तीन अलग-अलग <li> elements हैं। Browser इन सभी को <ul> के अंदर list items के रूप में display करता है।
Nesting of Lists
HTML में एक list के अंदर दूसरी list बनाना Nested List कहलाता है। इसका इस्तेमाल तब किया जाता है जब किसी main item के अंदर उससे related sub-items दिखाने हों।
उदाहरण के लिए, अगर किसी website पर Fruits एक main category है और उसके अंदर Mango तथा Banana जैसे items हैं, तो इन्हें nested list के रूप में दिखाया जा सकता है।
Nested List का Example
इस example में पहली <ul> main list है। इसके अंदर Fruits एक list item है और Fruits के अंदर दूसरी <ul> रखी गई है। यह दूसरी list nested list है।
Ordered List के अंदर Unordered List
Nested lists में केवल <ul> के अंदर <ul> ही जरूरी नहीं है। आप जरूरत के अनुसार ordered और unordered lists को एक-दूसरे के अंदर भी use कर सकते हैं।
यहाँ main list <ol> है, इसलिए Frontend और Backend numbered items हैं। इनके अंदर <ul> का इस्तेमाल करके sub-items बनाए गए हैं।
Styling HTML Lists with CSS
HTML lists को CSS की मदद से काफी आसानी से customize किया जा सकता है। आप list के bullets या numbers, text color, background, spacing, padding, border और अन्य properties को बदल सकते हैं।
नीचे एक example में ordered और unordered list को CSS के साथ style किया गया है। इसमें list items के बीच spacing, background, border और colors को customize किया गया है।