メインコンテンツへスキップ

table要素


1.仕様

TABLE要素は、
複数のディメンションを
持つデータを
表の形式で表します。

TABLE - - (caption?,colgroup*,thead?,(tbody|tr)*,tfoot?) +(%Scriptsupporting) -- table element. (Normal elements.) [Flow|Palpable] --

table

表 (table element)

種類

通常要素

カテゴリ

コンテンツモデル
0または1つの<caption>要素と、それに続く0個以上の<colgroup>要素と、それに続く0または1つの<thead>要素と、それに続く<tbody>要素または<tr>要素と、それに続く0または1つの<tfoot>要素 オプションでスクリプトをサポートする要素が混在

0または1つの<caption>要素と、それに続く0個以上の<colgroup>要素と、それに続く0または1つの<thead>要素と、それに続く<tbody>要素または<tr>要素と、それに続く0または1つの<tfoot>要素が配置できます。オプションで、スクリプトをサポートする要素を混在して配置できます。

スクリプトをサポートする要素に分類される要素は、<script>要素, <template>要素 です。

タグの省略

どちらのタグも省略できません。

コンテンツ属性

グローバル属性のみ

DOM インターフェイス
HTMLTableElement
  1. [Exposed=Window]
  2. interface HTMLTableElement : HTMLElement {
  3. lastReviewed;
  4. [HTMLConstructor] constructor();
  5.  
  6. [CEReactions] attribute HTMLTableCaptionElement? caption;
  7. HTMLTableCaptionElement createCaption();
  8. [CEReactions] undefined deleteCaption();
  9. [CEReactions] attribute HTMLTableSectionElement? tHead;
  10. HTMLTableSectionElement createTHead();
  11. [CEReactions] undefined deleteTHead();
  12. [CEReactions] attribute HTMLTableSectionElement? tFoot;
  13. HTMLTableSectionElement createTFoot();
  14. [CEReactions] undefined deleteTFoot();
  15. [SameObject] readonly attribute HTMLCollection tBodies;
  16. HTMLTableSectionElement createTBody();
  17. [SameObject] readonly attribute HTMLCollection rows;
  18. HTMLTableRowElement insertRow(optional long index = -1);
  19. [CEReactions] undefined deleteRow(long index);
  20.  
  21. // also has obsolete members
  22. };
HTMLElement
  1. [Exposed=Window]
  2. interface HTMLElement : Element {
  3. [HTMLConstructor] constructor();
  4.  
  5. // metadata attributes
  6. [CEReactions] attribute DOMString title;
  7. [CEReactions] attribute DOMString lang;
  8. [CEReactions] attribute boolean translate;
  9. [CEReactions] attribute DOMString dir;
  10.  
  11. // user interaction
  12. [CEReactions] attribute (boolean or unrestricted double or DOMString)? hidden;
  13. [CEReactions] attribute DOMString inert;
  14. undefined click();
  15. [CEReactions] attribute DOMString accessKey;
  16. readonly attribute DOMString accessKeyLabel;
  17. [CEReactions] attribute boolean draggable;
  18. [CEReactions] attribute boolean spellcheck;
  19. [CEReactions] attribute DOMString writingSuggestions;
  20. [CEReactions] attribute DOMString autocapitalize;
  21.  
  22. [CEReactions] attribute [LegacyNullToEmptyString] DOMString innerText;
  23. [CEReactions] attribute [LegacyNullToEmptyString] DOMString outerText;
  24.  
  25. ElementInternals attachInternals();
  26.  
  27. // The popover API
  28. undefined showPopover();
  29. undefined hidePopover();
  30. boolean togglePopover(optional boolean force);
  31. [CEReactions] attribute DOMString? popover;
  32. };
  33.  
  34. HTMLElement includes GlobalEventHandlers;
  35. HTMLElement includes ElementContentEditable;
  36. HTMLElement includes HTMLOrSVGElement;
