HTML Table Headers
In this page:
<table>
<tr>
<th>Column header</th>
</tr>
<tr>
<td>Cell</td>
</tr>
</table>
बुनियादी th Element
<th> structurally बिल्कुल <td> जैसा ही काम करता है -- यह एक table cell है -- लेकिन इसमें "यह cell एक label है" का semantic अर्थ होता है, जिसे ब्राउज़र default रूप से bold, centered text में render करते हैं, और जिसे assistive technology सामान्य data cells से अलग तरीके से announce करती है।
- हर उस cell के लिए <th> का उपयोग करें जो किसी row या column को label करती है, और <td> को केवल असल data values के लिए बचाकर रखें।
- Accepted attributes:
- scope — row | col | rowgroup | colgroup | auto
- colspan / rowspan — integers
- abbr — छोटा label
- headers — th ids की list
उदाहरण: The Basic th Element
<table>
<tr>
<th>Name</th>
<td>Alex</td>
</tr>
</table>
scope Attribute से Direction स्पष्ट करना
किसी <th> element पर scope attribute स्पष्ट रूप से बताता है कि वह पूरे column को label करता है (scope="col") या पूरी row को (scope="row"), जिससे किसी ऐसी table को navigate करने वाले screen reader users के लिए कोई भी ambiguity नहीं बचती जिसमें दोनों axes पर headers हों।
- किसी भी table में जहां header row और header column दोनों हों, हमेशा header cells में scope जोड़ें, क्योंकि तभी direction वाकई अस्पष्ट हो जाती है।
- Accepted values:
- row — row के लिए header
- col — column के लिए header
- rowgroup — row group के लिए header
- colgroup — column group के लिए header
- auto — default
उदाहरण: Clarifying Direction with the scope Attribute
<table>
<tr>
<th scope="col">Name</th>
<th scope="col">Age</th>
</tr>
</table>
thead से Grouping
<thead> table की header row(s) को असल data rows से अलग एक distinct semantic section में लपेटता है।
यह grouping header को अलग style करने (जैसे अलग background color) और किसी लंबी table को कई pages में print होने पर header row को दोहराने को support करने वाले ब्राउज़रों, दोनों के लिए उपयोगी है।
उदाहरण: Grouping with thead
<table>
<thead>
<tr><th>Name</th></tr>
</thead>
</table>
tbody और tfoot से Grouping
<tbody> table की main data rows को लपेटता है, जबकि <tfoot> एक footer row को लपेटता है, जो आमतौर पर totals या summary values के लिए उपयोग होता है।
<thead> के साथ मिलकर, ये तीनों sections किसी table को स्पष्ट रूप से labeled zones में बांटते हैं, जिनमें से हर एक को independently style किया जा सकता है, और कुछ layouts में independently scroll भी किया जा सकता है।
उदाहरण: Grouping with tbody and tfoot
<table>
<tbody>
<tr><td>Apple</td></tr>
</tbody>
<tfoot>
<tr><td>Total</td></tr>
</tfoot>
</table>
headers और id के साथ Accessible Multi-Level Headers
complex tables के लिए जहां एक single data cell एक से ज़्यादा header से जुड़ी हो (जैसे row label और column label दोनों), हर <th> पर id attribute को किसी <td> पर headers attribute के साथ जोड़ने से एक explicit link बनता है, जिससे screen readers उस specific cell के लिए हर relevant header announce कर सकते हैं।
- id/headers technique को सच में complex tables के लिए बचाकर रखें; simple tables आमतौर पर अकेले scope से भी काफी स्पष्ट होती हैं।
- Accepted attributes:
- th id — unique id
- td headers — th ids की space-separated list
- th scope — row | col | rowgroup | colgroup
उदाहरण: Accessible Multi-Level Headers with headers and id
<table>
<tr>
<th id="name">Name</th>
</tr>
<tr>
<td headers="name">Alex</td>
</tr>
</table>
Chapter Quiz — Complete all 26 topics to unlock
0/26 topics done
Complete these topics first:
- HTML Favicon
- HTML Page Title
- HTML Tables
- HTML Lists
- HTML Block & Inline
- HTML Comments
- HTML Colors
- HTML CSS
- HTML Links
- HTML Images
- HTML RGB Colors
- HTML HEX Colors
- HTML HSL Colors
- HTML Link Colors
- HTML Link Bookmarks
- HTML Background Images
- HTML Table Borders
- HTML Table Sizes
- HTML Table Headers
- HTML Table Padding & Spacing
- HTML Colspan & Rowspan
- HTML Table Styling
- HTML Table Colgroup
- HTML Unordered Lists
- HTML Ordered Lists
- HTML Other Lists / Description Lists