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 1055790 of <table>

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

Revision Content

{{HTMLRef}}

The HTML Table Element (<table>) represents tabular data: 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, and the {{HTMLElement("table")}} element should not be used for layout purposes.
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. one of the two alternatives:
    • one {{HTMLElement("tfoot")}} element, followed by:
      • either zero or more {{HTMLElement("tbody")}} elements,
      • or one or more {{HTMLElement("tr")}} elements,
    • a second alternative followed by an optional {{HTMLElement("tfoot")}} element:
      • either zero or more {{HTMLElement("tbody")}} elements,
      • or one or more {{HTMLElement("tr")}} elements
Tag omission None, both the start tag and the 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 the global attributes. The remainder of the attributes listed on this page may be deprecated.

{{htmlattrdef("align")}} {{Deprecated_inline}}
This enumerated attribute indicates how the table must be aligned in regard of the containing document. It may have the following values:
  • left, meaning that the table is to be displayed to the left of the document;
  • center, meaning that the table is to be displayed centered in the document;
  • right, meaning that the table is to be displayed to the right of the document.
Note
  • Do not use this attribute, as it has been deprecated and the {{HTMLElement("table")}} element should be styled using CSS. To give an effect similar to the align attribute, the CSS layout should be used, like {{cssxref("margin-left")}} and {{cssxref("margin-right")}} set to auto ( or {{cssxref("margin")}} to 0 auto) to center it.
  • 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 the table and its content. It is one of the 6-digit hexadecimal code as defined in sRGB, prefixed by a '#'. One of the sixteen predefined color strings may be used:
  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 and the {{HTMLElement("table")}} element should be styled using CSS. To give an effect similar to the bgcolor attribute, the CSS property {{cssxref("background-color")}} should be used.
{{htmlattrdef("border")}} {{Deprecated_inline}}
This integer attribute defines, in pixels, the size of the frame surrounding the table. If set to 0, it implies that the {{htmlattrxref("frame", "table")}} attribute is set to void.
Usage note: Do not use this attribute, as it has been deprecated and the {{HTMLElement("table")}} element should be styled using CSS. To give an effect similar to the border attribute, the CSS properties {{cssxref("border")}}, {{cssxref("border-color")}}, {{cssxref("border-width")}} and {{cssxref("border-style")}} should be used.
{{htmlattrdef("cellpadding")}} {{Deprecated_inline}}
This attribute defines the space between the content of a cell and the border, displayed or not, of it. If it is a pixel length, this pixel-sized space will be applied on all four sides; if it is a percentage length, 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 and the {{HTMLElement("table")}} element should be styled using CSS. To give an effect similar to the cellpadding attribute, use the CSS property {{cssxref("border-collapse")}} with the value collapse on the {{HTMLElement("table")}} element itself, and the property {{cssxref("padding")}} on the {{HTMLElement("td")}}.
{{htmlattrdef("cellspacing")}} {{Deprecated_inline}}
This attribute defines the size, in percentage or in pixels, of the space between two cells (both horizontally and vertically), 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 and the {{HTMLElement("table")}} element should be styled using CSS. To give an effect similar to the cellspacing attribute, use the CSS property {{cssxref("border-spacing")}} on the {{HTMLElement("table")}} element itself. 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 and the {{HTMLElement("table")}} element should be styled using CSS. To give an effect similar to the frame attribute, use the CSS properties {{cssxref("border-style")}} and {{cssxref("border-width")}}.
{{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 the no rules will be displayed; it is the default value;
  • groups, which will make 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 make the rules to be displayed between rows;
  • columns, which will make the rules to be displayed between columns;
  • all, which wil make 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 and the rules should be defined and styled using CSS. Use the CSS property {{cssxref("border")}} on the adequate {{HTMLElement("thead")}}, {{HTMLElement("tbody")}}, {{HTMLElement("tfoot")}}, {{HTMLElement("col")}} or {{HTMLElement("colgroup")}} elements.
{{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: 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, and the {{HTMLElement("table")}} element <strong>should</strong><strong> not</strong> be used for layout purposes.<!-- 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>one of the two alternatives:
      <ul>
       <li>one {{HTMLElement("tfoot")}} element, followed by:
        <ul>
         <li>either zero or more {{HTMLElement("tbody")}} elements,</li>
         <li>or one or more {{HTMLElement("tr")}} elements,</li>
        </ul>
       </li>
       <li>a second alternative followed by an optional {{HTMLElement("tfoot")}} element:
        <ul>
         <li>either zero or more {{HTMLElement("tbody")}} elements,</li>
         <li>or one or more {{HTMLElement("tr")}} elements</li>
        </ul>
       </li>
      </ul>
     </li>
    </ol>
    </div>
    </div>
   </td>
  </tr>
  <tr>
   <td>Tag omission</td>
   <td>None, both the <span title="syntax-start-tag">start tag</span> and the <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 the&nbsp;</span><a href="https://developer.mozilla.org/en-US/docs/HTML/Global_attributes">global attributes</a><span>. The remainder of the attributes listed on this page may be deprecated.</span></p>

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

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

 <ul>
  <li><strong>Do not use this attribute</strong>, as it has been deprecated and the {{HTMLElement("table")}} element should be styled using <a href="/en-US/docs/CSS">CSS</a>. To give an effect similar to the <code>align</code> attribute, the <a href="/en-US/docs/CSS">CSS</a> layout should be used, like {{cssxref("margin-left")}} and {{cssxref("margin-right")}} set to <code>auto</code> ( or {{cssxref("margin")}} to <code>0 auto</code>) to center it.</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>.</li>
 </ul>
 </div>
 </dd>
</dl>

<dl>
 <dt>{{htmlattrdef("bgcolor")}} {{Deprecated_inline}}</dt>
 <dd>This attribute defines the background color of the table and its content. It is one of the 6-digit hexadecimal code as defined in <a class="external" href="https://www.w3.org/Graphics/Color/sRGB">sRGB</a>, prefixed by a '#'. One of the sixteen predefined color strings may be used:
 <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 and the {{HTMLElement("table")}} element should be styled using <a href="/en-US/docs/CSS">CSS</a>. To give an effect similar to the <span>bgcolor</span> attribute, the <a href="/en-US/docs/CSS">CSS</a> property {{cssxref("background-color")}} should be used.</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>, it implies that 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 and the {{HTMLElement("table")}} element should be styled using <a href="/en-US/docs/CSS">CSS</a>. To give an effect similar to the <span>border</span> attribute, the <a href="/en-US/docs/CSS">CSS</a> properties {{cssxref("border")}}, {{cssxref("border-color")}}, {{cssxref("border-width")}} and {{cssxref("border-style")}} 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 the border, displayed or not, of it. If it is a pixel length, this pixel-sized space will be applied on all four sides; if it is a percentage length, 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 and the {{HTMLElement("table")}} element should be styled using <a href="/en-US/docs/CSS">CSS</a>. To give an effect similar to the cellpadding attribute, use the <a href="/en-US/docs/CSS">CSS</a> property {{cssxref("border-collapse")}} with the value collapse on the {{HTMLElement("table")}} element itself, and the property {{cssxref("padding")}} on the {{HTMLElement("td")}}.</div>
 </dd>
</dl>

<dl>
 <dt>{{htmlattrdef("cellspacing")}} {{Deprecated_inline}}</dt>
 <dd>This attribute defines the size, in percentage or in pixels, of the space between two cells (both horizontally and vertically), 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 and the {{HTMLElement("table")}} element should be styled using <a href="/en-US/docs/CSS">CSS</a>. To give an effect similar to the cellspacing&nbsp;attribute, use the <a href="/en-US/docs/CSS">CSS</a> property {{cssxref("border-spacing")}} on the {{HTMLElement("table")}} element itself. 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 and the {{HTMLElement("table")}} element should be styled using <a href="/en-US/docs/CSS">CSS</a>. To give an effect similar to the <span>frame</span> attribute, use the <a href="/en-US/docs/CSS">CSS</a> properties {{cssxref("border-style")}} and {{cssxref("border-width")}}.</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 the no rules will be displayed; it is the default value;</li>
  <li><span>groups</span>, which will make 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 make the rules to be displayed between rows;</li>
  <li><span>columns</span>, which will make the rules to be displayed between columns;</li>
  <li><span>all</span>, which wil make 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 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("border")}} on the adequate {{HTMLElement("thead")}}, {{HTMLElement("tbody")}}, {{HTMLElement("tfoot")}}, {{HTMLElement("col")}} or {{HTMLElement("colgroup")}} elements.</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