Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 1111377 of <table>

  • Revision slug: Web/HTML/Element/table
  • Revision title: <table>
  • Revision id: 1111377
  • Created:
  • Creator: mientje
  • Is current revision? No
  • Comment

Revision Content

{{HTMLRef}}

The HTML Table Element (<table>) represents tabular data - i.e., information expressed via two dimensions or more.

Note: Prior to the creation of CSS, HTML {{HTMLElement("table")}} elements were often used as a method for page layout. This usage has been discouraged since HTML 4.
However, HTML emails are an exception where tables are still commonly used for layout purposes. The reason for this is poor CSS support in popular email clients.

Usage context

Content categories Flow content
Permitted content
In this order:
  1. an optional {{HTMLElement("caption")}} element,
  2. zero or more {{HTMLElement("colgroup")}} elements,
  3. an optional {{HTMLElement("thead")}} element,
  4. an optional {{HTMLElement("tfoot")}} element, either before or after one of the following:
    • zero or more {{HTMLElement("tbody")}} elements
    • one or more {{HTMLElement("tr")}} elements
Tag omission None, both start and end tag are mandatory
Permitted parent elements Any element that accepts flow content
Normative document HTML5, section 4.9.1 (HTML4.01, section 11.2.1)

Attributes

This element includes global attributes. The following attributes listed on this page are now deprecated.

{{htmlattrdef("align")}} {{Deprecated_inline}}
This enumerated attribute indicates how the table must be aligned inside the containing document. It may have the following values:
  • left: the table is displayed on the left side of the document;
  • center: the table is displayed in the center of the document;
  • right: the table is displayed on the right side of the document.
Usage Note
  • Do not use this attribute, as it has been deprecated. The {{HTMLElement("table")}} element should be styled using CSS.  Set {{cssxref("margin-left")}} and {{cssxref("margin-right")}} to auto or {{cssxref("margin")}} to 0 auto to achieve an effect that is similar to the align attribute.
  • Prior to Firefox 4, Firefox also supported, in quirks mode only, the values middle, absmiddle, and abscenter as synonyms of center
{{htmlattrdef("bgcolor")}} {{Deprecated_inline}}
This attribute defines the background color of a table. It consists of a 6-digit hexadecimal code as defined in sRGB and is prefixed by '#'. This attribute may be used with one of sixteen predefined color strings :
  black = "#000000"   green = "#008000"
  silver = "#C0C0C0"   lime = "#00FF00"
  gray = "#808080"   olive = "#808000"
  white = "#FFFFFF"   yellow = "#FFFF00"
  maroon = "#800000"   navy = "#000080"
  red = "#FF0000"   blue = "#0000FF"
  purple = "#800080"   teal = "#008080"
  fuchsia = "#FF00FF"   aqua = "#00FFFF"
Usage note: Do not use this attribute, as it has been deprecated. The {{HTMLElement("table")}} element should be styled using CSS. Use the {{cssxref("background-color")}} property  in CSS to create an effect that is similar to the bgcolor attribute.
{{htmlattrdef("border")}} {{Deprecated_inline}}
This integer attribute defines, in pixels, the size of the frame surrounding the table. If set to 0, the {{htmlattrxref("frame", "table")}} attribute is set to void.
Usage note: Do not use this attribute, as it has been deprecated. The {{HTMLElement("table")}} element should be styled using CSS. To create an effect similar to the border attribute, the {{cssxref("border")}}, {{cssxref("border-color")}}, {{cssxref("border-width")}} and {{cssxref("border-style")}} properties in CSS should be used.
{{htmlattrdef("cellpadding")}} {{Deprecated_inline}}
This attribute defines the space between the content of a cell and its border, displayed or not. If the cellpadding's length is defined in pixels, this pixel-sized space will be applied to all four sides of the cell's content. If the length is defined using a percentage, the content will be centered and the total vertical space (top and bottom) will represent this percentage. The same is true for the total horizontal space (left and right).
Usage note: Do not use this attribute, as it has been deprecated. The {{HTMLElement("table")}} element should be styled using CSS. To create an effect similar to the cellpadding attribute, apply the {{cssxref("border-collapse")}} property to the {{HTMLElement("table")}} element, with its value set to collapse, and to the {{cssxref("padding")}} property in the {{HTMLElement("td")}} element.
{{htmlattrdef("cellspacing")}} {{Deprecated_inline}}
This attribute defines the size of the space between two cells in percentage or pixels,. The attribute is applied both horizontally and vertically, to the space between the top of the table and the cells of the first row, the left of the table and the first column, the right of the table and the last column and the bottom of the table and the last row.
Usage note: Do not use this attribute, as it has been deprecated. The {{HTMLElement("table")}} element should be styled using CSS. To create an effect similar to the cellspacing attribute, apply the {{cssxref("border-spacing")}} property to the {{HTMLElement("table")}} element in CSS. Border-spacing does not have any effect if {{cssxref("border-collapse")}} is set to collapse.
{{htmlattrdef("frame")}} {{Deprecated_inline}}
This enumerated attribute defines which side of the frame surrounding the table must be displayed. It may have the following values:
  above   below
  hsides   vsides
  lhs   rhs
  border   box
  void
