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

caption要素


1.仕様

CAPTION要素は、
親である表(テーブル)の
見出し(タイトル)を
表します。

CAPTION - O (%Flow)* -(table) -- table caption. (Normal elements.) [None] --

caption

表の見出し (table caption)

種類

通常要素

カテゴリ

なし

使用できるコンテキスト
<table>要素の最初

<table>要素の最初のコンテンツとして、使用できます。

コンテンツモデル
0個以上のフローコンテンツ (<table>要素 を除く)

0個以上のフローコンテンツが配置できます。ですが、<table>要素は子孫に持てません。

<table>要素を除くフローコンテンツに分類される要素は、<section>要素, <nav>要素, <aside>要素, <article>要素, <h1>要素, <h2>要素, <h3>要素, <h4>要素, <h5>要素, <h6>要素, <hgroup>要素, <header>要素, <footer>要素, <main>要素, <address>要素, <ol>要素, <ul>要素, <menu>要素, <dl>要素, <form>要素, <fieldset>要素, <search>要素, <hr>要素, <p>要素, <pre>要素, <blockquote>要素, <figure>要素, <div>要素, <dialog>要素, <details>要素, <script>要素, <noscript>要素, <template>要素, <input>要素, <textarea>要素, <select>要素, <label>要素, <button>要素, <output>要素, <progress>要素, <meter>要素, <datalist>要素, <picture>要素, <object>要素, <img>要素, <iframe>要素, <embed>要素, <video>要素, <audio>要素, <canvas>要素, <map>要素, <area>要素, <a>要素, <ruby>要素, <ins>要素, <del>要素, <bdi>要素, <bdo>要素, <br>要素, <wbr>要素, <abbr>要素, <b>要素, <cite>要素, <code>要素, <data>要素, <dfn>要素, <em>要素, <i>要素, <kbd>要素, <mark>要素, <q>要素, <s>要素, <samp>要素, <small>要素, <span>要素, <strong>要素, <sub>要素, <sup>要素, <u>要素, <var>要素, <time>要素, <slot>要素, テキスト, <meta>要素, <link>要素 です。

タグの省略
終了タグは省略できます。

caption要素の直後に ASCII 空白またはコメントが続かない場合は、caption要素の終了タグを省略できます。

コンテンツ属性

グローバル属性のみ

DOM インターフェイス
HTMLTableCaptionElement
  1. [Exposed=Window]
  2. interface HTMLTableCaptionElement : HTMLElement {
  3. lastReviewed;
  4. [HTMLConstructor] constructor();
  5.  
  6. // also has obsolete members
  7. };
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
暗黙的="caption" ARIAロール="No" aria-* 属性="Global"

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

作成者は、暗黙的な ARIAセマンティクス, または HTML要素のネイティブセマンティクスを上書きしてはいけません。

グローバル aria-* 属性が記述できます。

レンダリング
ブロックボックス
テーブル
  1. caption {
  2. display: table-caption;
  3. text-align: center;
  4. unicode-bidi: isolate;
  5. }
  6. caption[align=bottom i] {
  7. caption-side: bottom;
  8. }

CSS を大雑把に読むと、 テーブルラッパーボックスに関して特別な動作を持つブロックレベルのテーブルキャプションボックスを生成します。 などになります。

説明
caption要素は、親である表の見出しを表します。

