diff --git a/files/en-us/web/html/element/caption/index.md b/files/en-us/web/html/element/caption/index.md index 9d51c72442386d8..d3bc4f1dd3d6d60 100644 --- a/files/en-us/web/html/element/caption/index.md +++ b/files/en-us/web/html/element/caption/index.md @@ -21,35 +21,30 @@ The following attributes are deprecated and should not be used. They are documen - `align` {{deprecated_inline}} - - : This [enumerated](/en-US/docs/Glossary/Enumerated) attribute indicates how the caption must be aligned with respect to the table. It may have one of the following values: + - : Specifies on which side of the table the caption should be displayed. The possible {{Glossary("enumerated", "enumerated")}} values are `left`, `top`, `right`, or `bottom`. Use the {{cssxref("caption-side")}} and {{cssxref("text-align")}} CSS properties instead, as this attribute is deprecated. - - `left` - - : The caption is displayed to the left of the table. - - `top` - - : The caption is displayed above the table. - - `right` - - : The caption is displayed to the right of the table. - - `bottom` - - : The caption is displayed below the table. +## Usage notes - > **Warning:** Do not use this attribute, as it has been deprecated. The {{HTMLElement("caption")}} element should be styled using the [CSS](/en-US/docs/Web/CSS) properties {{cssxref("caption-side")}} and {{cssxref("text-align")}}. +- If included, the `
Login | @@ -57,31 +52,55 @@ This simple example presents a table that includes a caption.||
---|---|---|
user1 | -user1@sample.com | +user1@example.com |
user2 | -user2@sample.com | +user2@example.com |
Period | +Mon | +Tue | +Wed | +Thu | +Fri | +Sat | +Sun | +
---|---|---|---|---|---|---|---|
a.m. | +Clean room | +Football training | +Dance Course | +History Class | +Buy drinks | +Study hour | +Free time | +
p.m. | +Yoga | +Chess Club | +Meet friends | +Gymnastics | +Birthday party | +Fishing trip | +Free time | +
Mon | +Tue | +Wed | +Thu | +Fri | +Sat | +Sun | +
---|---|---|---|---|---|---|
Clean room | +Football training | +Dance Course | +History Class | +Buy drinks | +Study hour | +Free time | +
Yoga | +Chess Club | +Meet friends | +Gymnastics | +Birthday party | +Fishing trip | +Free time | +
- Content categories - | -- Flow content - | -
---|---|
Permitted content | -
- In this order:
-
|
-
Tag omission | -{{no_tag_omission}} | -
Permitted parents | -Any element that accepts flow content | -
Implicit ARIA role | -
- table
- |
-
Permitted ARIA roles | -Any | -
DOM interface | -{{domxref("HTMLTableElement")}} | -
John | -Doe | +Name | +Age |
---|---|---|---|
Jane | -Doe | +Maria Sanchez | +28 | +
Michael Johnson | +34 |
Simple table with header
First name | -Last name | +Name | +ID | +Member Since | +Balance |
---|---|---|---|---|---|
John | -Doe | +Margaret Nguyen | +427311 | ++ | 0.00 |
Jane | -Doe | +Edvard Galinski | +533175 | ++ | 37.00 | +
Hoshi Nakamura | +601942 | ++ | 15.00 |
Table with thead, tfoot, and tbody
+#### CSS + +With CSS, we provide the basic styling to create lines around the components of the table to make the data structure clearer. The CSS adds a solid border around the `Name | +ID | +Member Since | +Balance | +
---|---|---|---|
Margaret Nguyen | +427311 | ++ | 0.00 | +
Edvard Galinski | +533175 | ++ | 37.00 | +
Hoshi Nakamura | +601942 | ++ | 15.00 | +
Header content 1 | -Header content 2 | +Name | +ID | +Member Since | +Balance |
---|---|---|---|---|---|
Body content 1 | -Body content 2 | +Margaret Nguyen | +427311 | ++ | 0.00 |
Footer content 1 | -Footer content 2 | +Edvard Galinski | +533175 | ++ | 37.00 |
Hoshi Nakamura | +601942 | ++ | 15.00 | +
Table with colgroup
-Countries | -Capitals | -Population | -Language | -
---|---|---|---|
USA | -Washington, D.C. | -309 million | -English | -
Sweden | -Stockholm | -9 million | -Swedish | -
Table with colgroup and col
-Lime | -Lemon | -Orange | -
---|---|---|
Green | -Yellow | -Orange | -
Simple table with caption
+In this example, we extend the table even more by adding a column and introducing a multi-row head section. + +#### HTML + +Building on the table created so far, a new column for a "Membership End Date" is added in each body row with the {{HTMLElement("td")}} element. An additional row ({{HTMLElement("tr")}} element) is also added within the head section ({{HTMLElement("thead")}} element) to introduce a "Membership Dates" header as a heading for the "Joined" and "Canceled" columns. + +The creation of the second header row involves adding [`colspan`](/en-US/docs/Web/HTML/Element/th#colspan) and [`rowspan`](/en-US/docs/Web/HTML/Element/th#rowspan) attributes to the {{HTMLElement("th")}} elements to allocate the header cells to the correct columns and rows. + +```htmlAwesome data | -||||
Name | +ID | +Membership Dates | +Balance | +|
---|---|---|---|---|
Joined | +Canceled | +|||
Margaret Nguyen | +427311 | ++ | n/a | +0.00 | +
Edvard Galinski | +533175 | ++ | + | 37.00 | +
Hoshi Nakamura | +601942 | ++ | n/a | +15.00 | +
Name | +ID | +Membership Dates | +Balance | +|
---|---|---|---|---|
Joined | +Canceled | +|||
Margaret Nguyen | +427311 | ++ | n/a | +0.00 | +
Edvard Galinski | +533175 | ++ | + | 37.00 | +
Hoshi Nakamura | +601942 | ++ | n/a | +15.00 | +
Total balance | +52.00 | +
Name | +ID | +Membership Dates | +Balance | +||
---|---|---|---|---|---|
Joined | +Canceled | +||||
3 | +Margaret Nguyen | +427311 | ++ | n/a | +0.00 |
2 | +Edvard Galinski | +533175 | ++ | + | 37.00 |
1 | +Hoshi Nakamura | +601942 | ++ | n/a | +15.00 |
Total balance | +52.00 | +
` element of every `
| `. However, we don't do this for the `` to avoid long titles forcing columns to be wider than they need to be to display the data.
+#### CSS
+
+When looking at these styles you'll notice that table's {{cssxref("display")}} property has been set to `block`. While this allows scrolling, the table loses some of its integrity, and table cells try to become as small as possible. To mitigate this issue we've set {{cssxref("white-space")}} to `nowrap` on the {{HTMLElement("tbody")}}. However, we don't do this for the {{HTMLElement("thead")}} to avoid long titles forcing columns to be wider than they need to be to display the data.
+
+To keep the table headers on the page while scrolling down we've set {{cssxref("position")}} to sticky on the {{HTMLElement("th")}} elements. Note that we have **not** set {{cssxref("border-collapse")}} to `collapse`, as if we do the header cannot be separated correctly from the rest of the table.
-To keep the table headers on the page while scrolling down we've set {{cssxref("position")}} to sticky on the `` elements. Note that we have **not** set {{cssxref("border-collapse")}} to `collapse`, as if we do the header cannot be separated correctly from the rest of the table.
+Given that the `
+
+
+
diff --git a/files/en-us/web/html/element/td/column-row-span.png b/files/en-us/web/html/element/td/column-row-span.png
new file mode 100644
index 000000000000000..a779fb8e844a4e7
Binary files /dev/null and b/files/en-us/web/html/element/td/column-row-span.png differ
diff --git a/files/en-us/web/html/element/td/index.md b/files/en-us/web/html/element/td/index.md
index cb5ce2811ac804a..faeafe9f280e86e 100644
--- a/files/en-us/web/html/element/td/index.md
+++ b/files/en-us/web/html/element/td/index.md
@@ -7,7 +7,7 @@ browser-compat: html.elements.td
{{HTMLSidebar}}
-The **`5
+ 6
+ `** [HTML](/en-US/docs/Web/HTML) element defines a cell of a table that contains data. It participates in the _table model_.
+The **` | `** [HTML](/en-US/docs/Web/HTML) element defines a cell of a table that contains data and may be used as a child of the {{HTMLElement("tr")}} element.
{{EmbedInteractiveExample("pages/tabbed/td.html","tabbed-taller")}}
@@ -16,70 +16,265 @@ The **` | `** [HTML](/en-US/docs/Web/HTML) element defines a cell of a table th
This element includes the [global attributes](/en-US/docs/Web/HTML/Global_attributes).
- `colspan`
- - : This attribute contains a non-negative integer value that indicates for how many columns the cell extends. Its default value is `1`. Values higher than 1000 will be considered as incorrect and will be set to the default value (1).
+ - : Contains a non-negative integer value that indicates how many columns the data cell spans or extends. The default value is `1`. User agents dismiss values higher than 1000 as incorrect, setting to the default value (`1`).
- `headers`
- - : This attribute contains a list of space-separated strings, each corresponding to the **id** attribute of the {{HTMLElement("th")}} elements that apply to this element.
+ - : Contains a list of space-separated strings, each corresponding to the `id` attribute of the {{HTMLElement("th")}} elements that provide headings for this table cell.
- `rowspan`
- - : This attribute contains a non-negative integer value that indicates for how many rows the cell extends. Its default value is `1`; if its value is set to `0`, it extends until the end of the table section ({{HTMLElement("thead")}}, {{HTMLElement("tbody")}}, {{HTMLElement("tfoot")}}, even if implicitly defined), that the cell belongs to. Values higher than 65534 are clipped down to 65534.
+ - : Contains a non-negative integer value that indicates for how many rows the data cell spans or extends. The default value is `1`; if its value is set to `0`, it extends until the end of the table grouping section ({{HTMLElement("thead")}}, {{HTMLElement("tbody")}}, {{HTMLElement("tfoot")}}, even if implicitly defined), that the cell belongs to. Values higher than `65534` are clipped to `65534`.
### Deprecated attributes
-- `abbr` {{deprecated_inline}}
+The following attributes are deprecated and should not be used. They are documented below for reference when updating existing code and for historical interest only.
- - : This attribute contains a short abbreviated description of the cell's content. Some user-agents, such as speech readers, may present this description before the content itself.
+- `abbr` {{deprecated_inline}}
- > **Note:** Do not use this attribute as it is obsolete in the latest standard. Alternatively, you can put the abbreviated description inside the cell and place the long content in the **title** attribute.
+ - : Contains a short abbreviated description of the data cell's content. Some user-agents, such as speech readers, may present this description before the content itself. Put the abbreviated content inside the cell and place the (longer) description in the [`title`](/en-US/docs/Web/HTML/Global_attributes/title) attribute, as this attribute is deprecated. Or, preferably, include the content within the data cell, and use CSS to [visually clip overflowing text](/en-US/docs/Web/CSS/text-overflow).
- `align` {{deprecated_inline}}
- - : This [enumerated](/en-US/docs/Glossary/Enumerated) attribute specifies how the cell content's horizontal alignment will be handled. Possible values are:
+ - : Specifies the horizontal alignment of the data cell. The possible {{Glossary("enumerated")}} values are `left`, `center`, `right`, `justify`, and `char`. When supported, the `char` value aligns the textual content on the character defined in the [`char`](#char) attribute and the offset defined by the [`charoff`](#charoff) attribute. Use the {{cssxref("text-align")}} CSS property instead, as this attribute is deprecated.
- - `left`: The content is aligned to the left of the cell.
- - `center`: The content is centered in the cell.
- - `right`: The content is aligned to the right of the cell.
- - `justify` (with text only): The content is stretched out inside the cell so that it covers its entire width.
- - `char` (with text only): The content is aligned to a character inside the ` | ` element with minimal offset. This character is defined by the [`char`](#char) and [`charoff`](#charoff) attributes.
-
- The default value when this attribute is not specified is `left`.
+- `axis` {{deprecated_inline}}
- > **Note:**
- >
- > - To achieve the same effect as the `left`, `center`, `right` or `justify` values, apply the CSS {{cssxref("text-align")}} property to the element.
- > - To achieve the same effect as the `char` value, give the {{cssxref("text-align")}} property the same value you would use for the [`char`](#char).
+ - : Contains a list of space-separated strings, each corresponding to the `id` attribute of a group of cells that the data cell applies to.
-- `axis` {{deprecated_inline}}
- - : This attribute contains a list of space-separated strings. Each string is the `id` of a group of cells that this header applies to.
- `bgcolor` {{deprecated_inline}}
- - : This attribute defines the background color of each cell in a column. It is a [6-digit hexadecimal RGB code](/en-US/docs/Web/CSS/hex-color), prefixed by a '`#`'. One of the predefined [color keywords](/en-US/docs/Web/CSS/named-color) can also be used.
-
- To achieve a similar effect, use the CSS {{cssxref("background-color")}} property.
+ - : Defines the background color of the data cell. The value is an HTML color; either a [6-digit hexadecimal RGB code](/en-US/docs/Web/CSS/hex-color), prefixed by a '`#`', or a [color keyword](/en-US/docs/Web/CSS/named-color). Other CSS {{cssxref("color_value", "<color>")}} values are not supported. Use the {{cssxref("background-color")}} CSS property instead, as this attribute is deprecated.
- `char` {{deprecated_inline}}
- - : The content in the cell element is aligned to a character. Typical values include a period (.) to align numbers or monetary values. If [`align`](#align) is not set to `char`, this attribute is ignored.
+
+ - : Specifies the alignment of the content to a character of the data cell. Typical values for this include a period (`.`) when attempting to align numbers or monetary values. If [`align`](#align) is not set to `char`, this attribute is ignored.
+
- `charoff` {{deprecated_inline}}
- - : This attribute is used to shift column data to the right of the character specified by the **char** attribute. Its value specifies the length of this shift.
+
+ - : Specifies the number of characters to offset the data cell content from the alignment character specified by the [`char`](#char) attribute.
+
- `height` {{deprecated_inline}}
- - : This attribute is used to define a recommended cell height. Use the CSS {{cssxref("height")}} property instead.
+
+ - : Defines a recommended data cell height. Use the {{cssxref("height")}} CSS property instead, as this attribute is deprecated.
+
- `scope` {{deprecated_inline}}
- - : This enumerated attribute defines the cells that the header (defined in the {{HTMLElement("th")}}) element relates to. Only use this attribute with the ` | ` element to define the row or column for which it is a header.
-- `valign` {{deprecated_inline}}
- - : This attribute specifies how a text is vertically aligned inside a cell. Possible values for this attribute are:
+ - : Defines the cells that the header (defined in the {{HTMLElement("th")}}) element relates to. The possible {{Glossary("enumerated")}} values are `row`, `col`, `rowgroup`, and `colgroup`. Only use this attribute with the {{HTMLElement("th")}} element to define the row or column for which it is a header, as this attribute is deprecated for the ` | ` element.
- - `baseline`: Positions the text near the bottom of the cell and aligns it with the [baseline](https://en.wikipedia.org/wiki/Baseline_%28typography%29) of the characters instead of the bottom. If characters don't descend below the baseline, the baseline value achieves the same effect as `bottom`.
- - `bottom`: Positions the text near the bottom of the cell.
- - `middle`: Centers the text in the cell.
- - and `top`: Positions the text near the top of the cell.
+- `valign` {{deprecated_inline}}
- To achieve a similar effect, use the CSS {{cssxref("vertical-align")}} property.
+ - : Specifies the vertical alignment of the data cell. The possible {{Glossary("enumerated")}} values are `baseline`, `bottom`, `middle`, and `top`. Use the {{cssxref("vertical-align")}} CSS property instead, as this attribute is deprecated.
- `width` {{deprecated_inline}}
- - : This attribute is used to define a recommended cell width. Use the CSS {{cssxref("width")}} property instead.
+
+ - : Defines a recommended data cell width. Use the {{cssxref("width")}} CSS property instead, as this attribute is deprecated.
+
+## Usage notes
+
+- The ` | ` may only be used within a {{HTMLElement("tr")}} element.
+- When using the [`colspan`](#colspan) and [`rowspan`](#rowspan) attributes to span data cells across multiple columns and rows, cells without these attributes defined (with a default value of `1`) are automatically fitted into free available spaces in the table structure that span 1x1 cells, as illustrated in the following figure:
+
+ ![Illustration demonstrating column and row spanning of table cells: cells 1, 3, and 4 spanning two rows; cell 2 spanning two columns; cells 5 and 6 fitting into the available cells that are the second and third columns in the second row](column-row-span.png)
+
+ > **Note:** These attributes must not be used to overlap cells.
## Examples
-See {{HTMLElement("table")}} for examples on ` | `.
+See {{HTMLElement("table")}} for a complete table example introducing common standards and best practices.
+
+### Basic data cells
+
+This example uses ` | ` elements along with other table-related elements to introduce a basic table with data about the phonetic alphabet.
+
+#### HTML
+
+Some table rows ({{HTMLElement("tr")}} elements) contain both header cells ({{HTMLElement("th")}} elements) and data cell ` | ` elements. The {{HTMLElement("th")}} element that is the first child of each row forms the first column of the table, with each ` | ` providing the row header for the data cells within that row. Each corresponding ` | ` element contains data aligned with its respective column header and row header cell.
+
+> **Note:** Normally, a table head group with column headers would be implemented to make it easier to understand the information in the columns. The {{HTMLElement("thead")}} and {{HTMLElement("tbody")}} elements would be used to group such rows of headers and data into the respective table head and body sections. This is not implemented in this example to focus on the data cells and reduce the complexity of this example.
+
+```html
+ |
` element) is introduced within the first row ({{HTMLElement("tr")}} element). This creates a fourth column in the table.
+
+Using the [`rowspan`](#rowspan) attribute, the "ABC" cell is spanned across the first three rows of the table. The last data cells of the subsequent rows each span two columns. This is done using the [`colspan`](#colspan) attribute, aligning them correctly within the table structure. Note that an additional row ({{HTMLElement("tr")}} element) is added to the table to illustrate this.
+
+```html
+ |
` elements) and header cells ({{HTMLElement("th")}} elements), using {{HTMLElement("th")}} elements with the [`scope`](/en-US/docs/Web/HTML/Element/th#scope) attribute alone may not be sufficient for assistive technologies, especially screen readers.
+
+#### HTML
+
+To improve the {{Glossary("accessibility", "accessibility")}} of the [previous example](#column_and_row_spanning) and to allow screen readers, for example, to speak the headers associated with each data cell, the [`headers`](#headers) attribute can be introduced along with [`id`](/en-US/docs/Web/HTML/Global_attributes/id) attributes. Each row header cell ({{HTMLElement("th")}} element) associated with the "ABC" data cell, i.e., the letters "A", "B", and "C", is given a unique identifier with the [`id`](/en-US/docs/Web/HTML/Global_attributes/id) attribute. The "ABC" data cell (` | ` element) then uses these `id` values in a space-separated list for the [`headers`](#headers) attribute.
+
+> **Note:** It's recommended to use more descriptive and useful values for the [`id`](/en-US/docs/Web/HTML/Global_attributes/id) attribute. Each `id` in a document must be unique to that document. In this example, the `id` values are single characters to maintain focus on the concept of the [`headers`](#headers) attribute.
+
+```html
+ |
`) is now explicitly associated with its row header cell (` | `).
## Technical summary
@@ -143,3 +338,15 @@ See {{HTMLElement("table")}} for examples on ` | `.
## Browser compatibility
{{Compat}}
+
+## See also
+
+- [Learn: HTML tables](/en-US/docs/Learn/HTML/Tables)
+- {{HTMLElement("caption")}}, {{HTMLElement("col")}}, {{HTMLElement("colgroup")}}, {{HTMLElement("table")}}, {{HTMLElement("tbody")}}, {{HTMLElement("tfoot")}}, {{HTMLElement("th")}}, {{HTMLElement("thead")}}, {{HTMLElement("tr")}}: Other table-related elements
+- {{cssxref("background-color")}}: CSS property to set the background color of each data cell
+- {{cssxref("border")}}: CSS property to control borders of data cells
+- {{cssxref("height")}}: CSS property to control the recommended data cell height
+- {{cssxref("text-align")}}: CSS property to horizontally align each data cell content
+- {{cssxref("vertical-align")}}: CSS property to vertically align each data cell content
+- {{cssxref("width")}}: CSS property to control the recommended data cell width
+- {{cssxref(":nth-of-type")}}, {{cssxref(":first-of-type")}}, {{cssxref(":last-of-type")}}: CSS pseudo-classes to select the desired data cells
diff --git a/files/en-us/web/html/element/tfoot/index.md b/files/en-us/web/html/element/tfoot/index.md
index ccdd20ec897a159..0633be60fd23d59 100644
--- a/files/en-us/web/html/element/tfoot/index.md
+++ b/files/en-us/web/html/element/tfoot/index.md
@@ -7,7 +7,7 @@ browser-compat: html.elements.tfoot
{{HTMLSidebar}}
-The **` | `** [HTML](/en-US/docs/Web/HTML) element defines a set of rows summarizing the columns of the table.
+The **``** [HTML](/en-US/docs/Web/HTML) element encapsulates a set of table rows ({{HTMLElement("tr")}} elements), indicating that they comprise the foot of a table with information about the table's columns. This is usually a summary of the columns, e.g., a sum of the given numbers in a column.
{{EmbedInteractiveExample("pages/tabbed/tfoot.html","tabbed-taller")}}
@@ -21,45 +21,134 @@ The following attributes are deprecated and should not be used. They are documen
- `align` {{deprecated_inline}}
- - : This [enumerated](/en-US/docs/Glossary/Enumerated) attribute specifies how horizontal alignment of each cell content will be handled. Possible values are:
+ - : Specifies the horizontal alignment of each foot cell. The possible {{Glossary("enumerated")}} values are `left`, `center`, `right`, `justify`, and `char`. When supported, the `char` value aligns the textual content on the character defined in the [`char`](#char) attribute and on offset defined by the [`charoff`](#charoff) attribute. Use the {{cssxref("text-align")}} CSS property instead, as this attribute is deprecated.
- - `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`](#char) and [`charoff`](#charoff) attributes.
+- `bgcolor` {{deprecated_inline}}
- If this attribute is not set, the `left` value is assumed.
+ - : Defines the background color of each foot cell. The value is an HTML color; either a [6-digit hexadecimal RGB code](/en-US/docs/Web/CSS/hex-color), prefixed by a '`#`', or a [color keyword](/en-US/docs/Web/CSS/named-color). Other CSS {{cssxref("color_value", "<color>")}} values are not supported. Use the {{cssxref("background-color")}} CSS property instead, as this attribute is deprecated.
- > **Note:**
- >
- > - 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 CSS, you can use the value of the [`char`](#char) as the value of the {{cssxref("text-align")}} property.
+- `char` {{deprecated_inline}}
-- `bgcolor` {{Deprecated_inline}}
+ - : Specifies the alignment of the content to a character of each foot cell. Typical values for this include a period (`.`) when attempting to align numbers or monetary values. If [`align`](#align) is not set to `char`, this attribute is ignored.
- - : The background color of the table. It is a [6-digit hexadecimal RGB code](/en-US/docs/Web/CSS/hex-color), prefixed by a '`#`'. One of the predefined [color keywords](/en-US/docs/Web/CSS/named-color) can also be used.
+- `charoff` {{deprecated_inline}}
- To achieve a similar effect, use the CSS {{cssxref("background-color")}} property.
+ - : Specifies the number of characters to offset the foot cell content from the alignment character specified by the [`char`](#char) attribute.
-- `char` {{deprecated_inline}}
- - : This attribute specifies the alignment of the content in a column to a character. Typical values for this include a period (.) when attempting to align numbers or monetary values. If [`align`](#align) is not set to `char`, this attribute is ignored.
-- `charoff` {{deprecated_inline}}
- - : This attribute is used to indicate the number of characters to offset the column data from the alignment characters specified by the `char` attribute.
- `valign` {{deprecated_inline}}
- - : This attribute specifies the vertical alignment of the text within each row of cells of the table footer. Possible values for this attribute are:
+ - : Specifies the vertical alignment of each foot cell. The possible {{Glossary("enumerated")}} values are `baseline`, `bottom`, `middle`, and `top`. Use the {{cssxref("vertical-align")}} CSS property instead, as this attribute is deprecated.
+
+## Usage notes
+
+- The `` is placed after any {{HTMLElement("caption")}}, {{HTMLElement("colgroup")}}, {{HTMLElement("thead")}}, {{HTMLElement("tbody")}}, and {{HTMLElement("tr")}} elements.
+- Along with its related {{HTMLElement("thead")}} and {{HTMLElement("tbody")}} elements, the `` element provides useful {{Glossary("semantics", "semantic")}} information and can be used when rendering for either screen or print. Specifying such table content groups also provides valuable contextual information for assistive technologies, including screen readers and search engines.
+- When printing a document, in the case of a multipage table, the table foot usually specifies information that is output as an intermediate summary on each page.
- - `baseline`, which will put the text as close to the bottom of the cell as it is possible, but align it on the [baseline](https://en.wikipedia.org/wiki/Baseline_%28typography%29) 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;
- - and `top`, which will put the text as close to the top of the cell as it is possible.
+## Example
- > **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 a complete table example introducing common standards and best practices.
-## Examples
+This example demonstrates a table divided into a head section with column headers, a body section with the table's main data, and a foot section summarizing data of one column.
-Please see the {{HTMLElement("table")}} page for examples on ``.
+#### HTML
+
+The {{HTMLElement("thead")}}, {{HTMLElement("tbody")}}, and `` elements are used to structure a basic table into {{Glossary("semantics", "semantic")}} sections. The `` element represents the foot section of the table, which contains a row ({{HTMLElement("tr")}}) representing the calculated average of the values in the "Credits" column.
+
+To allocate the cells in the foot to the correct columns, the [`colspan`](/en-US/docs/Web/HTML/Element/th#colspan) attribute is used on the {{HTMLElement("th")}} element to span row header cell across the first three table columns. The single data cell ({{HTMLElement("td")}}) in the foot is automatically placed in the correct location, i.e., the fourth column, with the omitted [`colspan`](/en-US/docs/Web/HTML/Element/td#colspan) attribute value defaulting to `1`. Additionally, the [`scope`](/en-US/docs/Web/HTML/Element/th#scope) attribute is set to `row` on the header cell ({{HTMLElement("th")}}) in the foot to explicitly define that this foot header cell relates to the table cells within the same row, which in our example is the one data cell in the foot row that contains the calculated average.
+
+```html
+
Originally, in HTML4, the opposite was true: the {{HTMLElement("tfoot")}} element could not be placed after any - {{HTMLElement("tbody")}} or {{HTMLElement("tr")}} - element. + {{HTMLElement("tbody")}}, and {{HTMLElement("tr")}} + elements. Note that this is the requirement in HTML. Originally, in HTML4, the opposite was true: the {{HTMLElement("tfoot")}} element could not be placed after any + {{HTMLElement("tbody")}} and {{HTMLElement("tr")}} + elements.
+
+
+
diff --git a/files/en-us/web/html/element/th/column-row-span.png b/files/en-us/web/html/element/th/column-row-span.png
new file mode 100644
index 000000000000000..a779fb8e844a4e7
Binary files /dev/null and b/files/en-us/web/html/element/th/column-row-span.png differ
diff --git a/files/en-us/web/html/element/th/index.md b/files/en-us/web/html/element/th/index.md
index 01b70c97ceef27d..1bbf6f590229e80 100644
--- a/files/en-us/web/html/element/th/index.md
+++ b/files/en-us/web/html/element/th/index.md
@@ -7,7 +7,7 @@ browser-compat: html.elements.th
{{HTMLSidebar}}
-The **`5
+ 6
+ `** [HTML](/en-US/docs/Web/HTML) element defines a cell as the header of a group of table cells. The exact nature of this group is defined by the [`scope`](#scope) and [`headers`](#headers) attributes.
+The **` | `** [HTML](/en-US/docs/Web/HTML) element defines a cell as the header of a group of table cells and may be used as a child of the {{HTMLElement("tr")}} element. The exact nature of this group is defined by the [`scope`](#scope) and [`headers`](#headers) attributes.
{{EmbedInteractiveExample("pages/tabbed/th.html","tabbed-taller")}}
@@ -16,91 +16,293 @@ The **` | `** [HTML](/en-US/docs/Web/HTML) element defines a cell as the header
This element includes the [global attributes](/en-US/docs/Web/HTML/Global_attributes).
- `abbr`
- - : This attribute contains a short abbreviated description of the cell's content. Some user-agents, such as speech readers, may present this description before the content itself.
+ - : A short, abbreviated description of the header cell's content provided as an alternative label to use for the header cell when referencing the cell in other contexts. Some user-agents, such as speech readers, may present this description before the content itself.
- `colspan`
- - : This attribute contains a non-negative integer value that indicates for how many columns the cell extends. Its default value is `1`. Values higher than 1000 will be considered as incorrect and will be set to the default value (1).
+ - : A non-negative integer value indicating how many columns the header cell spans or extends. The default value is `1`. User agents dismiss values higher than 1000 as incorrect, defaulting such values to `1`.
- `headers`
- - : This attribute contains a list of space-separated strings, each corresponding to the **id** attribute of the {{HTMLElement("th")}} elements that apply to this element.
+ - : A list of space-separated strings corresponding to the `id` attributes of the ` | ` elements that provide the headers for this header cell.
- `rowspan`
- - : This attribute contains a non-negative integer value that indicates for how many rows the cell extends. Its default value is `1`; if its value is set to `0`, it extends until the end of the table section ({{HTMLElement("thead")}}, {{HTMLElement("tbody")}}, {{HTMLElement("tfoot")}}, even if implicitly defined), that the cell belongs to. Values higher than 65534 are clipped down to 65534.
+ - : A non-negative integer value indicating how many rows the header cell spans or extends. The default value is `1`; if its value is set to `0`, the header cell will extends to the end of the table grouping section ({{HTMLElement("thead")}}, {{HTMLElement("tbody")}}, {{HTMLElement("tfoot")}}, even if implicitly defined), that the ` | ` belongs to. Values higher than `65534` are clipped at `65534`.
- `scope`
- - : This [enumerated](/en-US/docs/Glossary/Enumerated) attribute defines the cells that the header (defined in the {{HTMLElement("th")}}) element relates to. It may have the following values:
+ - : Defines the cells that the header (defined in the ` | `) element relates to. Possible {{Glossary("enumerated", "enumerated")}} values are:
- - `row`: The header relates to all cells of the row it belongs to.
- - `col`: The header relates to all cells of the column it belongs to.
- - `rowgroup`: The header belongs to a rowgroup and relates to all of its cells.
- - `colgroup`: The header belongs to a colgroup and relates to all of its cells.
+ - `row`: the header relates to all cells of the row it belongs to;
+ - `col`: the header relates to all cells of the column it belongs to;
+ - `rowgroup`: the header belongs to a rowgroup and relates to all of its cells;
+ - `colgroup`: the header belongs to a colgroup and relates to all of its cells.
- If the `scope` attribute is not specified, or its value is not `row`, `col`, or `rowgroup`, or `colgroup`, then browsers automatically select the set of cells to which the header cell applies.
+ If the `scope` attribute is not specified, or its value is not `row`, `col`, `rowgroup`, or `colgroup`, then browsers automatically select the set of cells to which the header cell applies.
### Deprecated attributes
-- `align` {{deprecated_inline}}
-
- - : This enumerated attribute specifies how the cell content's horizontal alignment will be handled. Possible values are:
+The following attributes are deprecated and should not be used. They are documented below for reference when updating existing code and for historical interest only.
- - `left`: The content is aligned to the left of the cell.
- - `center`: The content is centered in the cell.
- - `right`: The content is aligned to the right of the cell.
- - `justify` (with text only): The content is stretched out inside the cell so that it covers its entire width.
- - `char` (with text only): The content is aligned to a character inside the ` | ` element with minimal offset. This character is defined by the [`char`](#char) and [`charoff`](#charoff) attributes.
-
- The default value when this attribute is not specified is `left`.
+- `align` {{deprecated_inline}}
- > **Note:** Do not use this attribute as it is obsolete in the latest standard.
- >
- > - To achieve the same effect as the `left`, `center`, `right` or `justify` values, apply the CSS {{cssxref("text-align")}} property to the element.
- > - To achieve the same effect as the `char` value, give the {{cssxref("text-align")}} property the same value you would use for the [`char`](#char).
+ - : Specifies the horizontal alignment of the header cell. The possible {{Glossary("enumerated")}} values are `left`, `center`, `right`, `justify`, and `char`. When supported, the `char` value aligns the textual content on the character defined in the [`char`](#char) attribute and the offset defined by the [`charoff`](#charoff) attribute. Use the {{cssxref("text-align")}} CSS property instead, as this attribute is deprecated.
- `axis` {{deprecated_inline}}
- - : This attribute contains a list of space-separated strings. Each string is the `id` of a group of cells that this header applies to.
+ - : Contains a list of space-separated strings, each corresponding to the `id` attribute of a group of cells that the header cell applies to. Use the [`scope`](#scope) attribute instead, as this attribute is deprecated.
- > **Note:** Do not use this attribute as it is obsolete in the latest standard: use the [`scope`](#scope) attribute instead.
+- `bgcolor` {{deprecated_inline}}
-- `bgcolor` {{Deprecated_Inline}}
-
- - : This attribute defines the background color of each cell in a column. It consists of a 6-digit hexadecimal code as defined in [sRGB](https://www.w3.org/Graphics/Color/sRGB) and is prefixed by '#'.
+ - : Defines the background color of the header cell. The value is an HTML color; either a [6-digit hexadecimal RGB code](/en-US/docs/Web/CSS/hex-color), prefixed by a '`#`', or a [color keyword](/en-US/docs/Web/CSS/named-color). Other CSS {{cssxref("color_value", "<color>")}} values are not supported. Use the {{cssxref("background-color")}} CSS property instead, as this attribute is deprecated.
- `char` {{deprecated_inline}}
- - : The content in the cell element is aligned to a character. Typical values include a period (.) to align numbers or monetary values. If [`align`](#align) is not set to `char`, this attribute is ignored.
-
- > **Note:** Do not use this attribute as it is obsolete in the latest standard. To achieve the same effect, you can specify the character as the first value of the {{cssxref("text-align")}} property.
+ - : Specifies the alignment of the content to a character of the header cell. Typical values for this include a period (`.`) when attempting to align numbers or monetary values. If [`align`](#align) is not set to `char`, this attribute is ignored.
- `charoff` {{deprecated_inline}}
- - : This attribute is used to shift column data to the right of the character specified by the **char** attribute. Its value specifies the length of this shift.
-
- > **Note:** Do not use this attribute as it is obsolete in the latest standard.
+ - : Specifies the number of characters to offset the header cell content from the alignment character specified by the [`char`](#char) attribute.
- `height` {{deprecated_inline}}
- - : This attribute is used to define a recommended cell height.
-
- > **Note:** Do not use this attribute as it is obsolete in the latest standard: use the CSS {{cssxref("height")}} property instead.
+ - : Defines a recommended header cell height. Use the {{cssxref("height")}} CSS property instead, as this attribute is deprecated.
- `valign` {{deprecated_inline}}
- - : This attribute specifies how a text is vertically aligned inside a cell. Possible values for this attribute are:
+ - : Specifies the vertical alignment of the header cell. The possible {{Glossary("enumerated")}} values are `baseline`, `bottom`, `middle`, and `top`. Use the {{cssxref("vertical-align")}} CSS property instead, as this attribute is deprecated.
- - `baseline`: Positions the text near the bottom of the cell and aligns it with the [baseline](https://en.wikipedia.org/wiki/Baseline_%28typography%29) of the characters instead of the bottom. If characters don't descend below the baseline, the baseline value achieves the same effect as `bottom`.
- - `bottom`: Positions the text near the bottom of the cell.
- - `middle`: Centers the text in the cell.
- - and `top`: Positions the text near the top of the cell.
+- `width` {{deprecated_inline}}
- > **Note:** Do not use this attribute as it is obsolete in the latest standard: use the CSS {{cssxref("vertical-align")}} property instead.
+ - : Defines a recommended header cell width. Use the {{cssxref("width")}} CSS property instead, as this attribute is deprecated.
-- `width` {{deprecated_inline}}
+## Usage notes
- - : This attribute is used to define a recommended cell width. Additional space can be added with the {{domxref("HTMLTableElement.cellSpacing", "cellspacing")}} and {{domxref("HTMLTableElement.cellPadding", "cellpadding")}} properties and the width of the {{HTMLElement("col")}} element can also create extra width. But, if a column's width is too narrow to show a particular cell properly, it will be widened when displayed.
+- The ` | ` may only be used within a {{HTMLElement("tr")}} element.
+- In simple contexts, using the [`scope`](#scope) attribute on header cells (` | ` elements) is redundant because [`scope`](#scope) is inferred. However, certain assistive technologies may fail to infer correctly, so specifying header scope may improve user experiences.
+- When using the [`colspan`](#colspan) and [`rowspan`](#rowspan) attributes to span header cells across multiple columns and rows, cells without these attributes defined (with a default value of `1`) are automatically fitted into free available spaces in the table structure that span 1x1 cells, as illustrated in the following figure:
- > **Note:** Do not use this attribute as it is obsolete in the latest standard: use the CSS {{cssxref("width")}} property instead.
+ ![Illustration demonstrating column and row spanning of table cells: cells 1, 3, and 4 spanning two rows; cell 2 spanning two columns; cells 5 and 6 fitting into the available cells that are the second and third columns in the second row](column-row-span.png)
+
+ > **Note:** These attributes must not be used to overlap cells.
## Examples
-See {{HTMLElement("table")}} for examples on ` | `.
+See {{HTMLElement("table")}} for a complete table example introducing common standards and best practices.
+
+### Basic column and row headers
+
+This example uses ` | ` elements to introduce column and row headers in a basic table structure.
+
+#### HTML
+
+The first row ({{HTMLElement("tr")}} element) contains the column headers (` | ` elements), which act as "titles" for the columns to make it easier to understand the information in the columns and identify the data. To indicate that each column header relates to all cells in the corresponding column, the [`scope`](#scope) attribute is set to `col` (column).
+
+The remaining rows contain the main data of the table. Each of these rows has a row header (` | ` element) introduced as the first cell. This creates a column with row headers as the first column of the table. Similar to the column headers, the [`scope`](#scope) attribute is set to `row` to specify which cells each row header relates to, which in the example below are all data cells ({{HTMLElement("td")}} elements) in each `row`.
+
+> **Note:** Normally, the grouping elements {{HTMLElement("thead")}} and {{HTMLElement("tbody")}} are used to group rows with headers into the respective table head and body sections. These elements are ommitted in this example to reduce complexity and enable focusing on the use of header cells.
+
+```html
+ |
` elements) and differentiating them each other and from the data cells ({{HTMLElement("td")}}).
+
+```css
+th,
+td {
+ border: 1px solid rgb(160 160 160);
+ padding: 8px 10px;
+}
+
+th[scope="col"] {
+ background-color: #505050;
+ color: #fff;
+}
+
+th[scope="row"] {
+ background-color: #d6ecd4;
+}
+
+tr:nth-of-type(odd) td {
+ background-color: #eee;
+}
+```
+
+```css hidden
+table {
+ border-collapse: collapse;
+ border: 2px solid rgb(140 140 140);
+ font-family: sans-serif;
+ font-size: 0.8rem;
+ letter-spacing: 1px;
+}
+```
+
+#### Result
+
+{{EmbedLiveSample("Basic_column_and_row_headers", 650, 170)}}
+
+### Column and row spanning
+
+This example extends and enhances the basic table from the [previous example](#basic_column_and_row_headers) by adding a second row for additional column headers.
+
+#### HTML
+
+An additional table row ({{HTMLElement("tr")}} element) is added as the second header row of the table with two additional column headers (` | ` elements). In this way, the "Pronunciation" column is split into two columns, one for the IPA (International Phonetic Alphabet) notation and one for the respelling (the original pronunciation column). The corresponding data cells ({{HTMLElement("td")}} elements) are added to each subsequent row.
+
+As shown in the [usage notes](#usage_notes), the [`colspan`](#colspan) and [`rowspan`](#rowspan) attributes can be used for the ` | ` elements to allocate the header cells to the correct columns and rows. To achieve a "two-row" header in the table structure, the first two header cells within the first {{HTMLElement("tr")}} element are spanned across two rows. The third header cell is spanned two columns wide (remaining in the first row). This setup leaves two available areas in the third and fourth columns in the second row, where the two headers within the second {{HTMLElement("tr")}} element are automatically placed, with the default value being `1` for the [`colspan`](#colspan) and [`rowspan`](#rowspan) attributes.
+
+> **Note:** Normally, {{HTMLElement("thead")}} and {{HTMLElement("tbody")}} elements are used to group rows with headers into the respective table head and body sections. This is not implemented in this example to focus on the headers and spanning and reduce the example's complexity.
+
+```html
+ |
`.
## See also
-- Other table-related HTML Elements: {{HTMLElement("caption")}}, {{HTMLElement("col")}}, {{HTMLElement("colgroup")}}, {{HTMLElement("table")}}, {{HTMLElement("tbody")}}, {{HTMLElement("td")}}, {{HTMLElement("tfoot")}}, {{HTMLElement("thead")}}, {{HTMLElement("tr")}}.
+- [Learn: HTML tables](/en-US/docs/Learn/HTML/Tables)
+- {{HTMLElement("caption")}}, {{HTMLElement("col")}}, {{HTMLElement("colgroup")}}, {{HTMLElement("table")}}, {{HTMLElement("tbody")}}, {{HTMLElement("td")}}, {{HTMLElement("tfoot")}}, {{HTMLElement("thead")}}, {{HTMLElement("tr")}}: Other table-related elements
+- {{cssxref("background-color")}}: CSS property to set the background color of each header cell
+- {{cssxref("border")}}: CSS property to control borders of header cells
+- {{cssxref("height")}}: CSS property to control the recommended header cell height
+- {{cssxref("text-align")}}: CSS property to horizontally align each header cell content
+- {{cssxref("vertical-align")}}: CSS property to vertically align each header cell content
+- {{cssxref("width")}}: CSS property to control the recommended header cell width
+- {{cssxref(":nth-of-type")}}, {{cssxref(":first-of-type")}}, {{cssxref(":last-of-type")}}: CSS pseudo-classes to select the desired header cells
diff --git a/files/en-us/web/html/element/thead/column-row-span.html b/files/en-us/web/html/element/thead/column-row-span.html
new file mode 100644
index 000000000000000..796d0f6595a12a3
--- /dev/null
+++ b/files/en-us/web/html/element/thead/column-row-span.html
@@ -0,0 +1,163 @@
+
+
+
+
+
+ |
+
+
+
diff --git a/files/en-us/web/html/element/thead/column-row-span.png b/files/en-us/web/html/element/thead/column-row-span.png
new file mode 100644
index 000000000000000..a779fb8e844a4e7
Binary files /dev/null and b/files/en-us/web/html/element/thead/column-row-span.png differ
diff --git a/files/en-us/web/html/element/thead/index.md b/files/en-us/web/html/element/thead/index.md
index f5fdb768511fd52..574891f1c965bf8 100644
--- a/files/en-us/web/html/element/thead/index.md
+++ b/files/en-us/web/html/element/thead/index.md
@@ -7,7 +7,7 @@ browser-compat: html.elements.thead
{{HTMLSidebar}}
-The **``** [HTML](/en-US/docs/Web/HTML) element defines a set of rows defining the head of the columns of the table.
+The **``** [HTML](/en-US/docs/Web/HTML) element encapsulates a set of table rows ({{HTMLElement("tr")}} elements), indicating that they comprise the head of a table with information about the table's columns. This is usually in the form of column headers ({{HTMLElement("th")}} elements).
{{EmbedInteractiveExample("pages/tabbed/thead.html","tabbed-taller")}}
@@ -17,54 +17,213 @@ This element includes the [global attributes](/en-US/docs/Web/HTML/Global_attrib
### Deprecated attributes
+The following attributes are deprecated and should not be used. They are documented below for reference when updating existing code and for historical interest only.
+
- `align` {{deprecated_inline}}
- - : This [enumerated](/en-US/docs/Glossary/Enumerated) attribute specifies how horizontal alignment of each cell content will be handled. Possible values are:
+ - : Specifies the horizontal alignment of each head cell. The possible {{Glossary("enumerated")}} values are `left`, `center`, `right`, `justify`, and `char`. When supported, the `char` value aligns the textual content on the character defined in the [`char`](#char) attribute and the offset defined by the [`charoff`](#charoff) attribute. Use the {{cssxref("text-align")}} CSS property instead, as this attribute is deprecated.
- - `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`](#char) and [`charoff`](#charoff) attributes.
+- `bgcolor` {{deprecated_inline}}
- If this attribute is not set, the `left` value is assumed.
+ - : Defines the background color of each head cell. The value is an HTML color; either a [6-digit hexadecimal RGB code](/en-US/docs/Web/CSS/hex-color), prefixed by a '`#`', or a [color keyword](/en-US/docs/Web/CSS/named-color). Other CSS {{cssxref("color_value", "<color>")}} values are not supported. Use the {{cssxref("background-color")}} CSS property instead, as this attribute is deprecated.
- > **Warning:** Do not use this attribute as it is obsolete (not supported) in the latest standard.
- >
- > - To align values, use the CSS {{cssxref("text-align")}} property instead.
+- `char` {{deprecated_inline}}
-- `bgcolor` {{Deprecated_Inline}}
+ - : Specifies the alignment of the content to a character of each head cell. If [`align`](#align) is not set to `char`, this attribute is ignored.
- - : This attribute defines the background color of each column cell. It accepts a 6-digit hexadecimal color or a named color. Alpha transparency is not supported.
+- `charoff` {{deprecated_inline}}
- > **Note:** Do not use this attribute, as it is non-standard. The `thead` element should be styled using the CSS {{cssxref("background-color")}} property, which can be applied to any element, including the `thead`, {{HTMLElement("tr")}}, {{HTMLElement("td")}} and {{HTMLElement("th")}} elements.
+ - : Specifies the number of characters to offset the head cell content from the alignment character specified by the [`char`](#char) attribute.
-- `char` {{deprecated_inline}}
+- `valign` {{deprecated_inline}}
- - : 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`](#align) is not set to `char`, this attribute is ignored.
+ - : Specifies the vertical alignment of each head cell. The possible {{Glossary("enumerated")}} values are `baseline`, `bottom`, `middle`, and `top`. Use the {{cssxref("vertical-align")}} CSS property instead, as this attribute is deprecated.
- > **Note:** Do not use this attribute as it is obsolete (and not supported) in the latest standard.
+## Usage notes
-- `charoff` {{deprecated_inline}}
+- The `` is placed after any {{HTMLElement("caption")}} and {{HTMLElement("colgroup")}} elements, but before any {{HTMLElement("tbody")}}, {{HTMLElement("tfoot")}}, and {{HTMLElement("tr")}} elements.
+- Along with its related {{HTMLElement("tbody")}} and {{HTMLElement("tfoot")}} elements, the `` element provides useful {{Glossary("semantics", "semantic")}} information and can be used when rendering for either screen or print. Specifying such table content groups also provides valuable contextual information for assistive technologies, including screen readers and search engines.
+- When printing a document, in the case of a multipage table, the table head usually specifies information that remains the same on each page.
- - : This attribute is used to indicate the number of characters to offset the column data from the alignment characters specified by the **char** attribute.
+## Examples
- > **Note:** Do not use this attribute as it is obsolete (and not supported) in the latest standard.
+See {{HTMLElement("table")}} for a complete table example introducing common standards and best practices.
-- `valign` {{deprecated_inline}}
+### Basic head structure
- - : This attribute specifies the vertical alignment of the text within each row of cells of the table header. Possible values for this attribute are:
+This example demonstrates a table divided into a head section with column headers and a body section with the table's main data.
- - `baseline`, which will put the text as close to the bottom of the cell as it is possible, but align it on the [baseline](https://en.wikipedia.org/wiki/Baseline_%28typography%29) 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.
+#### HTML
- > **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.
+The `` and {{HTMLElement("tbody")}} elements are used to structure the table rows into {{Glossary("semantics", "semantic")}} sections. The `` element represents the head section of the table, which contains a row ({{HTMLElement("tr")}}) of column headers cells ({{HTMLElement("th")}}).
-## Examples
+```html
+5
+ 6
+
A {{HTMLElement("table")}} element. The
{{HTMLElement("thead")}} must appear after any
- {{HTMLElement("caption")}} or
- {{HTMLElement("colgroup")}} element, even implicitly defined,
+ {{HTMLElement("caption")}} and
+ {{HTMLElement("colgroup")}} elements, even implicitly defined,
but before any {{HTMLElement("tbody")}},
- {{HTMLElement("tfoot")}} and {{HTMLElement("tr")}}
- element.
+ {{HTMLElement("tfoot")}}, and {{HTMLElement("tr")}}
+ elements.
|
` and ` | ` support the [`colspan`](/en-US/docs/Web/HTML/Element/td#colspan) attribute, which lets you specify how many columns wide the cell should be, with the default being 1. Similarly, you can use the [`rowspan`](/en-US/docs/Web/HTML/Element/td#rowspan) attribute on cells to indicate they should span more than one table row.
-
-This can take a little practice to get right when building your tables. We have some [examples](#examples) below, but for more examples and an in-depth tutorial, see the [HTML tables](/en-US/docs/Learn/HTML/Tables) series in our [Learn web development](/en-US/docs/Learn) area, where you'll learn how to use the table elements and their attributes to get just the right layout and formatting for your tabular data.
-
## Attributes
-This element includes the [global attributes](/en-US/docs/Web/HTML/Global_attributes). There are also several [deprecated attributes](#deprecated_attributes), which you should avoid but may need to know when reading older code.
+This element includes the [global attributes](/en-US/docs/Web/HTML/Global_attributes).
### Deprecated attributes
-The following attributes may still be implemented in browsers but are no longer part of the HTML specification and may be missing or may not work as expected. They should be avoided.
+The following attributes are deprecated and should not be used. They are documented below for reference when updating existing code and for historical interest only.
- `align` {{deprecated_inline}}
- - : A string which specifies how the cell's context should be aligned horizontally within the cells in the row; this is shorthand for using `align` on every cell in the row individually. Possible values are:
-
- - `left`
- - : Align the content of each cell at its left edge.
- - `center`
- - : Center the contents of each cell between their left and right edges.
- - `right`
- - : Align the content of each cell at its right edge.
- - `justify`
- - : Widen whitespaces within the text of each cell so that the text fills the full width of each cell (full justification).
- - `char`
- - : Align each cell in the row on a specific character (such that each row in the column that is configured this way will horizontally align its cells on that character). This uses the [`char`](#char) and [`charoff`](#charoff) to establish the alignment character (typically "." or "," when aligning numerical data) and the number of characters that should follow the alignment character. This alignment type was never widely supported.
-
- If no value is expressly set for `align`, the parent node's value is inherited.
-
- > **Note:** Instead of using the obsolete `align` attribute, you should instead use the CSS {{CSSxRef("text-align")}} property to establish `left`, `center`, `right`, or `justify` alignment for the row's cells. To apply character-based alignment, set the CSS {{CSSxRef("text-align")}} property to the alignment character (such as `"."` or `","`).
+ - : Specifies the horizontal alignment of each row cell. The possible {{Glossary("enumerated")}} values are `left`, `center`, `right`, `justify`, and `char`. When supported, the `char` value aligns the textual content on the character defined in the [`char`](#char) attribute and on offset defined by the [`charoff`](#charoff) attribute. Use the {{cssxref("text-align")}} CSS property instead, as this attribute is deprecated.
- `bgcolor` {{deprecated_inline}}
- - : A string specifying a color to apply to the backgrounds of each of the row's cells. This can be either a [hexadecimal `#RRGGBB` or `#RGB` value](/en-US/docs/Web/CSS/color_value/rgb) or a [color keyword](/en-US/docs/Web/CSS/named-color). Omitting the attribute or setting it to `null` in JavaScript causes the row's cells to inherit the row's parent element's background color.
-
- > **Note:** The {{HTMLElement("tr")}} element should be styled using [CSS](/en-US/docs/Web/CSS). To give a similar effect as the `bgcolor` attribute, use the CSS property {{CSSxRef("background-color")}}.
+ - : Defines the background color of each row cell. The value is an HTML color; either a [6-digit hexadecimal RGB code](/en-US/docs/Web/CSS/hex-color), prefixed by a '`#`', or a [color keyword](/en-US/docs/Web/CSS/named-color). Other CSS {{cssxref("color_value", "<color>")}} values are not supported. Use the {{cssxref("background-color")}} CSS property instead, as this attribute is deprecated.
- `char` {{deprecated_inline}}
- - : A string that sets the character to align the cells in each row's columns (each row's centering that uses the same character gets aligned with others using the same character. Typical values for this include a period (`"."`) or comma (`","`) when attempting to align numbers or monetary values. If [`align`](#align) is not set to `char`, this attribute is ignored.
-
- > **Note:** This attribute is obsolete and rarely implemented anyway. To achieve the same effect as the [`char`](#char) attribute, set the CSS {{CSSxRef("text-align")}} property to the same string you would specify for the `char` property, such as `text-align: "."`.
+ - : Specifies the alignment of the content to a character of each row cell. Typical values for this include a period (`.`) when attempting to align numbers or monetary values. If [`align`](#align) is not set to `char`, this attribute is ignored.
- `charoff` {{deprecated_inline}}
- - : A string indicating the number of characters on the tail end of the column's data should be displayed after the alignment character specified by the `char` attribute. For example, when displaying money values for currencies that use hundredths of a unit (such as the dollar, which is divided into 100 cents), you would typically specify a value of 2, so that in tandem with `char` being set to `"."`, the values in a column would be cleanly aligned on the decimal points, with the number of cents properly displayed to the right of the decimal point.
-
- > **Note:** This attribute is obsolete, and was never widely supported anyway.
+ - : Specifies the number of characters to offset the row cell content from the alignment character specified by the [`char`](#char) attribute.
- `valign` {{deprecated_inline}}
- - : A string specifying the vertical alignment of the text within each cell in the row. Possible values for this attribute are:
+ - : Specifies the vertical alignment of each row cell. The possible {{Glossary("enumerated")}} values are `baseline`, `bottom`, `middle`, and `top`. Use the {{cssxref("vertical-align")}} CSS property instead, as this attribute is deprecated.
- - `baseline`
- - : Aligns each cell's content text as closely as possible to the bottom of the cell, handling alignment of different fonts and font sizes by aligning the characters along the [baseline](https://en.wikipedia.org/wiki/Baseline) of the font(s) used in the row. If all the characters in the row are the same size, the effect is the same as `bottom`.
- - `bottom`,
- - : Draws the text in each of the row's cells as closely as possible to the bottom edge of those cells.
- - `middle`
- - : Each cell's text is vertically centered.
- - `top`
- - : Each cell's text is drawn as closely as possible to the top edge of the containing cell.
+## Usage notes
- > **Note:** Don't use the obsolete `valign` attribute. Instead, add the CSS {{CSSxRef("vertical-align")}} property to the row.
+- The ` |
`) within this head row to explicitly specify that each header cell relates to all the cells within its own column, even though those cells are in the {{HTMLElement("tbody")}}.
```html
|
|
---|