Usage note: Do not use this attribute, as it has been deprecated. The {{HTMLElement("table")}} element should be styled using CSS. To create an effect similar to the frame attribute, use the {{cssxref("border-style")}} and {{cssxref("border-width")}} properties in CSS.
{{htmlattrdef("rules")}} {{Deprecated_inline}}
This enumerated attribute defines where rules, i.e. lines, should appear in a table. It can have the following values:
  • none, which indicates that no rules will be displayed; it is the default value;
  • groups, which will cause the rules to be displayed between row groups (defined by the {{HTMLElement("thead")}}, {{HTMLElement("tbody")}} and {{HTMLElement("tfoot")}} elements) and between column groups (defined by the {{HTMLElement("col")}} and {{HTMLElement("colgroup")}} elements) only;
  • rows, which will cause the rules to be displayed between rows;
  • columns, which will cause the rules to be displayed between columns;
  • all, which wil cause the rules to be displayed between rows and columns.
Note:
  • The styling of the rules is browser-dependant and cannot be modified.
  • Do not use this attribute, as it has been deprecated. The rules should be defined and styled using CSS. Apply the {{cssxref("border")}} property to the appropriate{{HTMLElement("thead")}}, {{HTMLElement("tbody")}}, {{HTMLElement("tfoot")}}, {{HTMLElement("col")}} or {{HTMLElement("colgroup")}} elements in CSS.
{{htmlattrdef("summary")}} {{Deprecated_inline}}
This attribute defines an alternative text use to describe the table in user-agent unable to display it. Typically, it contents a description of it to allow visually impaired people, like blind people browsing the web using Braille screen, to get the information in it. If the information added in this attribute may also be useful for non-visually impaired people, consider using the {{HTMLElement("caption")}} instead. The summary attribute is not mandatory and may be omitted when a {{HTMLElement("caption")}} element fulfills its role.
Usage Note: Do not use this attribute, as it has been deprecated. Instead, use one of these way of describing a table:
  • In prose, surrounding the table (this is the less semantic-conveying way of doing it).
  • In the table's {{HTMLElement("caption")}} element.
  • In a {{HTMLElement("details")}} element, inside the table's {{HTMLElement("caption")}} element.
  • Include the {{HTMLElement("table")}} element in a {{HTMLElement("figure")}} element and add the description in prose next to it.
  • Include the {{HTMLElement("table")}} element in a {{HTMLElement("figure")}} element and add the description in prose inside a {{HTMLElement("figcaption")}} element.
  • Adjust the table so that such description is no more needed, by using {{HTMLElement("th")}} and {{HTMLElement("thead")}} elements for example.
{{htmlattrdef("width")}} {{Deprecated_inline}}
This attribute defines the width of the table. It may either be a pixel length or a percentage value, representing the percentage of the width of its container that the table should use.
Usage Note: Do not use this attribute, as it has been deprecated and the rules should be defined and styled using CSS. Use the CSS property {{cssxref("width")}} instead.

DOM interface

This element implements the HTMLTableElement interface.

Examples

Simple Table

<table>
  <tr>
    <td>John</td>
    <td>Doe</td>
  </tr>
  <tr>
    <td>Jane</td>
    <td>Doe</td>
  </tr>
</table>

