大网数据广告活动
Web 标准与前端开发

<thead>

· 52CE 我爱测

This element includes the global attributes.

HTML 的 <thead> 元素定义了一组定义表格的列头的行。

HTML Demo: <thead>

<table>
  <caption>
    Council budget (in £) 2018
  </caption>
  <thead>
    <tr>
      <th scope="col">Items</th>
      <th scope="col">Expenditure</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th scope="row">Donuts</th>
      <td>3,000</td>
    </tr>
    <tr>
      <th scope="row">Stationery</th>
      <td>18,000</td>
    </tr>
  </tbody>
  <tfoot>
    <tr>
      <th scope="row">Totals</th>
      <td>21,000</td>
    </tr>
  </tfoot>
</table>
thead,
tfoot {
  background-color: #2c5e77;
  color: #fff;
}

tbody {
  background-color: #e4f0f5;
}

table {
  border-collapse: collapse;
  border: 2px solid rgb(140 140 140);
  font-family: sans-serif;
  font-size: 0.8rem;
  letter-spacing: 1px;
}

caption {
  caption-side: bottom;
  padding: 10px;
}

th,
td {
  border: 1px solid rgb(160 160 160);
  padding: 8px 10px;
}

td {
  text-align: center;
}

<table class="properties"> <tbody> <tr> <th scope="row"><a href="/zh-CN/docs/Web/HTML/Guides/Content_categories">内容类别</a></th> <td>无。</td> </tr> <tr> <th scope="row">允许内容</th> <td>零或多个tr元素。</td> </tr> <tr> <th scope="row">标签省略</th> <td>开头的标签是强制的。如果thead 元素后直接跟 tbody或tfoot元素,结尾的标签可以被省略。</td> </tr> <tr> <th scope="row">Permitted parents</th> <td>A table element. The thead must appear after any caption or colgroup element, even implicitly defined, but before any tbody, tfoot and tr element.</td> </tr> <tr> <th scope="row">Permitted ARIA roles</th> <td>Any</td> </tr> <tr> <th scope="row">DOM interface</th> <td>HTMLTableSectionElement</td> </tr> </tbody> </table>

属性

This element includes the global attributes.

  • align

    • : This enumerated attribute specifies how horizontal alignment of each cell content will be handled. Possible values are:

      • left, aligning the content to the left of the cell
      • center, centering the content in the cell
      • right, aligning the content to the right of the cell
      • justify, inserting spaces into the textual content so that the content is justified in the cell
      • char, aligning the textual content on a special character with a minimal offset, defined by the char and charoff attributes. If this attribute is not set, the left value is assumed.

      [!NOTE] Do not use this attribute as it is obsolete (not supported) in the latest standard.

      • To achieve the same effect as the left, center, right or justify values, use the CSS text-align property on it.
      • To achieve the same effect as the char value, in CSS3, you can use the value of the char as the value of the text-align property.
  • bgcolor

    • : This attribute defines the background color of each cell of the column. It is one of the 6-digit hexadecimal code as defined in sRGB, prefixed by a '#'. One of the sixteen predefined color strings may be used.

      [!NOTE] Do not use this attribute, as it is non-standard and only implemented in some versions of Microsoft Internet Explorer: the thead element should be styled using CSS. To give a similar effect to the bgcolor attribute, use the CSS property background-color, on the relevant td or th elements.

  • char

    • : This attribute is used to set the character to align the cells in a column on. Typical values for this include a period (.) when attempting to align numbers or monetary values. If align is not set to char, this attribute is ignored.

      [!NOTE] Do not use this attribute as it is obsolete (and not supported) in the latest standard. To achieve the same effect as the char, in CSS3, you can use the character set using the char attribute as the value of the text-align property.

  • charoff

    • : This attribute is used to indicate the number of characters to offset the column data from the alignment characters specified by the char attribute.

      [!NOTE] Do not use this attribute as it is obsolete (and not supported) in the latest standard.

  • valign

    • : This attribute specifies the vertical alignment of the text within each row of cells of the table header. Possible values for this attribute are:

      • baseline, which will put the text as close to the bottom of the cell as it is possible, but align it on the baseline of the characters instead of the bottom of them. If characters are all of the size, this has the same effect as bottom.
      • bottom, which will put the text as close to the bottom of the cell as it is possible;
      • middle, which will center the text in the cell;
      • top, which will put the text as close to the top of the cell as it is possible.

      [!NOTE] Do not use this attribute as it is obsolete (and not supported) in the latest standard: instead set the CSS vertical-align property on it.

示例

See table for examples on <thead>.

规范

浏览器兼容性

参见

  • Other table-related HTML Elements: caption, col, colgroup, table, tbody, td, tfoot, th, tr;
  • CSS properties and pseudo-classes that may be specially useful to style the <thead> element:
    • the :nth-child pseudo-class to set the alignment on the cells of the column;
    • the text-align property to align all cells content on the same character, like '.'.<

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。