Table row. tr elements must appear within a <table> element. The HTML <tr> tag is used for specifying a <table> row within a <table>. A <table> row contains one or more <td> and/or <th> tags which determine individual cells/columns.

TR Element

The <tr> element can only be used in the following contexts:

  • As a child of a <thead> element
  • As a child of a <tbody> element
  • As a child of a <tfoot> element
  • As a child of a <table> element, after any <caption>, <colgroup>, and <thead> elements, but only if there are no <tbody> elements that are children of the <table> element

Also, the <tr> tag must contain one of the following tags:

  • When the parent node is a <thead> element: Zero or more <th> elements
  • Otherwise: Zero or more <td> or <th> elements

Required Attributes

  • None.

Optional Attributes

  • align can be used to horizontally align the content of the cell. The value can be left, center, right, justify or char.
  • valign can be used to vertically align the content of the cell. The value can be top, middle, bottom or baseline.
  • char can be used to specify a character with which cells will align, such as a decimal point. It is not supported by any major browser.
  • charoff can be used to specify the number of pixels the alignment should be offset from the char character. It is not supported by any major browser.
  • Common attributes

Example

<table>
	<tr>
		<th>Name</th>
		<th>Nationality</th>
	</tr>
	<tr>
		<td>John</td>
		<td>English</td>
	</tr>
	<tr>
		<td>Pedro</td>
		<td>Portuguese</td>
	</tr>
</table>

Changes in HTML5

  • None.

Related Tags