{{EmbedLiveSample('Simple_Table', '100%', '100', '', 'Web/HTML/Element/table')}}

More Examples

<p>Simple table with header</p>
<table>
  <tr>
    <th>First name</th>
    <th>Last name</th>
  </tr>
  <tr>
    <td>John</td>
    <td>Doe</td>
  </tr>
  <tr>
    <td>Jane</td>
    <td>Doe</td>
  </tr>
</table>

<p>Table with thead, tfoot, and tbody</p>
<table>
  <thead>
    <tr>
      <th>Header content 1</th>
      <th>Header content 2</th>
    </tr>
  </thead>
  <tfoot>
    <tr>
      <td>Footer content 1</td>
      <td>Footer content 2</td>
    </tr>
  </tfoot>
  <tbody>
    <tr>
      <td>Body content 1</td>
      <td>Body content 2</td>
    </tr>
  </tbody>
</table>

<p>Table with colgroup</p>
<table>
  <colgroup span="4"></colgroup>
  <tr>
    <th>Countries</th>
    <th>Capitals</th>
    <th>Population</th>
    <th>Language</th>
  </tr>
  <tr>
    <td>USA</td>
    <td>Washington D.C.</td>
    <td>309 million</td>
    <td>English</td>
  </tr>
  <tr>
    <td>Sweden</td>
    <td>Stockholm</td>
    <td>9 million</td>
    <td>Swedish</td>
  </tr>
</table>

<p>Table with colgroup and col</p>
<table>
  <colgroup>
    <col style="background-color: #0f0">
    <col span="2">
  </colgroup>
  <tr>
    <th>Lime</th>
    <th>Lemon</th>
    <th>Orange</th>
  </tr>
  <tr>
    <td>Green</td>
    <td>Yellow</td>
    <td>Orange</td>
  </tr>
</table>

<p>Simple table with caption</p>
<table>
  <caption>Awesome caption</caption>
  <tr>
    <td>Awesome data</td>
  </tr>
</table>

{{EmbedLiveSample('More_Examples', '100%', '700', '', 'Web/HTML/Element/table')}}

Browser compatibility

{{CompatibilityTable}}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 1.0 {{CompatGeckoDesktop("1")}} 4.0[1] 7.0 1.0
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support 1.0 {{CompatGeckoMobile("1")}} 6.0[1] 6.0 1.0

[1] There is an Internet Explorer 9 rendering bug involving {{HTMLElement("table")}} and {{cssxref(":hover")}}; see the "Browser compatibility" section of the :hover article for details.

See also

  • Other table-related HTML Elements: {{HTMLElement("caption")}}, {{HTMLElement("col")}}, {{HTMLElement("colgroup")}}, {{HTMLElement("tbody")}}, {{HTMLElement("td")}}, {{HTMLElement("tfoot")}}, {{HTMLElement("th")}}, {{HTMLElement("thead")}}, {{HTMLElement("tr")}};
  • CSS properties that may be specially useful to style the <table> element:
    • {{cssxref("width")}} to control the width of the table;
    • {{cssxref("border")}}, {{cssxref("border-style")}}, {{cssxref("border-color")}}, {{cssxref("border-width")}}, {{cssxref("border-collapse")}}, {{cssxref("border-spacing")}} to control the aspect of cell borders, rules and frame;
    • {{cssxref("margin")}} and {{cssxref("padding")}} to style the individual cell content;
    • {{cssxref("text-align")}} and {{cssxref("vertical-align")}} to define alignment of text and cell content.

Revision Source

<div>{{HTMLRef}}</div>

<p>The <strong>HTML Table Element</strong> (<code>&lt;table&gt;</code>) represents tabular data - i.e., information expressed via two dimensions or more.</p>

<div class="note"><strong>Note: </strong>Prior to the creation of <a href="/en-US/docs/CSS">CSS</a>, HTML {{HTMLElement("table")}} elements were often used as a method for page layout. This usage has been discouraged since HTML 4.<!-- Who discourages that method? --><br />
However, HTML emails are an exception where tables are still commonly used for layout purposes. The reason for this is <a href="https://css-tricks.com/using-css-in-html-emails-the-real-story/">poor CSS support in popular email clients</a>.</div>

