Help:Table

Tables are a way of organizing data using a series of columns and rows. Tables can be created on using the wikitext syntax, and are highly customizable.

As a general rule, it is best to avoid using a table unless it's necessary or there is a lot of data to organize. Tables can complicate page editing.

Table markup summary

 * All of the markup listed above must be placed on a new line, except for the double  and   for adding consecutive cells to a line. Any blank spaces placed at the beginning of a line are ignored.
 * All of the markup, except for the table end, optionally accepts one or more HTML attributes, which must be placed on the same line as the mark. Attributes should be separated from each other with a single space.
 * Cells and caption ( or ,   or  , and  ) hold content, so separate any attributes from its content with a single pipe . Cell content may follow on the same line or on the following lines.
 * Table and row marks ( and  ) do not directly hold content. Do not add a pipe  after their optional attributes.
 * Content may either follow its cell mark on the same line (after any optional HTML attributes), or on lines below the cell mark. Any content that normally needs to go on a new line, such as lists and headings, must go on a new line.
 * To insert the pipe character into a table, use the &lt;nowiki&gt; &lt;/nowiki&gt; escaping markup.

Inserting tables using the toolbar
The easiest way to insert a table is to use the "Insert table" option found on the edit toolbar.

To automatically insert a table, click on the or  buttons. The following text will be added: 

Which renders as:

You can customize this table as you see fit. For more advanced table settings, see below.

Basics
Tables, in their most basic form, do not contain any boxes or lines, making them a good way to place text side-by-side.


 * style="width:50%; background:#f9f9f9; border-width:1px;border-style:solid none none solid;border-color:#ddd; padding:9px 5px 5px; vertical-align:top;"|
 * style="width:50%; border-width:1px;border-style:solid none none none;border-color:#ddd; padding:5px; vertical-align:top;"|
 * style="width:50%; border-width:1px;border-style:solid none none none;border-color:#ddd; padding:5px; vertical-align:top;"|
 * }
 * }

Cells in the same row can be listed on the same line if they are separated by two pipe symbols. If the text in the cell should contain a line break, use  instead.


 * style="width:50%; background:#f9f9f9; border-width:1px;border-style:solid none none solid;border-color:#ddd; padding:9px 5px 5px; vertical-align:top;"|
 * style="width:50%; border-width:1px;border-style:solid none none none;border-color:#ddd; padding:5px; vertical-align:top;"|
 * style="width:50%; border-width:1px;border-style:solid none none none;border-color:#ddd; padding:5px; vertical-align:top;"|
 * }
 * }

Single line breaks are taken into account on the line where the cell marker is; the following lines are rendered like normal wiki markup (single line breaks are ignored; other formatting, such as lists and even other tables, can be used).


 * style="width:50%; background:#f9f9f9; border-width:1px;border-style:solid none none solid;border-color:#ddd; padding:9px 5px 5px; vertical-align:top;"|
 * style="width:50%; border-width:1px;border-style:solid none none none;border-color:#ddd; padding:5px; vertical-align:top;"|
 * style="width:50%; border-width:1px;border-style:solid none none none;border-color:#ddd; padding:5px; vertical-align:top;"|
 * }
 * }

class="wikitable"
Tables can utilize a "class" parameter that loads predefined CSS into the table for styling. All wikis come with  available by default, which provides basic styling (by default, this is a light gray background, borders, padding and align left) for tables. More CSS classes can be added at MediaWiki:Common.css.


 * style="width:50%; background:#f9f9f9; border-width:1px;border-style:solid none none solid;border-color:#ddd; padding:9px 5px 5px; vertical-align:top;"|
 * style="width:50%; border-width:1px;border-style:solid none none none;border-color:#ddd; padding:5px; vertical-align:top;"|
 * style="width:50%; border-width:1px;border-style:solid none none none;border-color:#ddd; padding:5px; vertical-align:top;"|
 * }
 * }

Table headers
Table headers are created by using an exclamation mark instead of a pipe. Headers show up bold and centered by default, and are usually placed at the top or leftmost-side of the table.


 * style="width:50%; background:#f9f9f9; border-width:1px;border-style:solid none none solid;border-color:#ddd; padding:9px 5px 5px; vertical-align:top;"|
 * style="width:50%; border-width:1px;border-style:solid none none none;border-color:#ddd; padding:5px; vertical-align:top;"|
 * style="width:50%; border-width:1px;border-style:solid none none none;border-color:#ddd; padding:5px; vertical-align:top;"|
 * }
 * }

Note that, when using attributes, the pipe character is always used for separation, never an exclamation mark. More information on attributes is shown below.

