Elements/th - HTML Wiki

  • List of Elements
    • Tables
      • table
      • caption
      • colgroup
      • col
      • tbody
      • thead
      • tfoot
      • tr
      • td
      • th

Contents

  • 1 <th>
    • 1.1 Point
    • 1.2 HTML Attributes
    • 1.3 Examples
      • 1.3.1 Example A
      • 1.3.2 Example B
      • 1.3.3 Example C
      • 1.3.4 Example D
    • 1.4 HTML Reference
<th>

The <th> element represents a header cell in a table.

Point

  • The th element can specify the cell which the influence of headding cell reaches by the scope attribute.

HTML Attributes

  • colspan = valid non-negative integerThis attribute gives the number of columns respectively that the cell is to span.
  • rowspan = valid non-negative integerThis attribute gives the number of rows respectively that the cell is to span. [Example B]
  • headers = unordered set of unique space-separated tokensThe value of this attribute must have the value of an id attribute of the th element that is targeted. [Example C]
  • scope = row/ col/ rowgroup/ colgroupThe scope attribute specifies the cell which the influence of headding cell reaches. [Example D]
    • rowThe header cell applies to some of the subsequent cells in the same row(s).
    • colThe header cell applies to some of the subsequent cells in the same column(s).
    • rowgroupThe header cell applies to all the remaining cells in the row group. A th element's scope attribute must not be in the row group state if the element is not anchored in a row group.
    • colgroupThe header cell applies to all the remaining cells in the column group. A th element's scope attribute must not be in the column group state if the element is not anchored in a column group.

See also global attributes.

Examples

Example A

[try it]

<table> <caption> <p>table 1. List of HTML elements</p> </caption> <thead> <tr> <th>Number</th> <th>element</th> </tr> </thead> <tbody> <tr> <td>4.1.1</td> <td>html</td> </tr> <tr> <td>4.2.1</td> <td>head</td> </tr> </tbody> </table>

Example B

[try it]:

<table> <caption> <p>table 1. Sample table</p> </caption> <tr> <td rowspan="2">1</td> <td>2</td> </tr> <tr> <td>3</td> </tr> </table>

Example C

Use case of the headers attribute [try it]:

<table> <caption> <p>table 1. List of HTML elements</p> </caption> <thead> <tr> <th id="c1">Number</th> <th id="c2">element</th> </tr> </thead> <tbody> <tr> <td headers="c1">4.1.1</td> <td headers="c2">html</td> </tr> <tr> <td headers="c1">4.2.1</td> <td headers="c2">head</td> </tr> </tbody> </table>

Example D

The scope attribute specifies the cell which the influence of headding cell reaches [try it]:

<table> <caption> <p>table 1. List of HTML elements</p> </caption> <thead> <tr> <th scope="row">Number</th> <th scope="row">element</th> </tr> </thead> <tbody> <tr> <td>4.1.1</td> <td>html</td> </tr> <tr> <td>4.2.1</td> <td>head</td> </tr> </tbody> </table>

HTML Reference

The HTML5 specification defines the <th> element in 4.9.10 The th element.

Từ khóa » Html Th Column