<h2 id="Usage_context">Usage context</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <td><a href="/en-US/docs/HTML/Content_categories">Content categories</a></td>
   <td><a href="/en-US/docs/HTML/Content_categories#Flow_content">Flow content</a></td>
  </tr>
  <tr>
   <td>Permitted content</td>
   <td>
    <div class="content-models">
    <div id="table-mdls">In this order:
    <ol>
     <li>an optional {{HTMLElement("caption")}} element,</li>
     <li>zero or more {{HTMLElement("colgroup")}} elements,</li>
     <li>an optional {{HTMLElement("thead")}} element,</li>
     <li>an optional {{HTMLElement("tfoot")}} element, either before or after one of&nbsp;the following:
      <ul>
       <li>zero or more {{HTMLElement("tbody")}} elements</li>
       <li>one or more {{HTMLElement("tr")}} elements</li>
      </ul>
     </li>
    </ol>
    </div>
    </div>
   </td>
  </tr>
  <tr>
   <td>Tag omission</td>
   <td>None, both <span title="syntax-start-tag">start </span>and <span title="syntax-end-tag">end tag</span> are mandatory</td>
  </tr>
  <tr>
   <td>Permitted parent elements</td>
   <td>Any element that accepts flow content</td>
  </tr>
  <tr>
   <td>Normative document</td>
   <td><a class="external" href="https://www.w3.org/TR/html5/tabular-data.html#the-table-element" rel="external nofollow">HTML5, section 4.9.1</a> (<a class="external" href="https://www.w3.org/TR/REC-html40/struct/tables.html#edef-TABLE">HTML4.01, section 11.2.1</a>)</td>
  </tr>
 </tbody>
</table>

<h2 id="Attributes">Attributes</h2>

<p><span>This element includes </span><a href="https://developer.mozilla.org/en-US/docs/HTML/Global_attributes">global attributes</a><span>. The following attributes listed on this page are now deprecated.</span></p>

<dl>
 <dt>{{htmlattrdef("align")}} {{Deprecated_inline}}</dt>
 <dd>This enumerated attribute indicates how the table must be aligned inside the containing document. It may have the following values:
 <ul>
  <li><span>left: the</span>&nbsp;table is displayed on the left side of the document;</li>
  <li><span>center:</span>&nbsp;the table is displayed in the center of the document;</li>
  <li><span>right:</span>&nbsp;the table is displayed on the right side of the document.</li>
 </ul>

 <div class="note"><strong>Usage Note</strong>

 <ul>
  <li><strong>Do not use this attribute</strong>, as it has been deprecated. The {{HTMLElement("table")}} element should be styled using <a href="/en-US/docs/CSS">CSS</a>. &nbsp;Set&nbsp;{{cssxref("margin-left")}} and {{cssxref("margin-right")}} to <code>auto</code>&nbsp;or {{cssxref("margin")}} to <code>0 auto</code>&nbsp;to achieve an effect that is similar to the align attribute.</li>
  <li>Prior to Firefox 4, Firefox also supported, in quirks mode only, the values <code>middle</code>, <code>absmiddle</code>, and <code>abscenter</code> as synonyms of <code>center</code>.&nbsp;</li>
 </ul>
 </div>
 </dd>
</dl>