Element
  1. [Exposed=Window]
  2. interface Element : Node {
  3. readonly attribute DOMString? namespaceURI;
  4. readonly attribute DOMString? prefix;
  5. readonly attribute DOMString localName;
  6. readonly attribute DOMString tagName;
  7.  
  8. [CEReactions] attribute DOMString id;
  9. [CEReactions] attribute DOMString className;
  10. [SameObject, PutForwards=value] readonly attribute DOMTokenList classList;
  11. [CEReactions, Unscopable] attribute DOMString slot;
  12.  
  13. boolean hasAttributes();
  14. [SameObject] readonly attribute NamedNodeMap attributes;
  15. sequence<DOMString> getAttributeNames();
  16. DOMString? getAttribute(DOMString qualifiedName);
  17. DOMString? getAttributeNS(DOMString? namespace, DOMString localName);
  18. [CEReactions] undefined setAttribute(DOMString qualifiedName, DOMString value);
  19. [CEReactions] undefined setAttributeNS(DOMString? namespace, DOMString qualifiedName, DOMString value);
  20. [CEReactions] undefined removeAttribute(DOMString qualifiedName);
  21. [CEReactions] undefined removeAttributeNS(DOMString? namespace, DOMString localName);
  22. [CEReactions] boolean toggleAttribute(DOMString qualifiedName, optional boolean force);
  23. boolean hasAttribute(DOMString qualifiedName);
  24. boolean hasAttributeNS(DOMString? namespace, DOMString localName);
  25.  
  26. Attr? getAttributeNode(DOMString qualifiedName);
  27. Attr? getAttributeNodeNS(DOMString? namespace, DOMString localName);
  28. [CEReactions] Attr? setAttributeNode(Attr attr);
  29. [CEReactions] Attr? setAttributeNodeNS(Attr attr);
  30. [CEReactions] Attr removeAttributeNode(Attr attr);
  31.  
  32. ShadowRoot attachShadow(ShadowRootInit init);
  33. readonly attribute ShadowRoot? shadowRoot;
  34.  
  35. Element? closest(DOMString selectors);
  36. boolean matches(DOMString selectors);
  37. boolean webkitMatchesSelector(DOMString selectors); // legacy alias of .matches
  38.  
  39. HTMLCollection getElementsByTagName(DOMString qualifiedName);
  40. HTMLCollection getElementsByTagNameNS(DOMString? namespace, DOMString localName);
  41. HTMLCollection getElementsByClassName(DOMString classNames);
  42.  
  43. [CEReactions] Element? insertAdjacentElement(DOMString where, Element element); // legacy
  44. undefined insertAdjacentText(DOMString where, DOMString data); // legacy
  45. };