Caption
A table caption can be added to the top of any table. They appear centered by default, and bolded if  is used.


 * style="width:50%; background:#f9f9f9; border-width:1px;border-style:solid none none solid;border-color:#ddd; padding:9px 5px 5px; vertical-align:top;"|
 * style="width:50%; border-width:1px;border-style:solid none none none;border-color:#ddd; padding:5px; vertical-align:top;"|
 * style="width:50%; border-width:1px;border-style:solid none none none;border-color:#ddd; padding:5px; vertical-align:top;"|
 * }
 * }

HTML colspan and rowspan
The HTML  and   attributes allow you to create cells that span multiple columns (horizontally) and/or multiple rows (vertically). For example, specifying  will cause the cell to span two columns instead of just one. When this is done, the table code must exclude the cells that are covered by such a span. The resulting row- and column-counting must fit.


 * style="width:50%; background:#f9f9f9; border-width:1px;border-style:solid none none solid;border-color:#ddd; padding:9px 5px 5px; vertical-align:top;"|
 * style="width:50%; border-width:1px;border-style:solid none none none;border-color:#ddd; padding:5px; vertical-align:top;"|
 * style="width:50%; border-width:1px;border-style:solid none none none;border-color:#ddd; padding:5px; vertical-align:top;"|
 * }
 * }

Sortable headers
It is possible to configure the columns of a table to be sortable, meaning that they will be sorted in alphabetical order when the headers are clicked (it is currently not possible to make a table be sorted automatically upon page load, aside from manually sorting the table in the wikitext of the page). To do this, add  to the   declaration, and ensure that the table is using headers (i.e. using an exclamation mark instead of a pipe character at the start).


 * style="width:50%; background:#f9f9f9; border-width:1px;border-style:solid none none solid;border-color:#ddd; padding:9px 5px 5px; vertical-align:top;"|
 * style="width:50%; border-width:1px;border-style:solid none none none;border-color:#ddd; padding:5px; vertical-align:top;"|
 * style="width:50%; border-width:1px;border-style:solid none none none;border-color:#ddd; padding:5px; vertical-align:top;"|
 * }
 * }

HTML attributes
Tables can accept HTML attributes to provide further customization and styling. For an authoritative source on HTML attributes for tables, see the W3C's website.

Attributes on tables
Attributes placed after the start tag will apply to the entire table.


 * style="width:50%; background:#f9f9f9; border-width:1px;border-style:solid none none solid;border-color:#ddd; padding:9px 5px 5px; vertical-align:top;"|
 * style="width:50%; border-width:1px;border-style:solid none none none;border-color:#ddd; padding:5px; vertical-align:top;"|
 * style="width:50%; border-width:1px;border-style:solid none none none;border-color:#ddd; padding:5px; vertical-align:top;"|
 * }
 * }

Attributes on cells
Attributes placed after the cell mark will apply to the respective cell. Note that the attribute must be separated from the content of the cell by a pipe character.


 * style="width:50%; background:#f9f9f9; border-width:1px;border-style:solid none none solid;border-color:#ddd; padding:9px 5px 5px; vertical-align:top;"|
 * style="width:50%; border-width:1px;border-style:solid none none none;border-color:#ddd; padding:5px; vertical-align:top;"|
 * style="width:50%; border-width:1px;border-style:solid none none none;border-color:#ddd; padding:5px; vertical-align:top;"|
 * }
 * }

If you are listing multiple cells on the same line, the attributes are placed after the double marks. They must still be separated from the cell content by a single mark.


 * style="width:50%; background:#f9f9f9; border-width:1px;border-style:solid none none solid;border-color:#ddd; padding:9px 5px 5px; vertical-align:top;"|
 * style="width:50%; border-width:1px;border-style:solid none none none;border-color:#ddd; padding:5px; vertical-align:top;"|
 * style="width:50%; border-width:1px;border-style:solid none none none;border-color:#ddd; padding:5px; vertical-align:top;"|
 * }
 * }

Attributes on rows
Attributes placed after the table row marker will apply to the entire row.


 * style="width:50%; background:#f9f9f9; border-width:1px;border-style:solid none none solid;border-color:#ddd; padding:9px 5px 5px; vertical-align:top;"|
 * style="width:50%; border-width:1px;border-style:solid none none none;border-color:#ddd; padding:5px; vertical-align:top;"|
 * style="width:50%; border-width:1px;border-style:solid none none none;border-color:#ddd; padding:5px; vertical-align:top;"|
 * }
 * }

Attributes on captions
Attributes placed after the table caption marker will apply to the caption.


 * style="width:50%; background:#f9f9f9; border-width:1px;border-style:solid none none solid;border-color:#ddd; padding:9px 5px 5px; vertical-align:top;"|
 * style="width:50%; border-width:1px;border-style:solid none none none;border-color:#ddd; padding:5px; vertical-align:top;"|
 * style="width:50%; border-width:1px;border-style:solid none none none;border-color:#ddd; padding:5px; vertical-align:top;"|
 * }
 * }