<dl>
 <dt>{{htmlattrdef("bgcolor")}} {{Deprecated_inline}}</dt>
 <dd>This attribute defines the background color of a table. It consists of a 6-digit hexadecimal code as defined in <a class="external" href="https://www.w3.org/Graphics/Color/sRGB">sRGB</a>&nbsp;and is prefixed by&nbsp;'#'. This attribute may be used with one of sixteen predefined color strings&nbsp;:
 <table>
  <tbody>
   <tr>
    <td style="width: 24px; background-color: black;">&nbsp;</td>
    <td><span>black</span> = "#000000"</td>
    <td style="width: 24px; background-color: green;">&nbsp;</td>
    <td><span>green</span> = "#008000"</td>
   </tr>
   <tr>
    <td style="width: 24px; background-color: silver;">&nbsp;</td>
    <td><span>silver</span> = "#C0C0C0"</td>
    <td style="width: 24px; background-color: lime;">&nbsp;</td>
    <td><span>lime</span> = "#00FF00"</td>
   </tr>
   <tr>
    <td style="width: 24px; background-color: gray;">&nbsp;</td>
    <td><span>gray</span> = "#808080"</td>
    <td style="width: 24px; background-color: olive;">&nbsp;</td>
    <td><span>olive</span> = "#808000"</td>
   </tr>
   <tr>
    <td style="width: 24px; background-color: white;">&nbsp;</td>
    <td><span>white</span> = "#FFFFFF"</td>
    <td style="width: 24px; background-color: yellow;">&nbsp;</td>
    <td><span>yellow</span> = "#FFFF00"</td>
   </tr>
   <tr>
    <td style="width: 24px; background-color: maroon;">&nbsp;</td>
    <td><span>maroon</span> = "#800000"</td>
    <td style="width: 24px; background-color: navy;">&nbsp;</td>
    <td><span>navy</span> = "#000080"</td>
   </tr>
   <tr>
    <td style="width: 24px; background-color: red;">&nbsp;</td>
    <td><span>red</span> = "#FF0000"</td>
    <td style="width: 24px; background-color: blue;">&nbsp;</td>
    <td><span>blue</span> = "#0000FF"</td>
   </tr>
   <tr>
    <td style="width: 24px; background-color: purple;">&nbsp;</td>
    <td><span>purple</span> = "#800080"</td>
    <td style="width: 24px; background-color: teal;">&nbsp;</td>
    <td><span>teal</span> = "#008080"</td>
   </tr>
   <tr>
    <td style="width: 24px; background-color: fuchsia;">&nbsp;</td>
    <td><span>fuchsia</span> = "#FF00FF"</td>
    <td style="width: 24px; background-color: aqua;">&nbsp;</td>
    <td><span>aqua</span> = "#00FFFF"</td>
   </tr>
  </tbody>
 </table>

 <div class="note"><strong>Usage note:</strong> Do not use this attribute, as it has been deprecated. The {{HTMLElement("table")}} element should be styled using <a href="/en-US/docs/CSS">CSS</a>. Use the {{cssxref("background-color")}} property &nbsp;in&nbsp;<a href="/en-US/docs/CSS">CSS</a>&nbsp;to create an effect that is similar to the <span>bgcolor</span> attribute.</div>
 </dd>
</dl>

<dl>
 <dt>{{htmlattrdef("border")}} {{Deprecated_inline}}</dt>
 <dd>This integer attribute defines, in pixels, the size of the frame surrounding the table. If set to <span>0</span>, the {{htmlattrxref("frame", "table")}} attribute is set to <span>void</span>.
 <div class="note"><strong>Usage note:</strong> Do not use this attribute, as it has been deprecated. The {{HTMLElement("table")}} element should be styled using <a href="/en-US/docs/CSS">CSS</a>. To create&nbsp;an effect similar to the <span>border</span> attribute, the {{cssxref("border")}}, {{cssxref("border-color")}}, {{cssxref("border-width")}} and {{cssxref("border-style")}}&nbsp;properties in&nbsp;<a href="/en-US/docs/CSS">CSS</a> should be used.</div>
 </dd>
</dl>

<dl>
 <dt>{{htmlattrdef("cellpadding")}} {{Deprecated_inline}}</dt>
 <dd>This attribute defines the space between the content of a cell and its border, displayed or not. If the cellpadding's length is defined in pixels, this pixel-sized space will be applied to&nbsp;all four sides of the cell's content. If the length is defined using a percentage, the content will be centered and the total vertical space (top and bottom) will represent this percentage. The same is true for the total horizontal space (left and right).
 <div class="note"><strong>Usage note:</strong> Do not use this attribute, as it has been deprecated. The {{HTMLElement("table")}} element should be styled using <a href="/en-US/docs/CSS">CSS</a>. To create an effect similar to the cellpadding attribute, apply the&nbsp;{{cssxref("border-collapse")}} property to&nbsp;the {{HTMLElement("table")}} element, with its&nbsp;value set to collapse,&nbsp;and to the {{cssxref("padding")}} property in the&nbsp;{{HTMLElement("td")}} element.</div>
 </dd>
</dl>