GlobalEventHandlers
  1. interface mixin GlobalEventHandlers {
  2. attribute EventHandler onabort;
  3. attribute EventHandler onauxclick;
  4. attribute EventHandler onbeforeinput;
  5. attribute EventHandler onbeforematch;
  6. attribute EventHandler onbeforetoggle;
  7. attribute EventHandler onblur;
  8. attribute EventHandler oncancel;
  9. attribute EventHandler oncanplay;
  10. attribute EventHandler oncanplaythrough;
  11. attribute EventHandler onchange;
  12. attribute EventHandler onclick;
  13. attribute EventHandler onclose;
  14. attribute EventHandler oncontextlost;
  15. attribute EventHandler oncontextmenu;
  16. attribute EventHandler oncontextrestored;
  17. attribute EventHandler oncopy;
  18. attribute EventHandler oncuechange;
  19. attribute EventHandler oncut;
  20. attribute EventHandler ondblclick;
  21. attribute EventHandler ondrag;
  22. attribute EventHandler ondragend;
  23. attribute EventHandler ondragenter;
  24. attribute EventHandler ondragleave;
  25. attribute EventHandler ondragover;
  26. attribute EventHandler ondragstart;
  27. attribute EventHandler ondrop;
  28. attribute EventHandler ondurationchange;
  29. attribute EventHandler onemptied;
  30. attribute EventHandler onended;
  31. attribute OnErrorEventHandler onerror;
  32. attribute EventHandler onfocus;
  33. attribute EventHandler onformdata;
  34. attribute EventHandler oninput;
  35. attribute EventHandler oninvalid;
  36. attribute EventHandler onkeydown;
  37. attribute EventHandler onkeypress;
  38. attribute EventHandler onkeyup;
  39. attribute EventHandler onload;
  40. attribute EventHandler onloadeddata;
  41. attribute EventHandler onloadedmetadata;
  42. attribute EventHandler onloadstart;
  43. attribute EventHandler onmousedown;
  44. [LegacyLenientThis] attribute EventHandler onmouseenter;
  45. [LegacyLenientThis] attribute EventHandler onmouseleave;
  46. attribute EventHandler onmousemove;
  47. attribute EventHandler onmouseout;
  48. attribute EventHandler onmouseover;
  49. attribute EventHandler onmouseup;
  50. attribute EventHandler onpaste;
  51. attribute EventHandler onpause;
  52. attribute EventHandler onplay;
  53. attribute EventHandler onplaying;
  54. attribute EventHandler onprogress;
  55. attribute EventHandler onratechange;
  56. attribute EventHandler onreset;
  57. attribute EventHandler onresize;
  58. attribute EventHandler onscroll;
  59. attribute EventHandler onscrollend;
  60. attribute EventHandler onsecuritypolicyviolation;
  61. attribute EventHandler onseeked;
  62. attribute EventHandler onseeking;
  63. attribute EventHandler onselect;
  64. attribute EventHandler onslotchange;
  65. attribute EventHandler onstalled;
  66. attribute EventHandler onsubmit;
  67. attribute EventHandler onsuspend;
  68. attribute EventHandler ontimeupdate;
  69. attribute EventHandler ontoggle;
  70. attribute EventHandler onvolumechange;
  71. attribute EventHandler onwaiting;
  72. attribute EventHandler onwebkitanimationend;
  73. attribute EventHandler onwebkitanimationiteration;
  74. attribute EventHandler onwebkitanimationstart;
  75. attribute EventHandler onwebkittransitionend;
  76. attribute EventHandler onwheel;
  77. };
ElementContentEditable
  1. interface mixin ElementContentEditable {
  2. [CEReactions] attribute DOMString contentEditable;
  3. [CEReactions] attribute DOMString enterKeyHint;
  4. readonly attribute boolean isContentEditable;
  5. [CEReactions] attribute DOMString inputMode;
  6. };
HTMLOrSVGElement
  1. interface mixin HTMLOrSVGElement {
  2. [SameObject] readonly attribute DOMStringMap dataset;
  3. attribute DOMString nonce; // intentionally no [CEReactions]
  4.  
  5. [CEReactions] attribute boolean autofocus;
  6. [CEReactions] attribute long tabIndex;
  7. undefined focus(optional FocusOptions options = {});
  8. undefined blur();
  9. };
ARIA in HTML
暗黙的="table" ARIAロール="任意" aria-* 属性="GlobalAny"

暗黙的な ARIAセマンティクスは、role=table です。

要素で任意の role 値を使用できます。ただし、作成者が要素の暗黙的なロール, 汎用ロール, または ARIA によって非推奨となったロールをこれらの要素に対して指定することは推奨されません。

グローバル aria-* 属性と、許可されたロールに適用される任意の aria-* 属性が記述できます。

レンダリング
ブロックボックス
テーブル
  1. table {
  2. display: table;
  3. box-sizing: border-box;
  4. border-spacing: 2px;
  5. border-collapse: separate;
  6. text-indent: initial;
  7. unicode-bidi: isolate;
  8. }
  9. table[align=left i] {
  10. float: left;
  11. }
  12. table[align=right i] {
  13. float: right;
  14. }
  15. table[align=center i] {
  16. margin-inline: auto;
  17. }
  18. table[rules=none i], table[rules=groups i], table[rules=rows i], table[rules=cols i], table[rules=all i] {
  19. border-style: hidden;
  20. border-collapse: collapse;
  21. }
  22. table[border] {
  23. border-style: outset;
  24. }
  25. table[frame=void i] {
  26. border-style: hidden;
  27. }
  28. table[frame=above i] {
  29. border-style: outset hidden hidden hidden;
  30. }
  31. table[frame=below i] {
  32. border-style: hidden hidden outset hidden;
  33. }
  34. table[frame=hsides i] {
  35. border-style: outset hidden outset hidden;
  36. }
  37. table[frame=lhs i] {
  38. border-style: hidden hidden hidden outset;
  39. }
  40. table[frame=rhs i] {
  41. border-style: hidden outset hidden hidden;
  42. }
  43. table[frame=vsides i] {
  44. border-style: hidden outset;
  45. }
  46. table[frame=box i], table[frame=border i] {
  47. border-style: outset;
  48. }

