--- title: slug: Web/HTML/Element/tr translation_of: Web/HTML/Element/tr ---

HTML <tr> 元素定义表格中的行。 同一行可同时出现{{HTMLElement("td")}} 和{{HTMLElement("th")}} 元素。

Content categories None
Permitted content Zero or more {{HTMLElement("td")}} or {{HTMLElement("th")}} elements, or a mix of them
Tag omission Start tag is mandatory. End tag may be omitted if the {{HTMLElement("tr")}} element is immediately followed by a {{HTMLElement("tr")}} element, or if the parent table group ({{HTMLElement("thead")}}, {{HTMLElement("tbody")}} or {{HTMLElement("tfoot")}}) element doesn't have any more content
Permitted parents {{HTMLElement("table")}}, {{HTMLElement("thead")}}, {{HTMLElement("tbody")}} or {{HTMLElement("tfoot")}} element
Permitted ARIA roles Any
DOM interface {{domxref("HTMLTableRowElement")}}

Attributes

表格标签支持 全局特性。还有一些过期的特性,你应该避免使用它们,但是可以了解它们,会在你阅读旧代码的时候有所帮助。

{{htmlattrdef("align")}} {{deprecatedGeneric("inline","html4.01")}}, {{obsoleteGeneric("inline","html5")}}
该枚举属性指定每个单元格中内容的水平对齐方式,可使用的属性值如下:

If this attribute is not set, the parent node's value is inherited.

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", "tr")}} as the value of the {{cssxref("text-align")}} property {{unimplemented_inline}}.
{{htmlattrdef("bgcolor")}} {{deprecatedGeneric("inline","html4.01")}}, {{obsoleteGeneric("inline","html5")}}
This attribute defines the background color of each cell of the row. It can be either an hexadecimal #RRGGBB or #RGB value or a color keyword.
Usage note: the {{HTMLElement("tr")}} element should be styled using CSS. To give a similar effect to the bgcolor attribute, use the CSS property {{cssxref("background-color")}}.
{{htmlattrdef("char")}} {{deprecatedGeneric("inline","html4.01")}}, {{obsoleteGeneric("inline","html5")}}
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", "tr")}}, in CSS3, you can use the character set using the {{htmlattrxref("char", "tr")}} attribute as the value of the {{cssxref("text-align")}} property {{unimplemented_inline}}.
{{htmlattrdef("charoff")}} {{deprecatedGeneric("inline","html4.01")}}, {{obsoleteGeneric("inline","html5")}}
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")}} {{deprecatedGeneric("inline","html4.01")}}, {{obsoleteGeneric("inline","html5")}}
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.

Examples

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

Specifications

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

Browser compatibility

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

See also

{{HTMLRef}}