<dl>
 <dt>{{htmlattrdef("cellspacing")}} {{Deprecated_inline}}</dt>
 <dd>This attribute defines the size of the space between two cells&nbsp;in percentage or pixels,. The&nbsp;attribute is applied&nbsp;both horizontally and vertically, to the space between the top of the table and the cells of the first row, the left of the table and the first column, the right of the table and the last column and the bottom of the table and the last row.
 <div class="note"><strong>Usage note:</strong> Do not use this attribute, as it has been deprecated. The {{HTMLElement("table")}} element should be styled using <a href="/en-US/docs/CSS">CSS</a>. To create&nbsp;an effect similar to the cellspacing&nbsp;attribute, apply the&nbsp;{{cssxref("border-spacing")}} property to&nbsp;the {{HTMLElement("table")}} element in <a href="/en-US/docs/CSS">CSS</a>. Border-spacing does not have any effect if&nbsp;{{cssxref("border-collapse")}} is set to collapse.</div>
 </dd>
</dl>

<dl>
 <dt>{{htmlattrdef("frame")}} {{Deprecated_inline}}</dt>
 <dd>This enumerated attribute defines which side of the frame surrounding the table must be displayed. It may have the following values:
 <table style="width:668px">
  <tbody>
   <tr>
    <td style="width: 24px; background-color: rgb(224, 224, 224);">&nbsp;</td>
    <td><span>above</span></td>
    <td style="width: 24px; background-color: rgb(224, 224, 224);">&nbsp;</td>
    <td><span>below</span></td>
   </tr>
   <tr>
    <td style="width: 24px; background-color: rgb(224, 224, 224);">&nbsp;</td>
    <td><span>hsides</span></td>
    <td style="width: 24px; background-color: rgb(224, 224, 224);">&nbsp;</td>
    <td><span>vsides</span></td>
   </tr>
   <tr>
    <td style="width: 24px; background-color: rgb(224, 224, 224);">&nbsp;</td>
    <td><span>lhs</span></td>
    <td style="width: 24px; background-color: rgb(224, 224, 224);">&nbsp;</td>
    <td><span>rhs</span></td>
   </tr>
   <tr>
    <td style="width: 24px; background-color: rgb(224, 224, 224);">&nbsp;</td>
    <td><span>border</span></td>
    <td style="width: 24px; background-color: rgb(224, 224, 224);">&nbsp;</td>
    <td><span>box</span></td>
   </tr>
   <tr>
    <td style="width: 24px; background-color: rgb(224, 224, 224);">&nbsp;</td>
    <td><span>void</span></td>
   </tr>
  </tbody>
 </table>

 <div class="note"><strong>Usage note:</strong> Do not use this attribute, as it has been deprecated. The {{HTMLElement("table")}} element should be styled using <a href="/en-US/docs/CSS">CSS</a>. To create&nbsp;an effect similar to the <span>frame</span> attribute, use the {{cssxref("border-style")}} and {{cssxref("border-width")}} properties in <a href="/en-US/docs/CSS">CSS</a>.</div>
 </dd>
</dl>

<dl>
 <dt>{{htmlattrdef("rules")}} {{Deprecated_inline}}</dt>
 <dd>This enumerated attribute defines where rules, i.e. lines, should appear in a table. It can have the following values:
 <ul>
  <li><span>none</span>, which indicates that no rules will be displayed; it is the default value;</li>
  <li><span>groups</span>, which will cause the rules to be displayed between row groups (defined by the {{HTMLElement("thead")}}, {{HTMLElement("tbody")}} and {{HTMLElement("tfoot")}} elements) and between column groups (defined by the {{HTMLElement("col")}} and {{HTMLElement("colgroup")}} elements) only;</li>
  <li><span>rows</span>, which will cause&nbsp;the rules to be displayed between rows;</li>
  <li><span>columns</span>, which will cause&nbsp;the rules to be displayed between columns;</li>
  <li><span>all</span>, which wil cause&nbsp;the rules to be displayed between rows and columns.</li>
 </ul>

 <div class="note"><strong>Note</strong>:

 <ul>
  <li>The styling of the rules is browser-dependant and cannot be modified.</li>
  <li>Do not use this attribute, as it has been deprecated. The&nbsp;rules should be defined and styled using <a href="/en-US/docs/CSS">CSS</a>. Apply the {{cssxref("border")}} property to&nbsp;the appropriate{{HTMLElement("thead")}}, {{HTMLElement("tbody")}}, {{HTMLElement("tfoot")}}, {{HTMLElement("col")}} or {{HTMLElement("colgroup")}} elements in <a href="/en-US/docs/CSS">CSS</a>.</li>
 </ul>
 </div>
 </dd>