CSS を大雑把に読むと、 ブロックレベルのテーブルラッパーボックスを生成します。 などになります。

説明
table要素は、複数の次元を持つデータを、表の形式で表します。

table要素は、複数のディメンションを持つデータを表(テーブル・table)の形式で表します。
ここでの表すとは、表形式の描画の比重が大きいのでその点を意識した方が良いと思います。

  1. <!DOCTYPE html>
  2. <html lang="ja">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>table要素の例 - (Example of table element) | 離珠のHTMLでしぃ!</title>
  6. <meta name="author" content="コータン (KOUTAN)">
  7. <link rel="icon" href="../favicon.ico" type="image/vnd.microsoft.icon">
  8. </head>
  9. <body>
  10. <h1>table要素の例</h1>
  11. <table>
  12. <caption>table要素の例</caption>
  13. <colgroup>
  14. <col>
  15. <col>
  16. <col>
  17. </colgroup>
  18. <thead>
  19. <tr>
  20. <th>id</th>
  21. <th>name</th>
  22. <th>data</th>
  23. </tr>
  24. </thead>
  25. <tbody>
  26. <tr>
  27. <td>10</td>
  28. <th>name01</th>
  29. <td>data01</td>
  30. </tr>
  31. <tr>
  32. <td>20</td>
  33. <th>name02</th>
  34. <td>data02</td>
  35. </tr>
  36. </tbody>
  37. <tbody>
  38. <tr>
  39. <td>55</td>
  40. <th>name55</th>
  41. <td>data55</td>
  42. </tr>
  43. <tr>
  44. <td>57</td>
  45. <th>name57</th>
  46. <td>data57</td>
  47. </tr>
  48. <tr>
  49. <td>59</td>
  50. <th>name59</th>
  51. <td>data59</td>
  52. </tr>
  53. </tbody>
  54. <tfoot>
  55. <tr>
  56. <td>-</td>
  57. <th>total</th>
  58. <td>data99</td>
  59. </tr>
  60. </tfoot>
  61. </table>
  62. </body>
  63. </html>

このサンプルへのリンクです。
(./extable.htm)

