Introduction to HTML Table Tags, Advantages and Limitations in Hindi
HTML में जब हमें information को rows और columns के form में दिखाना होता है, तब हम Table का इस्तेमाल करते हैं। Table की मदद से related data को एक structured और easy-to-read format में arrange किया जा सकता है।
उदाहरण के लिए students की list, exam results, product prices, class timetable, employee details और अन्य structured information को table के रूप में दिखाया जा सकता है।
HTML Table क्या है?
HTML Table एक ऐसा structure है जिसमें data को rows और columns में arrange किया जाता है। HTML में पूरा table बनाने के लिए <table> tag का इस्तेमाल होता है।
एक table के अंदर अलग-अलग rows और cells होते हैं। Row बनाने के लिए <tr>, heading cell के लिए <th> और normal data cell के लिए <td> tag इस्तेमाल किया जाता है।
Basic HTML Table Structure
एक simple table का basic structure इस प्रकार होता है:
ऊपर के example में <table> पूरा table create करता है। इसके अंदर दो rows हैं। पहली row में headings और दूसरी row में actual data दिया गया है।
HTML Table के Important Tags
1. <table> Tag
<table> tag HTML table का main container होता है। Table की सभी rows और cells इसी tag के अंदर लिखे जाते हैं।
2. <tr> Tag
<tr> का मतलब Table Row होता है। इसका इस्तेमाल table में एक पूरी row बनाने के लिए किया जाता है।
एक row के अंदर एक या एक से ज्यादा <td> या <th> cells हो सकते हैं।
3. <th> Tag
<th> का मतलब Table Header होता है। इसका इस्तेमाल table के heading cells बनाने के लिए किया जाता है। जैसे Name, Age, Course, Marks आदि।
Browser की default styling में <th> का text आमतौर पर bold और centered दिखाई देता है, हालांकि CSS के जरिए इसका design बदला जा सकता है।
4. <td> Tag
<td> का मतलब Table Data होता है। इसका इस्तेमाल table में actual data दिखाने के लिए किया जाता है।
Table में Border लगाना
HTML table में border दिखाने के लिए आजकल CSS का इस्तेमाल करना बेहतर होता है। CSS की मदद से हम table, heading cells और data cells के लिए border define कर सकते हैं।
इस example में CSS selector table, th, td तीनों elements पर border apply कर रहा है।
Table में Padding और Spacing
Table को readable बनाने के लिए cells के अंदर थोड़ा space देना useful होता है। CSS की padding property से cell के अंदर spacing दी जा सकती है।
border-collapse: collapse; adjacent borders को combine करके table को cleaner appearance देता है।
Table Caption
<caption> tag का उपयोग table के title या description के लिए किया जाता है। इससे user को table के बारे में शुरुआत में ही पता चल सकता है।
thead, tbody और tfoot
जब table में ज्यादा data हो, तो rows को logical sections में organize करने के लिए <thead>, <tbody> और <tfoot> tags का उपयोग किया जा सकता है।
- <thead>: Table की heading rows को represent करता है।
- <tbody>: Table के main data rows को represent करता है।
- <tfoot>: Table के footer या summary rows के लिए उपयोग किया जाता है।
Colspan का उपयोग
colspan attribute का उपयोग तब किया जाता है जब एक cell को एक से ज्यादा columns में फैलाना हो।
उदाहरण के लिए अगर तीन columns हैं और हमें एक heading को तीनों columns में फैलाना है, तो colspan="3" का उपयोग किया जा सकता है।
Rowspan का उपयोग
rowspan attribute का उपयोग किसी cell को एक से ज्यादा rows में फैलाने के लिए किया जाता है।
HTML Tables के Advantages
HTML tables का सबसे बड़ा फायदा यह है कि structured data को rows और columns के form में आसानी से present किया जा सकता है।
- Data को व्यवस्थित तरीके से दिखाया जा सकता है।
- Rows और columns के कारण information को compare करना आसान होता है।
- Student results और marks जैसी information के लिए useful हैं।
- Schedules और timetables को आसानी से display किया जा सकता है।
- Pricing और comparison information को structured format में दिखाया जा सकता है।
- CSS की मदद से tables को अलग-अलग designs दिए जा सकते हैं।
HTML Tables की Limitations
HTML tables structured data के लिए useful हैं, लेकिन पूरे webpage का layout बनाने के लिए tables का इस्तेमाल करना modern web development में सही approach नहीं माना जाता। Page layout के लिए CSS layout techniques का उपयोग करना बेहतर होता है।
- बहुत बड़ी tables mobile screens पर difficult हो सकती हैं।
- बहुत ज्यादा columns होने पर horizontal scrolling की जरूरत पड़ सकती है।
- Complex tables को समझना और maintain करना मुश्किल हो सकता है।
- Webpage layout बनाने के लिए tables flexible नहीं होते।
Complete HTML Table Example
अब एक complete example देखते हैं जिसमें <table>, <caption>, <thead>, <tbody>, <tfoot>, <tr>, <th>, <td>, colspan और CSS को एक साथ use किया गया है।