--- title: slug: Web/HTML/Element/thead tags: - 元素 - 表格 translation_of: Web/HTML/Element/thead ---

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

{{EmbedInteractiveExample("pages/tabbed/thead.html","tabbed-taller")}}

内容类别 无.
允许内容 零或多个{{ HTMLElement("tr") }}元素.
标签省略 开头的标签是强制的. 如果{{ HTMLElement("thead") }} 元素后直接跟 {{ HTMLElement("tbody") }}或{{ HTMLElement("tfoot") }}元素,结尾的标签可以被省略。
Permitted parents A {{ HTMLElement("table") }} element. The {{ HTMLElement("thead") }} must appear after any {{ HTMLElement("caption") }} or {{ HTMLElement("colgroup") }} element, even implicitly defined, but before any {{ HTMLElement("tbody") }}, {{ HTMLElement("tfoot") }} and {{ HTMLElement("tr") }} element.
Permitted ARIA roles Any
DOM interface {{domxref("HTMLTableSectionElement")}}

属性

This element includes the global attributes.

{{ htmlattrdef("align") }} {{ Deprecated_inline() }} in {{ HTMLVersionInline("4") }}, {{ obsolete_inline() }} in {{ HTMLVersionInline("5") }}
This enumerated attribute specifies how horizontal alignment of each cell content will be handled. Possible values are:

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 {{ cssxref("text-align") }} property on it.
  • To achieve the same effect as the char value, in CSS3, you can use the value of the {{ htmlattrxref("char", "thead") }} as the value of the {{ cssxref("text-align") }} property {{ unimplemented_inline() }}.
{{ htmlattrdef("bgcolor") }} {{ Non-standard_inline() }}
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:
black = "#000000" green = "#008000"
silver = "#C0C0C0" lime = "#00FF00"
gray = "#808080" olive = "#808000"
white = "#FFFFFF" yellow = "#FFFF00"
maroon = "#800000" navy = "#000080"
red = "#FF0000" blue = "#0000FF"
purple = "#800080" teal = "#008080"
fuchsia = "#FF00FF" aqua = "#00FFFF"
Usage note: Do not use this attribute, as it is non-standard and only implemented in some versions of Microsoft Internet Explorer: the {{ HTMLElement("thead") }} element should be styled using CSS. To give a similar effect to the bgcolor attribute, use the CSS property {{ cssxref("background-color") }}, on the relevant {{ HTMLElement("td") }} or {{ HTMLElement("th") }} elements.
{{ htmlattrdef("char") }} {{ Deprecated_inline() }} in {{ HTMLVersionInline("4") }}, {{ obsolete_inline() }} in {{ HTMLVersionInline("5") }}
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 {{ htmlattrxref("align", "tr") }} 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 {{ htmlattrxref("char", "thead") }}, in CSS3, you can use the character set using the {{ htmlattrxref("char", "thead") }} attribute as the value of the {{ cssxref("text-align") }} property {{ unimplemented_inline() }}.
{{ htmlattrdef("charoff") }} {{ Deprecated_inline() }} in {{ HTMLVersionInline("4") }}, {{ obsolete_inline() }} in {{ HTMLVersionInline("5") }}
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.
{{ htmlattrdef("valign") }} {{ Deprecated_inline() }} in {{ HTMLVersionInline("4") }}, {{ obsolete_inline() }} in {{ HTMLVersionInline("5") }}
This attribute specifies the vertical alignment of the text within each row of cells of the table header. Possible values for this attribute are:
Note: Do not use this attribute as it is obsolete (and not supported) in the latest standard: instead set the CSS {{ cssxref("vertical-align") }} property on it.

示例

See {{ HTMLElement("table") }} for examples on <thead>.

规范

Specification Status Comment
{{SpecName('HTML WHATWG','tables.html#the-thead-element','thead element')}} {{Spec2('HTML WHATWG')}}
{{SpecName('HTML5 W3C','tabular-data.html#the-thead-element','thead element')}} {{Spec2('HTML5 W3C')}}

浏览器兼容性

{{Compat("html.elements.thead")}}

参见

{{HTMLRef}}