参照元
参照元
JSONデータ
JSON形式での、データのイメージです。
  1. {
  2. "table": {
  3. "group": "Tables",
  4. "element": "- - (caption?,colgroup*,thead?,(tbody|tr)*,tfoot?) +(%Scriptsupporting) -- table element. (Normal elements.) [Flow|Palpable] --",
  5. "attlist": {"%Global;": ""},
  6. "summary": "表 (table element)",
  7. "point": "複数の次元を持つデータを、表の形式で表します。",
  8. "description": [
  9. "複数のディメンションを持つデータを表(テーブル・table)の形式で表します。",
  10. "ここでの表すとは、表形式の描画の比重が大きいのでその点を意識した方が良いと思います。",
  11. ],
  12. "elementKind": "Normal",
  13. "categories": [
  14. "Flow",
  15. "Palpable",
  16. ],
  17. "canUsedContexts": "parent (%Flow)*",
  18. "contentModel": "table (caption?,colgroup*,thead?,(tbody|tr)*,tfoot?) +(%Scriptsupporting)",
  19. "tagOmission": [
  20. "-",
  21. "-",
  22. ],
  23. "rendering": [
  24. "Tables",
  25. "Bidirectional",
  26. ],
  27. "domInterface": "HTMLTableElement",
  28. "contentAttributes": "Global",
  29. "reference": [
  30. {
  31. "title": "HTML Living Standard. 4.9.1 The table element. Last Updated 29 August 2025",
  32. "href": "https://html.spec.whatwg.org/multipage/tables.html#the-table-element",
  33. "heading": "HTML Living Standard. 4.9.1 The table element",
  34. "sub": "最終更新日 2025年8月29日",
  35. },
  36. {
  37. "title": "HTML Living Standard. 15 Rendering 15.3.8 Tables. Last Updated 29 August 2025",
  38. "href": "https://html.spec.whatwg.org/multipage/rendering.html#tables-2",
  39. "heading": "HTML Living Standard. 15 Rendering 15.3.8 Tables",
  40. "sub": "最終更新日 2025年8月29日",
  41. },
  42. {
  43. "title": "HTML 5.3 W3C Working Draft. 4.9.1 The table element. W3C First Public Working Draft, 14 December 2017",
  44. "href": "https://www.w3.org/TR/2017/WD-html53-20171214/tabular-data.html#the-table-element",
  45. "heading": "HTML 5.3 W3C 初公開ワーキングドラフト. 4.9.1 The table element",
  46. "sub": "W3Cワーキングドラフト、2017年12月14日",
  47. },
  48. {
  49. "title": "HTML 5.3 W3C Working Draft. 10.3.9. Tables. W3C First Public Working Draft, 14 December 2017",
  50. "href": "https://www.w3.org/TR/2017/WD-html53-20171214/rendering.html#tables",
  51. "heading": "HTML 5.3 W3C 初公開ワーキングドラフト. 10. Rendering 10.3.9. Tables",
  52. "sub": "W3Cワーキングドラフト、2017年12月14日",
  53. },
  54. {
  55. "title": "HTML 5.2 W3C Recommendation. 4.9.1 The table element. W3C Recommendation, 14 December 2017.",
  56. "href": "https://www.w3.org/TR/2017/REC-html52-20171214/tabular-data.html#the-table-element",
  57. "heading": "HTML 5.2 W3C 勧告. 4.9.1 The table element",
  58. "sub": "W3C勧告、2017年12月14日",
  59. },
  60. {
  61. "title": "HTML 5.2 W3C Recommendation. 10.3.9. Tables.",
  62. "href": "https://www.w3.org/TR/2017/REC-html52-20171214/rendering.html#tables",
  63. "heading": "HTML 5.2 W3C 勧告. 10.3.9. Tables",
  64. "sub": "W3C勧告、2017年12月14日",
  65. },
  66. {
  67. "title": "HTML 5.1 W3C Recommendation. 4.9.1 The table element. W3C Recommendation, 1 November 2016.",
  68. "href": "https://www.w3.org/TR/2016/REC-html51-20161101/tabular-data.html#the-table-element",
  69. "heading": "HTML 5.1 W3C 勧告. 4.9.1 The table element",
  70. "sub": "W3C勧告、2016年11月1日",
  71. },
  72. {
  73. "title": "HTML 5.1 W3C Recommendation. 10.3.9. Tables. W3C Recommendation, 1 November 2016.",
  74. "href": "https://www.w3.org/TR/2016/REC-html51-20161101/rendering.html#tables",
  75. "heading": "HTML 5.1 W3C 勧告. 10.3.9. Tables",
  76. "sub": "W3C勧告、2016年11月1日",
  77. },
  78. {
  79. "title": "HTML 5 W3C Recommendation. 4.9.1 The table element. W3C Recommendation, 28 October 2014.",
  80. "href": "https://www.w3.org/TR/2014/REC-html5-20141028/tabular-data.html#the-table-element",
  81. "heading": "HTML 5 W3C 勧告. 4.9.1 The table element",
  82. "sub": "W3C勧告、2014年10月28日",
  83. },
  84. {
  85. "title": "HTML 5 W3C Recommendation. 10.3.9 Tables. W3C Recommendation, 28 October 2014.",
  86. "href": "https://www.w3.org/TR/2014/REC-html5-20141028/rendering.html#tables",
  87. "heading": "HTML 5 W3C 勧告. 10.3.9 Tables",
  88. "sub": "W3C勧告、2014年10月28日",
  89. },
  90. {
  91. "title": "HTML 4.01 Specification W3C Recommendation. 11.2.1 The TABLE element. W3C Recommendation 24 December 1999.",
  92. "href": "https://www.w3.org/TR/html401/struct/tables.html#h-11.2.1",
  93. "heading": "HTML 4.01 Specification W3C 勧告. 11.2.1 The TABLE element",
  94. "sub": "W3C勧告1999年12月24日",
  95. },
  96. {
  97. "title": "HTML 3.2 Reference Specification. W3C Recommendation 14-Jan-1997.",
  98. "href": "https://www.w3.org/TR/2018/SPSD-html32-20180315/",
  99. "heading": "HTML 3.2 Reference Specification",
  100. "sub": "W3C勧告1997年1月14日",
  101. },
  102. {
  103. "title": "MDN Web Docs. HTML <table>: The Table element.",
  104. "href": "https://developer.mozilla.org/ja/docs/Web/HTML/Element/table",
  105. "heading": "<table>: 表要素 - HTML: ハイパーテキストマークアップ言語 | MDN",
  106. },
  107. ],
  108. "version": {
  109. "first": "HTML3",
  110. "latest": "HTML Living Standard",
  111. },
  112. "lastReviewed": "2025-08-31",
  113. "obsoleteAttributes": [
  114. "datapagesize",
  115. "summary",
  116. "datasrc",
  117. "dataformatas",
  118. "align",
  119. "bgcolor",
  120. "border",
  121. "bordercolor",
  122. "cellpadding",
  123. "cellspacing",
  124. "frame",
  125. "height",
  126. "rules",
  127. "width",
  128. "background",
  129. ],
  130. }
  131. }