</dl>

<dl>
 <dt>{{htmlattrdef("summary")}} {{Deprecated_inline}}</dt>
 <dd>This attribute defines an alternative text use to describe the table in user-agent unable to display it. Typically, it contents a description of it to allow visually impaired people, like blind people browsing the web using Braille screen, to get the information in it. If the information added in this attribute may also be useful for non-visually impaired people, consider using the {{HTMLElement("caption")}} instead. The summary attribute is not mandatory and may be omitted when a {{HTMLElement("caption")}} element fulfills its role.
 <div class="note"><strong>Usage Note: </strong>Do not use this attribute, as it has been deprecated. Instead, use one of these way of describing a table:
 <ul>
  <li>In prose, surrounding the table (this is the less semantic-conveying way of doing it).</li>
  <li>In the table's {{HTMLElement("caption")}} element.</li>
  <li>In a {{HTMLElement("details")}} element, inside the table's {{HTMLElement("caption")}} element.</li>
  <li>Include the {{HTMLElement("table")}} element in a {{HTMLElement("figure")}} element and add the description in prose next to it.</li>
  <li>Include the {{HTMLElement("table")}} element in a {{HTMLElement("figure")}} element and add the description in prose inside a {{HTMLElement("figcaption")}} element.</li>
  <li>Adjust the table so that such description is no more needed, by using {{HTMLElement("th")}} and {{HTMLElement("thead")}} elements for example.</li>
 </ul>
 </div>
 </dd>
</dl>

<dl>
 <dt>{{htmlattrdef("width")}} {{Deprecated_inline}}</dt>
 <dd>This attribute defines the width of the table. It may either be a pixel length or a percentage value, representing the percentage of the width of its container that the table should use.
 <div class="note"><strong>Usage Note: </strong>Do not use this attribute, as it has been deprecated and the rules should be defined and styled using <a href="/en-US/docs/CSS">CSS</a>. Use the <a href="/en-US/docs/CSS">CSS</a> property {{cssxref("width")}} instead.</div>
 </dd>
</dl>

<h2 id="DOM_interface">DOM interface</h2>

<p>This element implements the <code><a href="/en-US/docs/DOM/HTMLTableElement">HTMLTableElement</a></code> interface.</p>

<h2 id="Examples">Examples</h2>

<h3 id="Simple_Table">Simple Table</h3>

<pre class="brush: html">
&lt;table&gt;
  &lt;tr&gt;
    &lt;td&gt;John&lt;/td&gt;
    &lt;td&gt;Doe&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Jane&lt;/td&gt;
    &lt;td&gt;Doe&lt;/td&gt;
  &lt;/tr&gt;
&lt;/table&gt;
</pre>

<p>{{EmbedLiveSample('Simple_Table', '100%', '100', '', 'Web/HTML/Element/table')}}</p>

<h3 id="More_Examples">More Examples</h3>

<pre class="brush: html">
&lt;p&gt;Simple table with header&lt;/p&gt;
&lt;table&gt;
  &lt;tr&gt;
    &lt;th&gt;First name&lt;/th&gt;
    &lt;th&gt;Last name&lt;/th&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;John&lt;/td&gt;
    &lt;td&gt;Doe&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Jane&lt;/td&gt;
    &lt;td&gt;Doe&lt;/td&gt;
  &lt;/tr&gt;
&lt;/table&gt;

&lt;p&gt;Table with thead, tfoot, and tbody&lt;/p&gt;
&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Header content 1&lt;/th&gt;
      &lt;th&gt;Header content 2&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tfoot&gt;
    &lt;tr&gt;
      &lt;td&gt;Footer content 1&lt;/td&gt;
      &lt;td&gt;Footer content 2&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tfoot&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Body content 1&lt;/td&gt;
      &lt;td&gt;Body content 2&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Table with colgroup&lt;/p&gt;