Simple one-pixel table border

 * style="width:50%; background:#f9f9f9; border-width:1px;border-style:solid none none solid;border-color:#ddd; padding:9px 5px 5px; vertical-align:top;"|
 * style="width:50%; border-width:1px;border-style:solid none none none;border-color:#ddd; padding:5px; vertical-align:top;"|
 * style="width:50%; border-width:1px;border-style:solid none none none;border-color:#ddd; padding:5px; vertical-align:top;"|
 * }
 * }

Border width
If  is called with only one number, it will apply to all four sides of the table.
 * style="width:50%; background:#f9f9f9; border-width:1px;border-style:solid none none solid;border-color:#ddd; padding:9px 5px 5px; vertical-align:top;"|
 * style="width:50%; border-width:1px;border-style:solid none none none;border-color:#ddd; padding:5px; vertical-align:top;"|
 * style="width:50%; border-width:1px;border-style:solid none none none;border-color:#ddd; padding:5px; vertical-align:top;"|
 * }
 * }

If  is called with more than one number, the four numbers are for top, right, bottom, left. Remember this order! If there is more than one number but less than four, the value for left takes its default from the value for right, the value for bottom takes its default from the value for top, and the value for right takes its default from the value for top.


 * style="width:50%; background:#f9f9f9; border-width:1px;border-style:solid none none solid;border-color:#ddd; padding:9px 5px 5px; vertical-align:top;"|
 * style="width:50%; border-width:1px;border-style:solid none none none;border-color:#ddd; padding:5px; vertical-align:top;"|
 * style="width:50%; border-width:1px;border-style:solid none none none;border-color:#ddd; padding:5px; vertical-align:top;"|
 * }
 * }

A better way to define the border width for each side is to use,  ,  , and.


 * style="width:50%; background:#f9f9f9; border-width:1px;border-style:solid none none solid;border-color:#ddd; padding:9px 5px 5px; vertical-align:top;"|
 * style="width:50%; border-width:1px;border-style:solid none none none;border-color:#ddd; padding:5px; vertical-align:top;"|
 * style="width:50%; border-width:1px;border-style:solid none none none;border-color:#ddd; padding:5px; vertical-align:top;"|
 * }
 * }

With HTML attributes and CSS styles
CSS style attributes can be used in tables as well. They can be combined with other HTML attributes, or just used on their own.


 * style="width:50%; background:#f9f9f9; border-width:1px;border-style:solid none none solid;border-color:#ddd; padding:9px 5px 5px; vertical-align:top;"|
 * style="width:50%; border-width:1px;border-style:solid none none none;border-color:#ddd; padding:5px; vertical-align:top;"|
 * style="width:50%; border-width:1px;border-style:solid none none none;border-color:#ddd; padding:5px; vertical-align:top;"|
 * }
 * }

Padding
Padding can be applied to specify the amount of space between the cell walls and the contents of the cell.
 * style="width:50%; background:#f9f9f9; border-width:1px;border-style:solid none none solid;border-color:#ddd; padding:9px 5px 5px; vertical-align:top;"|
 * style="width:50%; border-width:1px;border-style:solid none none none;border-color:#ddd; padding:5px; vertical-align:top;"|
 * style="width:50%; border-width:1px;border-style:solid none none none;border-color:#ddd; padding:5px; vertical-align:top;"|
 * }
 * }

Column width
The  style attribute can be added after the table start  to specify the width of the entire table. Like other attributes, it can be placed after the cell mark to specify the width of the column.

You type:

You get:

Accessibility of table cells
Table header cells do not explicitly specify which table data cells they apply to (those on their right on the same row, or those below them on the same column). When the table is rendered in a visual 2D environment, this is usually easy to infer. However, when tables are rendered in a non-visual environment, such as for screen readers, it can be helpful to specify which table header cell applies to the description of any selected cell using the  and   attributes. In most cases with simple tables, you'll use  on all header cells of the first row, and   on the first cell of the following rows:


 * style="width:50%; background:#f9f9f9; border-width:1px;border-style:solid none none solid;border-color:#ddd; padding:9px 5px 5px; vertical-align:top;"|
 * style="width:50%; border-width:1px;border-style:solid none none none;border-color:#ddd; padding:5px; vertical-align:top;"|
 * style="width:50%; border-width:1px;border-style:solid none none none;border-color:#ddd; padding:5px; vertical-align:top;"|
 * }
 * }