注意: 簡易に描画する為に、各項目の後ろに , を付与しています。JSON の形式では、末尾の項目の後には , は付けません。

最終確認日

2025-08-31


2.使用できるコンテキスト

table要素は、
フローコンテンツを
受け入れる要素に
使用できます。

<table>要素が使用できるコンテキスト(Context文脈)は、フローコンテンツを受け入れる要素コンテンツとしてです。

body
table
  1. <body>
  2. <table>
  3. <tbody>
  4. <tr>
  5. <th>セル11</th>
  6. <td>セル12</td>
  7. </tr>
  8. </tbody>
  9. </table>
  10. </body>

<body>要素のコンテンツの一部として、フローコンテンツである<table>要素を配置している例です。


3.コンテンツモデル

table要素は、
caption要素,
colgroup要素,
thead要素,
tfoot要素,
tbody要素,
tr要素を
配置できます。

<table>要素子や子孫としてどのようなコンテンツ(Content内容) が含まれなければならないかというと、0または1つの<caption>要素と、それに続く 0個以上の <colgroup>要素と、それに続く 0または1つの <thead>要素と、それに続く 0個以上の <tbody>要素または <tr>要素と、それに続く 0または1つの <tfoot>要素 および スクリプトをサポートする要素です。

<tr>要素が置けますが、<tbody>要素のタグが省略されているものとして扱われて<table>要素の孫として処理される事があります。なので<tr>要素<table>要素の子ではなく<tbody>要素の子として記述する事をお勧めします。

スクリプトをサポートする要素に分類される要素は、以下の各要素です。

table
caption
colgroup
thead
tbody
tfoot
Flow
col
tr
tr
tr
  1. <table>
  2. <caption>見出し</caption>
  3. <colgroup>
  4. <col>
  5. <col>
  6. </colgroup>
  7. <thead>
  8. <tr>
  9. <th>セルH11</th>
  10. <td>セルH12</td>
  11. </tr>
  12. </thead>
  13. <tbody>
  14. <tr>
  15. <th>セルB11</th>
  16. <td>セルB12</td>
  17. </tr>
  18. </tbody>
  19. <tfoot>
  20. <tr>
  21. <th>セルF11</th>
  22. <td>セルF12</td>
  23. </tr>
  24. </tfoot>
  25. </table>

<table>要素のコンテンツの一部として、<caption>要素と、それに続く 0個以上の <colgroup>要素と、それに続く 0または1つの <thead>要素と、それに続く 0個以上の <tbody>要素または <tr>要素と、それに続く 0または1つの <tfoot>要素を配置できます。


4.コンテンツ属性

table要素は、
グローバル属性のみ、
配置できます。