caption要素は、親である表(テーブル・table)の見出し(タイトル)を表します。これによって表のコンテキストが紹介され、非常に理解しやすくなります。

  1. <!DOCTYPE html>
  2. <html lang="ja">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>caption要素の例 - (Example of caption 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>caption要素の例</h1>
  11. <table>
  12. <caption>caption要素の例</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>

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

JSONデータ
JSON形式での、データのイメージです。
  1. {
  2. "caption": {
  3. "group": "Tables",
  4. "element": "- O (%Flow)* -(table) -- table caption. (Normal elements.) [None] --",
  5. "attlist": {"%Global;": ""},
  6. "summary": "表の見出し (table caption)",
  7. "point": "親である表の見出しを表します。",
  8. "description": "親である表(テーブル・table)の見出し(タイトル)を表します。これによって表のコンテキストが紹介され、非常に理解しやすくなります。",
  9. "elementKind": "Normal",
  10. "categories": "None",
  11. "canUsedContexts": "table (caption?,colgroup*,thead?,(tbody|tr)*,tfoot?)",
  12. "contentModel": "caption (%Flow)* -(table)",
  13. "tagOmission": [
  14. "-",
  15. "O",
  16. ],
  17. "tagsupplement": "caption要素の直後に ASCII 空白またはコメントが続かない場合は、caption要素の終了タグを省略できます。",
  18. "rendering": [
  19. "Tables",
  20. "Bidirectional",
  21. ],
  22. "domInterface": "HTMLTableCaptionElement",
  23. "contentAttributes": "Global",
  24. "reference": [
  25. {
  26. "title": "HTML Living Standard. 4.9.2 The caption element. Last Updated 29 August 2025",
  27. "href": "https://html.spec.whatwg.org/multipage/tables.html#the-caption-element",
  28. "heading": "HTML Living Standard. 4.9.2 The caption element",
  29. "sub": "最終更新日 2025年8月29日",
  30. },
  31. {
  32. "title": "HTML Living Standard. 15 Rendering 15.3.8 Tables. Last Updated 29 August 2025",
  33. "href": "https://html.spec.whatwg.org/multipage/rendering.html#tables-2",
  34. "heading": "HTML Living Standard. 15 Rendering 15.3.8 Tables",
  35. "sub": "最終更新日 2025年8月29日",
  36. },
  37. {
  38. "title": "HTML 5.3 W3C Working Draft. 4.9.2 The caption element. W3C First Public Working Draft, 14 December 2017",
  39. "href": "https://www.w3.org/TR/2017/WD-html53-20171214/tabular-data.html#the-caption-element",
  40. "heading": "HTML 5.3 W3C 初公開ワーキングドラフト. 4.9.2 The caption element",
  41. "sub": "W3Cワーキングドラフト、2017年12月14日",
  42. },
  43. {
  44. "title": "HTML 5.3 W3C Working Draft. 10.3.9. Tables. W3C First Public Working Draft, 14 December 2017",
  45. "href": "https://www.w3.org/TR/2017/WD-html53-20171214/rendering.html#tables",
  46. "heading": "HTML 5.3 W3C 初公開ワーキングドラフト. 10. Rendering 10.3.9. Tables",
  47. "sub": "W3Cワーキングドラフト、2017年12月14日",
  48. },
  49. {
  50. "title": "HTML 5.2 W3C Recommendation. 4.9.2 The caption element. W3C Recommendation, 14 December 2017.",
  51. "href": "https://www.w3.org/TR/2017/REC-html52-20171214/tabular-data.html#the-caption-element",
  52. "heading": "HTML 5.2 W3C 勧告. 4.9.2 The caption element",
  53. "sub": "W3C勧告、2017年12月14日",
  54. },
  55. {
  56. "title": "HTML 5.2 W3C Recommendation. 10.3.9. Tables.",
  57. "href": "https://www.w3.org/TR/2017/REC-html52-20171214/rendering.html#tables",
  58. "heading": "HTML 5.2 W3C 勧告. 10.3.9. Tables",
  59. "sub": "W3C勧告、2017年12月14日",
  60. },
  61. {
  62. "title": "HTML 5.1 W3C Recommendation. 4.9.2 The caption element. W3C Recommendation, 1 November 2016.",
  63. "href": "https://www.w3.org/TR/2016/REC-html51-20161101/tabular-data.html#the-caption-element",
  64. "heading": "HTML 5.1 W3C 勧告. 4.9.2 The caption element",
  65. "sub": "W3C勧告、2016年11月1日",
  66. },
  67. {
  68. "title": "HTML 5.1 W3C Recommendation. 10.3.9. Tables. W3C Recommendation, 1 November 2016.",
  69. "href": "https://www.w3.org/TR/2016/REC-html51-20161101/rendering.html#tables",
  70. "heading": "HTML 5.1 W3C 勧告. 10.3.9. Tables",
  71. "sub": "W3C勧告、2016年11月1日",
  72. },
  73. {
  74. "title": "HTML 5 W3C Recommendation. 4.9.2 The caption element. W3C Recommendation, 28 October 2014.",
  75. "href": "https://www.w3.org/TR/2014/REC-html5-20141028/tabular-data.html#the-caption-element",
  76. "heading": "HTML 5 W3C 勧告. 4.9.2 The caption element",
  77. "sub": "W3C勧告、2014年10月28日",
  78. },
  79. {
  80. "title": "HTML 5 W3C Recommendation. 10.3.9 Tables. W3C Recommendation, 28 October 2014.",
  81. "href": "https://www.w3.org/TR/2014/REC-html5-20141028/rendering.html#tables",
  82. "heading": "HTML 5 W3C 勧告. 10.3.9 Tables",
  83. "sub": "W3C勧告、2014年10月28日",
  84. },
  85. {
  86. "title": "HTML 4.01 Specification W3C Recommendation. 11.2.2 Table Captions: The CAPTION element. W3C Recommendation 24 December 1999.",
  87. "href": "https://www.w3.org/TR/html401/struct/tables.html#h-11.2.2",
  88. "heading": "HTML 4.01 Specification W3C 勧告. 11.2.2 Table Captions: The CAPTION element",
  89. "sub": "W3C勧告1999年12月24日",
  90. },
  91. {
  92. "title": "HTML 3.2 Reference Specification. W3C Recommendation 14-Jan-1997.",
  93. "href": "https://www.w3.org/TR/2018/SPSD-html32-20180315/",
  94. "heading": "HTML 3.2 Reference Specification",
  95. "sub": "W3C勧告1997年1月14日",
  96. },
  97. {
  98. "title": "MDN Web Docs. HTML <caption>: The Table Caption element.",
  99. "href": "https://developer.mozilla.org/ja/docs/Web/HTML/Element/caption",
  100. "heading": "<caption>: 表キャプション要素 - HTML: ハイパーテキストマークアップ言語 | MDN",
  101. },
  102. ],
  103. "version": {
  104. "first": "HTML3",
  105. "latest": "HTML Living Standard",
  106. },
  107. "lastReviewed": "2025-08-31",
  108. "obsoleteAttributes": [
  109. "align",
  110. ],
  111. }
  112. }

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

最終確認日

2025-08-31


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

caption要素は、
table要素に
使用できます。

<caption>要素が使用できるコンテキスト(Context文脈)は、<table>要素の 1番目のコンテンツとしてです。

table
caption
  1. <table>
  2. <caption>見出し</caption>
  3. <tbody>
  4. <tr>
  5. <th>セルB11</th>
  6. <td>セルB12</td>
  7. </tr>
  8. </tbody>
  9. </table>

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


3.コンテンツモデル

caption要素は、
table要素を除く
フローコンテンツを
配置できます。

<caption>要素子や子孫としてどのようなコンテンツ(Content内容) が含まれなければならないかというと、0 以上のフローコンテンツです。ただし、子孫に<table>要素があってはいけません。

table
caption
Flow
content
  1. <table>
  2. <caption><p>見出し</p></caption>
  3. <tbody>
  4. <tr>
  5. <th>セルB11</th>
  6. <td>セルB12</td>
  7. </tr>
  8. </tbody>
  9. </table>

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


4.コンテンツ属性

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

<caption>要素に指定することができる属性は、グローバル属性のみです。廃止された属性に、align属性があります。


5.DOM インターフェイス

caption要素を、
表すには、
table要素の
captionプロパティが
使えます。

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

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

この例示の文字の色は、です。
caption要素の文字の色
table要素の文字の色 table要素の文字の色
  1. <form>
  2. この例示の文字の色は、<select onchange="document.getElementById('JTA501').caption.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. <caption>caption要素の文字の色</caption>
  10. <tbody>
  11. <tr>
  12. <td>table要素の文字の色</td>
  13. <td>table要素の文字の色</td>
  14. </tr>
  15. </tbody>
  16. </table>

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


6.アクセシビリティ

caption要素の
暗黙的な
ARIAセマンティクスは
caption role
(図、表、グリッド、
またはツリーグリッドの名前、
および説明を表す
可視コンテンツ。)
です。

<caption>要素暗黙的なARIAセマンティクスは、role="caption" です。
caption role は、「図、表、グリッド、またはツリーグリッドの名前、および説明を表す可視コンテンツ。」です。

キャプションを使用する場合、作成者は以下の点を確認する必要があります。
キャプションは、図、表、グリッド、またはツリーグリッドの直接の子要素です。
キャプションは、表、グリッド、またはツリーグリッドの最初の子要素です。
キャプションは、図の最初または最後の子要素です。
作成者は、親の図、表、グリッド、またはツリーグリッドに、ロールがキャプションである要素を参照するために aria-labelledby を設定する必要があります。ただし、キャプションに親の名前と説明の両方として機能するコンテンツが含まれている場合、作成者は、キャプション内の簡潔な名前を含む要素を参照するために aria-labelledby を設定し、キャプション内の説明コンテンツを含む要素を参照するために aria-describeby を設定しても構いません。

作成者が<caption>要素に明示的に指定可能なARIA ロール(役割)は、No role (役割なし) です。作成者は暗黙的なARIAセマンティクスまたは HTML 要素のネイティブ セマンティクスを上書きしてはならないことを表します。

Naming prohibited (命名禁止) として識別される要素は、作成者がaria-label属性またはaria-labelledby属性を指定してはなりません。ただし、その要素が暗黙的なロールを、作成者による命名を許可する明示的なWAI-ARIA ロールによって上書きできる場合は除きます。
それ以外の場合は、グローバル aria-* 属性を使用します。


7.レンダリング

  1. caption {
  2. display: table-caption;
  3. text-align: center;
  4. unicode-bidi: isolate;
  5. }

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

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

ブロックフォーマットコンテキストに参加して、ブロックフォーマットコンテキストを継承, 確立します。もし、インラインフォーマットコンテキストに参加するコンテンツのみを含む場合は、新しいインラインフォーマットコンテキストを確立します。次に、すべてのインラインコンテンツをラップするルートインラインボックスも生成します。

テーブルキャプションボックスは、テーブルおよびテーブルラッパーボックスに関して特別な動作をするブロックボックスです。

  1. caption[align=bottom i] { caption-side: bottom; }

<caption>要素のレンダリングに関する部分を抜粋したものです。<caption>要素が関わる他の要素のレンダリングに関する部分は省いています。

align属性は、廃止されました。代わりに CSS を使用してください。

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

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

<table>要素は、ブロックレベルブロックコンテナであるボックス(テーブルラッパーボックス) を生成します。その中に、(ブロックレベルの)テーブルグリッドボックスを生成します。(※ <caption>要素以外の要素のボックスは、ここに収めます。) <table>要素ブロックフォーマットコンテキストに配置される為、ブロックフォーマットコンテキストを継承します。<table>要素は、ブロックレベルボックスを生成する<caption>要素などを配置します。

<caption>要素は、ブロックコンテナボックスを生成します。<p>要素は、ブロックレベルボックスを生成します。この例ではブロックレベルボックスを生成する要素だけを配置しています。なので、ブロックフォーマットコンテキストを継続します。

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

見出し
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 style="caption-side: ; border-style: ; border-width: px; border-radius: em em em em; box-shadow: ;" id="JCA702">見出し</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>

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

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


8.気を付ける点

位置

記述する位置は、<table>要素の 1番目に配置できます。そして描画する位置は、caption-side: top という既定値で表(テーブル)の上方に配置します。ここで注意点は、<table>要素の描画するボックスの外に<caption>要素が位置するという事です。caption-side: bottom と指定すると、表(テーブル)の下方に配置します。これも<table>要素の描画するボックスの外です。

使用できる状態

<table>要素の最初の子要素として使用できます。つまり<table>要素に1つだけ用いる事が出来るという事です。2つは出来ません。
表(テーブル)の上方と下方の両方に<caption>要素の様な記述をしたい場合は、装飾用に<table>要素を含む要素 (<div>要素など) を用いる必要があります。この時のこの含む要素の用途, 目的は、幅を合わせる為のものです。幅が固定(事前に指定できる)ならば、単純に前後に<caption>要素の代用の<div>要素を配置して表せば済みます。