Table alignment
Table alignment is achieved by using CSS. Alignment is controlled by margins; a fixed margin on one side will align that table on that side, if the margin on the opposite site is defined as auto. For example, to align a table to the right, set the left margin to be auto, and the right margin to be 0px.


 * style="width:50%; background:#f9f9f9; border-width:1px;border-style:solid none none solid;border-color:#ddd; padding:9px 5px 5px; vertical-align:top;"|
 * style="width:50%; border-width:1px;border-style:solid none none none;border-color:#ddd; padding:5px; vertical-align:top;"|
 * style="width:50%; border-width:1px;border-style:solid none none none;border-color:#ddd; padding:5px; vertical-align:top;"|
 * }
 * }

To center-align a table, set both margins to auto.


 * style="width:50%; background:#f9f9f9; border-width:1px;border-style:solid none none solid;border-color:#ddd; padding:9px 5px 5px; vertical-align:top;"|
 * style="width:50%; border-width:1px;border-style:solid none none none;border-color:#ddd; padding:5px; vertical-align:top;"|
 * style="width:50%; border-width:1px;border-style:solid none none none;border-color:#ddd; padding:5px; vertical-align:top;"|
 * }
 * }

Table floating around text
By default, tables break the text they are in, meaning that text does not appear on the sides of the table, which can make it look clearer. You can use the  attribute to allow the text to wrap around the table instead. When  is used, margins do not control the table alignment and are used instead to specify the margin between the table and the surrounding text.

Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
 * style="width:50%; background:#f9f9f9; border-width:1px;border-style:solid none none solid;border-color:#ddd; padding:9px 5px 5px; vertical-align:top;"|

Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
 * style="width:50%; border-width:1px;border-style:solid none none none;border-color:#ddd; padding:5px; vertical-align:top;"|
 * style="width:50%; border-width:1px;border-style:solid none none none;border-color:#ddd; padding:5px; vertical-align:top;"|
 * }
 * }

Cell contents alignment
The alignment of the cell content themselves can be controlled using the  and   CSS properties. can be applied to the entire table, row or individual cells, while  only can be applied to individual rows and cells.


 * style="width:50%; background:#f9f9f9; border-width:1px;border-style:solid none none solid;border-color:#ddd; padding:9px 5px 5px; vertical-align:top;"|
 * style="width:50%; border-width:1px;border-style:solid none none none;border-color:#ddd; padding:5px; vertical-align:top;"|
 * style="width:50%; border-width:1px;border-style:solid none none none;border-color:#ddd; padding:5px; vertical-align:top;"|
 * }
 * }

Negative numbers
If you start a cell on a new line that starts with a minus sign (-), such as to list a negative number, the table may break as the minus sign will be interpreted together with the cell mark to mean a new row, not a table cell. To avoid this, insert a space before the value or use in-line cell markup.

! Item ! Expense
 * style="width:50%; background:#f9f9f9; border-width:1px;border-style:solid none none solid;border-color:#ddd; padding:9px 5px 5px; vertical-align:top;"|
 * style="width:50%; border-width:1px;border-style:solid none none none;border-color:#ddd; padding:5px; vertical-align:top;"|
 * style="width:50%; border-width:1px;border-style:solid none none none;border-color:#ddd; padding:5px; vertical-align:top;"|
 * style="width:50%; background:#f9f9f9; border-width:1px;border-style:solid none none solid;border-color:#ddd; padding:9px 5px 5px; vertical-align:top;"| {| class="wikitable"
 * style="width:50%; background:#f9f9f9; border-width:1px;border-style:solid none none solid;border-color:#ddd; padding:9px 5px 5px; vertical-align:top;"| {| class="wikitable"
 * style="width:50%; background:#f9f9f9; border-width:1px;border-style:solid none none solid;border-color:#ddd; padding:9px 5px 5px; vertical-align:top;"| {| class="wikitable"
 * Housing and Utilities
 * 900
 * Food
 * 700
 * Transportation
 * -200
 * Medical
 * 0
 * }
 * Medical
 * 0
 * }
 * }
 * style="width:50%; background:#f9f9f9; border-width:1px;border-style:solid none none solid;border-color:#ddd; padding:9px 5px 5px; vertical-align:top;"|
 * }

CSS vs attributes
Table borders specified through CSS rather than the border attribute will render incorrectly in a small subset of text browsers.

Common attributes for columns, column groups and row groups
The MediaWiki syntax for tables currently offers no support for specifying common attributes for columns (with the HTML element ), column groups (HTML element  ) and row groups (HTML elements ,   and  ). Those standard HTML elements are not accepted even in their HTML or XHTML syntax.

All the rows and cells (header or data) of the table are rendered within a single implicit row group (HTML element ) without any attributes or styles.