&lt;table&gt;
  &lt;colgroup span="4"&gt;&lt;/colgroup&gt;
  &lt;tr&gt;
    &lt;th&gt;Countries&lt;/th&gt;
    &lt;th&gt;Capitals&lt;/th&gt;
    &lt;th&gt;Population&lt;/th&gt;
    &lt;th&gt;Language&lt;/th&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;USA&lt;/td&gt;
    &lt;td&gt;Washington D.C.&lt;/td&gt;
    &lt;td&gt;309 million&lt;/td&gt;
    &lt;td&gt;English&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Sweden&lt;/td&gt;
    &lt;td&gt;Stockholm&lt;/td&gt;
    &lt;td&gt;9 million&lt;/td&gt;
    &lt;td&gt;Swedish&lt;/td&gt;
  &lt;/tr&gt;
&lt;/table&gt;

&lt;p&gt;Table with colgroup and col&lt;/p&gt;
&lt;table&gt;
  &lt;colgroup&gt;
    &lt;col style="background-color: #0f0"&gt;
    &lt;col span="2"&gt;
  &lt;/colgroup&gt;
  &lt;tr&gt;
    &lt;th&gt;Lime&lt;/th&gt;
    &lt;th&gt;Lemon&lt;/th&gt;
    &lt;th&gt;Orange&lt;/th&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Green&lt;/td&gt;
    &lt;td&gt;Yellow&lt;/td&gt;
    &lt;td&gt;Orange&lt;/td&gt;
  &lt;/tr&gt;
&lt;/table&gt;

&lt;p&gt;Simple table with caption&lt;/p&gt;
&lt;table&gt;
  &lt;caption&gt;Awesome caption&lt;/caption&gt;
  &lt;tr&gt;
    &lt;td&gt;Awesome data&lt;/td&gt;
  &lt;/tr&gt;
&lt;/table&gt;
</pre>

<div class="hidden">
<pre class="brush: css">
table
{
border-collapse: collapse;
border-spacing: 0px;
}
table, th, td
{
padding: 5px;
border: 1px solid black;
}</pre>
</div>

<p>{{EmbedLiveSample('More_Examples', '100%', '700', '', 'Web/HTML/Element/table')}}</p>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<p>{{CompatibilityTable}}</p>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>1.0</td>
   <td>{{CompatGeckoDesktop("1")}}</td>
   <td>4.0<sup>[1]</sup></td>
   <td>7.0</td>
   <td>1.0</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Mobile</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>1.0</td>
   <td>{{CompatGeckoMobile("1")}}</td>
   <td>6.0<sup>[1]</sup></td>
   <td>6.0</td>
   <td>1.0</td>
  </tr>
 </tbody>
</table>
</div>

<p>[1] There is an Internet Explorer 9 rendering bug involving {{HTMLElement("table")}} and {{cssxref(":hover")}}; see <a href="/en-US/docs/Web/CSS/:hover#Browser_compatibility">the "Browser compatibility" section of the <code>:hover</code> article</a> for details.</p>

<h2 id="See_also">See also</h2>

<ul>
 <li>Other table-related HTML Elements: {{HTMLElement("caption")}}, {{HTMLElement("col")}}, {{HTMLElement("colgroup")}}, {{HTMLElement("tbody")}}, {{HTMLElement("td")}}, {{HTMLElement("tfoot")}}, {{HTMLElement("th")}}, {{HTMLElement("thead")}}, {{HTMLElement("tr")}};</li>
 <li>CSS properties that may be specially useful to style the <code>&lt;table&gt;</code> element:
  <ul>
   <li>{{cssxref("width")}} to control the width of the table;</li>
   <li>{{cssxref("border")}}, {{cssxref("border-style")}}, {{cssxref("border-color")}}, {{cssxref("border-width")}}, {{cssxref("border-collapse")}}, {{cssxref("border-spacing")}} to control the aspect of cell borders, rules and frame;</li>
   <li>{{cssxref("margin")}} and {{cssxref("padding")}} to style the individual cell content;</li>
   <li>{{cssxref("text-align")}} and {{cssxref("vertical-align")}} to define alignment of text and cell content.</li>
  </ul>
 </li>
</ul>
Revert to this revision