<table>要素に指定することができる属性は、グローバル属性のみです。align属性, bgcolor属性, border属性, bordercolor属性, cellpadding属性, cellspacing属性, frame属性, height属性, rules属性, width属性, background属性は廃止されています。


5.DOM インターフェイス

table要素を、
直接表す
プロパティは
ありません。

<table>要素を JavaScript などで操作するには、documentgetElementById()メソッドを用いてid属性で指定して、<table>要素を取得する方法があります。この時に取得できる値の形式はHTMLTableElement インターフェイスです。

他には、documentquerySelectorAll()メソッドを用いて要素セレクタtableと指定して用いるとか、name属性があればdocumentgetElementsByName()メソッドを用いるとか、状況, 目的によりいろいろあります。

この例示の文字の色は、です。
table要素の文字の色 table要素の文字の色
  1. <form>
  2. この例示の文字の色は、<select onchange="document.getElementById('JTA501').style.color = this.value;">
  3. <option value="inherit">継承する</option>
  4. <option value="red"></option>
  5. <option value="blue"></option>
  6. </select>です。
  7. </form>
  8. <table id="JTA501">
  9. <tbody>
  10. <tr>
  11. <td>table要素の文字の色</td>
  12. <td>table要素の文字の色</td>
  13. </tr>
  14. </tbody>
  15. </table>

<table>要素id属性を指定して、そのid属性で要素を取得する例です。例示では、cssのcolorを選択して設定する処理としています。例示で動的に表示する為に、フォームの内容が変更された時に処理するコードとしています。


6.アクセシビリティ

table要素の
暗黙的な
ARIAセマンティクスは
table role
(行と列に配置された
データを含む
セクション。)
です。

<table>要素暗黙的なARIAセマンティクスは、role="table" です。
table role は、「行と列に配置されたデータを含むセクション。」です。

table ロールは、インタラクティブではない表形式のコンテナを対象としています。表形式のコンテナが選択状態を維持したり、独自の2次元ナビゲーションを提供したり、ユーザーがコンテンツやその表示を並べ替えたり操作したりできる場合、作成者は代わりに grid または treegrid を使用すべきです。

作成者は、可能な限り、HTML の table 要素など、ホスト言語の表のセマンティクスを使用するべきです。

作成者が<table>要素に明示的に指定可能なARIA ロール(役割)は、Any role (任意の役割) です。要素に任意のロール値を使用できることを表します。ただし、作成者が要素の暗黙的なロールgenericロール、または ARIA で非推奨のロールをこれらの要素に指定することは推奨されません。

ARIA の状態プロパティについては、すべての要素で使用できるグローバル aria-* 属性に加えて、上記のロールに応じて使用可能なaria-* 属性が許可されます。


7.レンダリング

  1. table {
  2. display: table;
  3. box-sizing: border-box;
  4. border-spacing: 2px;
  5. border-collapse: separate;
  6. text-indent: initial;
  7. unicode-bidi: isolate;
  8. }

<table>要素ユーザーエージェントレベルスタイルシートデフォルトでは、displayプロパティの値は table であり、ブロックレベルブロックコンテナボックス(テーブルラッパーボックス) を生成します。その中に、(ブロックレベルの)テーブルグリッドボックスを生成します。

ブロックフォーマットコンテキストに参加して、ブロックフォーマットコンテキストを継承, 確立します。

<table>要素は、ブロックレベルボックスを生成する<caption>要素を配置します。他の要素はテーブルグリッドボックス内に収めます。なのでここでは、インラインフォーマットコンテキストは確立されません。

border-collapse は、表(テーブル)の中のセルが境界を共有するか分離するかを設定します。separate は、隣接するセルが個別に境界線を持つです。
尚これは、テーブルフォーマットコンテキスト内での振る舞いです。セルの上位の要素にdisplayプロパティを指定してテーブルフォーマットコンテキスト以外のフォーマットモデルにした場合は、効果が得られません。

HTML Living Standard でのレンダリングの提案の量が 少々多いので、ここでは一部の抜粋としています。
詳細は 15 Rendering 15.3.8 Tablesをご覧ください。

body要素ブロックフォーマット
コンテキスト
table要素ブロック
フォーマット
コンテキスト
(継続)
caption要素コンテンツ
Table grid box内部テーブル
ボックス
  1. <body>
  2. <table>
  3. <caption>見出し</caption>
  4. <colgroup>
  5. <col>
  6. <col>
  7. </colgroup>
  8. <thead>
  9. <tr>
  10. <th>セルH11</th>
  11. <td>セルH12</td>
  12. </tr>
  13. </thead>
  14. <tbody>
  15. <tr>
  16. <th>セルB11</th>
  17. <td>セルB12</td>
  18. </tr>
  19. </tbody>
  20. <tfoot>
  21. <tr>
  22. <th>セルF11</th>
  23. <td>セルF12</td>
  24. </tr>
  25. </tfoot>
  26. </table>
  27. </body>

<body>要素が存在して、その中に<table>要素が存在して、その中に<caption>要素, <colgroup>要素, <thead>要素, <tfoot>要素, <tbody>要素がある例です。

<body>要素は、ブロックレベルブロックコンテナであるボックスを生成します。<body>要素ブロックフォーマットコンテキストに配置される為、ブロックフォーマットコンテキストを継承します。<body>要素は、ブロックレベルボックスを生成する<table>要素などを配置します。

<table>要素は、ブロックコンテナボックス(テーブルラッパーボックス) を生成します。<caption>要素は、ブロックレベルボックスを生成します。<colgroup>要素, <thead>要素, <tfoot>要素, <tbody>要素は、テーブルグリッドボックス内に収めます。この例ではブロックレベルボックスを生成する要素だけを配置しています。なので、ブロックフォーマットコンテキストを継続します。

尚、この説明は各要素のレンダリングに関する指定が既定値での話で、個々にスタイルを指定した場合はこの限りではありません。

見出し
code name data
01 name01 10
02 name02 20
total 30
  1. <table style="border-collapse: ; border-spacing: px; border: ; border-left: ; border-image: ; border-radius: em em em em; box-shadow: ;" class="" id="JTA701">
  2. <caption>見出し</caption>
  3. <colgroup>
  4. <col>
  5. <col>
  6. <col>
  7. </colgroup>
  8. <thead>
  9. <tr>
  10. <th>code</th>
  11. <th>name</th>
  12. <th>data</th>
  13. </tr>
  14. </thead>
  15. <tbody>
  16. <tr>
  17. <th>01</th>
  18. <td>name01</td>
  19. <td>10</td>
  20. </tr>
  21. <tr>
  22. <th>02</th>
  23. <td>name02</td>
  24. <td>20</td>
  25. </tr>
  26. </tbody>
  27. <tfoot>
  28. <tr>
  29. <td></td>
  30. <th>total</th>
  31. <td>30</td>
  32. </tr>
  33. </tfoot>
  34. </table>

<table>要素の装飾例です。例示で分かり易くする為に、別途にセルの境界線の装飾を指定できる様にしています。

とりあえず詰め込んだ例示なので、組み合わせによっては効果のない物もあります。またスクリプトにて動的に処理している為、指定する順番で効果が異なる可能性もあります。
実際に使用する場合は、動作確認を改めて行ってから採用して下さい。

box-shadowプロパティの、"length | color" の実際のコードは、以下の通りです。
box-shadow: 0.25em 0.25em 0.25em 0.05em #ffccff

border-imageプロパティの、"linear-gradient" の実際のコードは、以下の通りです。
border-image: linear-gradient(to right, blue 11%, rgba(0,0,0,0) 11%, rgba(0,0,0,0) 22%, blue 22%, blue 33%, rgba(0,0,0,0) 66%) 33%


8.気を付ける点

フレージングコンテンツではないフローコンテンツである要素の多くの幅は、親となる要素と同じです。しかし<table>要素はセルの幅の積み重ねとなる為に、注意が必要です。

描画

<table>要素ボーダー領域は、テーブルラッパーボックスではなくテーブルグリッドボックスになります。つまり <table>要素に境界線を引くと、<caption>要素はその外に位置する事になります。<caption>要素を含んだ表(テーブル)の線を引きたい場合は、<table>要素を包む装飾用の要素 (<div>要素など) を用いる必要があります。