A wikitable is an arrangement of columns and rows used to organize and position data. Tables are useful for this purpose and there are many different styles and tricks that can be used to customise each. This page gives you information about syntax to build wikitables in Wikipedia.
The following text is inserted when Insert a table is clicked:
| Example |
| Example |
| Example |
| Example |
| Example |
| Example |
Although HTML table syntax also works, special wikicode can be used as a shortcut to create a table. The pipe () codes function exactly the same as markup, so a knowledge of HTML table code will help in understanding pipe code. The shortcuts are as follows:
'''{|''' ''table code goes here'' '''|}'''
{|
'''| ''caption'''''
''table code goes here''
|}
{|
| The table's caption
'''|-'''
''row code goes here''
'''|-'''
''next row code goes here''
|}
{|
| The table's caption
|-
'''|''' ''cell code goes here''
|-
'''|''' ''next row cell code goes here''
'''|''' ''next cell code goes here''
|}
{|
| The table's caption
|-
'''|Cell 1 || Cell 2 || Cell 3'''
|-
'''|Cell A'''
'''|Cell B'''
'''|Cell C'''
|}
{| border="1"
|-
|format modifier (not displayed) '''|'''These all '''|'''(including the pipes) '''|'''go into '''|'''the first cell||second cell
|-
|format '''|'''These all '''||'''format '''|'''go into '''|'''the second cell
|}
which is probably not what you expected:
| second cell |
| the second cell |
{| border="1"
|-
| Cell 1 (no modifier—not aligned)
|-
| align="right" | Cell 2 (right aligned)
|}
| Cell 1 (no modifier—not aligned) |
| Cell 2 (right aligned) |
Just remember: no more than 2 single pipes on a line!
{|
| The table's caption
'''! scope="col" | Column heading 1'''
'''! scope="col" | Column heading 2'''
'''! scope="col" | Column heading 3'''
|-
| Cell 1 || Cell 2 || Cell 3
|-
| Cell A
| Cell B
| Cell C
|}
{|
| The table's caption
! scope="col" | Column heading 1
! scope="col" | Column heading 2
! scope="col" | Column heading 3
|-
'''! scope="row" | Row heading 1'''
| Cell 2 || Cell 3
|-
'''! scope="row" | Row heading A'''
| Cell B
| Cell C
|}
{| '''border="1"'''
| The table's caption
! scope="col" | Column heading 1
! scope="col" | Column heading 2
! scope="col" | Column heading 3
|-
! scope="row" | Row heading 1
| Cell 2 || Cell 3
|-
! scope="row" | Row heading A
| Cell B
| Cell C
|}
The final table would display like this:
| The table's caption ! scope="col" | Column heading 1 ! scope="col" | Column heading 2 ! scope="col" | Column heading 3 |
If you want narrow one-pixel wide borders around all the cells use this in the top line of the table:
{| border="1" style="border-collapse:collapse;"
Here is the revised table:
| The table's caption ! scope="col" | Column heading 1 ! scope="col" | Column heading 2 ! scope="col" | Column heading 3 |
The simplest way is to use Wikipedia's external style sheet for tables: class="wikitable" and so on.
| The table's caption ! Column heading 1 ! Column heading 2 ! Column heading 3 |
It produces this:
| The table's caption ! Column heading 1 ! Column heading 2 ! Column heading 3 |
The table parameters and cell parameters are the same as in , see http://www.w3.org/TR/html401/struct/tables.html#edef-TABLE and . However, the colgroup and col elements are currently not supported in MediaWiki. Thead, tbody and tfoot are supported from Mediawiki version 1.18 on ( Current version on Wikipedia: ).
A table can be useful even if none of the cells have content. For example, the background colors of cells can be changed with cell parameters, making the table into a diagram, like . An "image" in the form of a table is much more convenient to edit than an uploaded image.
Each row must have the same number of cells as the other rows, so that the number of columns in the table remains consistent. For empty cells, use the non-breaking space &nbsp; as content to ensure that the cells are displayed. To show a visible pipe in a cell, use <nowiki>|</nowiki> or &#124;.
With colspan and rowspan cells can span several columns or rows, see the Mélange example below. However, this has the disadvantage that sorting does not work properly anymore.
Wiki markup:
| A | B |
| C | D |
| B |
| D |
As it appears in a browser (note that there are no borders):
| A | B |
| C | D |
Wiki markup:
| Multiplication table |
As it appears in a browser:
| Multiplication table |
Wiki markup:
| ghi |
| pqr |
| yz |
As it appears in a browser:
| ghi |
| pqr |
| yz |
Note that style="inline CSS" has no effect with some browsers. If compatibility is important, equivalent older constructs like width="75%" should work on more browsers.
Wiki markup:
| Green star |
| Green star |
As long as the "Image:" specs omit the parameter "thumb|" they will not show the caption lines in the table (only during mouse-over). The border color "darkgray" matches typical tables or infoboxes in articles; however, it could be any color name (such as style="border: 1px solid darkgreen;") or use a hex-color (such as: #DDCCBB).
A column format-specifier (enclosed in "|...|") can have a style-parameter to set borders on each cell, as follows:
Wiki markup:
| Green star |
Note only the image cells, here, have individual borders, not the text.
| Green star |
Prior to April 2009, using "float" to position a table was discouraged; however, it no longer always breaks page rendering at large font sizes. See a floated image, below, under "Floating images in the center".
This paragraph is before the table. Lorem ipsum dolor sit
amet, consectetur adipisicing elit, sed do eiusmod...
| Col 1, row 1 | Col 2, row 1 (and 2) | Col 3, row 1 |
| Col 1, row 2 | Col 3, row 2 |
Note the floating-table to the right.
This paragraph is after the table. The text in column 2 will span both rows due to format specifier "rowspan=2" so there is no coding for "Col 2" in the 2nd row, just: Col 1 & Col 3.
As it appears in a browser:
| Col 1, row 1 | Col 2, row 1 (and 2) | Col 3, row 1 |
| Col 1, row 2 | Col 3, row 2 |
This paragraph is after the table. The text in column 2 will span both rows due to format specifier "rowspan=2" so there is no coding for "Col 2" in the 2nd row, just: Col 1 & Col 3.
Wiki markup:
Text before table...
| Cells left-aligned, table centered ! scope="col" | Duis ! scope="col" | aute ! scope="col" | irure |
| in voluptate velit | |||
| pariatur. |
As it appears in a browser:
| Cells left-aligned, table centered ! Duis | irure |
| in voluptate velit | |
| pariatur. |
Seven different (blue) tables are shown nested inside the cells of a table. Automatically the two tables |A| and |B|B| are vertically aligned instead of the usual side by side of text characters in a cell. "float" is used to fix each of tables |C| and |D| to their own position within one cell of the table. This may be used for charts and schemes. Nested tables must start on a new line.
Wiki markup
<nowiki></nowiki> border="1"<br /> | &alpha;<br /> | style="text-align: center;"| cell2<br /> <span style="color: navy;"> '''<nowiki></nowiki> border="2" style="background: #ABCDEF;"''' <nowiki></nowiki><br /> '''| NESTED'''<br /> '''|-'''<br /> '''| TABLE'''<br /> '''<nowiki></nowiki>'''<br /> </span> | style="vertical-align:bottom;"| the original table again<br /> | style="width:100px;" |<br /> <span style="color: navy;"> '''<nowiki></nowiki> border="2" style="background: #ABCDEF;"'''<br /> '''| A'''<br /> '''<nowiki></nowiki>'''<br /> '''<nowiki></nowiki> border="2" style="background: #ABCDEF;"'''<br /> '''| B || B'''<br /> '''<nowiki></nowiki>'''<br /> </span> | style="width:50px;" |<br /> <span style="color: navy;"> '''<nowiki></nowiki> border="2" style="background: #ABCDEF; float:left;"'''<br /> '''| C'''<br /> '''<nowiki></nowiki>'''<br /> '''<nowiki></nowiki> border="2" style="background: #ABCDEF; float: right;"'''<br /> '''| D'''<br /> '''<nowiki></nowiki>'''<br /> </span> <nowiki></nowiki>
As it appears in a browser:
| α | cell2 { | border="2" style="background: #ABCDEF;" |
| NESTED | ||
| TABLE |
| A |
| B |
| C |
| D |
Wiki markup:
ghi pqr yz
As it appears in a browser:
| ghi |
| pqr |
| yz |
Wiki markup:
| abc | def | ghi | jkl |
As it appears in a browser:
| abc | def | ghi | jkl |
Like other parameters, colors can also be specified for a whole row or the whole table; parameters for a row override the value for the table, and those for a cell override those for a row. (Note that there is no easy way to specify a color for a whole column—each cell in the column must be individually specified. Tools can make it easier.)
Wiki markup:
| yz |
| yz |
| yz |
As it appears in a browser:
| yz |
| yz |
| yz |
To make the table blend in with the background, use style="background: none;" or style="background: transparent;". (Warning: style="background: inherit;", does not work with some browsers, including IE6!)
To force a cell to match one of the default colors of the class="wikitable" template, use style="background: #f2f2f2" for the darker header, and style="background: #f9f9f9" for the lighter body.
See: , , , and the template .
Wiki markup:
| cell2 | cell3 |
As it appears in a browser:
| cell3 |
To fix this, apply the valign="top" attribute to the rows (unfortunately it seems to be necessary to apply this individually to every single row).
Wiki markup:
Wiki markup:
| 1 |
| 2 |
| 1 |
| 2 |
Wiki markup:
| All versions |
| All versions |
| All versions |
| All versions |
To set column widths in a table without headers, specify the width in the first cell for each column.
Wiki markup:
| This column is 100 points wide | This column is 200 points wide | This column is 300 points wide |
| bluh |
| This column is 100 points wide | This column is 200 points wide | This column is 300 points wide |
| bluh |
One application of setting the widths is aligning columns of consecutive tables:
| Amsterdam |
| Paris |
Without 'nowrap', as it appears in a browser:
| "The Journey Begins" | January 1, 2010 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. |
| "When Episodes Attack" | January 8, 2010 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. |
| "So Long" | January 15, 2010 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. |
With 'nowrap', as it appears in a browser:
| "The Journey Begins" | January 1, 2010 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. |
| "When Episodes Attack" | January 8, 2010 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. |
| "So Long" | January 15, 2010 | Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. |
Here is a more advanced example, showing some more options available for making up tables. Note however that with colspan and rowspan sorting does not work properly anymore.
Users can play with these settings in their own table to see what effect they have. Not all of these techniques may be appropriate in all cases; just because colored backgrounds can be added, for example, does not mean it is always a good idea. Try to keep the markup in tables relatively simple—remember, other people are going to be editing the article too! This example should give an idea of what is possible, though.
Wiki markup:
Text before centered table...
| An example table | ||
| upper left | | right side |
| lower left | lower middle | |
| Text before a nested table... { border="0" | A table in a table | |
| Two Wikipedia logos |
As it appears in a browser:
| An example table | ||
| upper left | | right side |
| lower left | lower middle | |
| Text before a nested table... { border="0" | A table in a table | |
| Two Wikipedia logos |
Temple of Bel (floating). |
The text inside the floating-table is sized by style="font-size: 86%;". That floating-image table floats a typical image-box, but allows adjusting the left-hand margin of the image (see temple-example floating below).
| This sample infobox shows how the floating image-box aligns toward the center. |
Temple of Bel (floating). |
An image set with parameter "left|" will gain a wide right-side margin (opposite margin of parameter "right|"), so floating toward the left would require an image set as "center|" inside a table with style="float:left; margin:0.46em 0.2em".
Recall that, outside an image-table, the parameter "right|" causes an image to align (either) above or below an infobox, but would not float alongside the infobox.
Note the order of precedence: first come infoboxes or images using "right|", then come the floating-tables, and lastly, any text will wrap that can still fit. If the first text-word is too long, no text will fit to complete the left-hand side, so beware creating a "ragged left margin" when not enough space remains for text to fit alongside floating-tables.
If multiple single image-tables are stacked, they will float to align across the page, depending on page-width. The text will be squeezed to allow as many floating-tables as can fit, as auto-aligned, then wrap whatever text (can still fit) at the left-hand side.
...by float: right |
...images wrap... |
All these... |
That auto-aligning feature can be used to create a "floating-gallery" of images: a set of 20 floating-tables will wrap (backward, right-to-left) as if each table were a word of text to wrap across and down the page. To wrap in the typical direction (wrapping left-to-right) define all those floating-tables, instead, as left-side tables using the top parameter style="float:left; margin:0.46em 0.2em". Multiple floating-images empower more flexible typesetting of images around the text.
| Column 3 | ||
| A | B | |
| C | D | |
| E | F | |
| G | ||
| H | ||
As it appears in a browser:
| Column 3 | ||
| A | B | |
| C | D | |
| E | F | |
| G | ||
| H | ||
Note that using rowspan="2" for cell G combined with rowspan="3" for cell F to get another row below G and F won't work, because all (implicit) cells would be empty. Likewise complete columns are not displayed if all their cells are empty. Borders between non-empty and empty cells might be also not displayed (depending on the browser), use &nbsp; to fill an empty cell with dummy content.
Wiki markup:
| .1 |
| .21 |
| .321 |
As it appears in a browser:
| .1 |
| .21 |
| .321 |
If the column of numbers appears in a table with cell padding or cell spacing, you can still align the decimal points without an unsightly gap in the middle. Embed a table in each number's cell and specify its column widths. Make the embedded tables' column widths the same for each cell in the column. (If decimal points are still misaligned using this method, the main table's column may be too narrow. Add a parameter to increase the column's width.)
Wiki markup:
| { cellpadding="0" cellspacing="0" width="100" | .1 |
| .21 |
| .321 |
As it appears in a browser:
| { cellpadding="0" cellspacing="0" style="width: 100px;" |
| .1 |
| .21 |
| .321 |
In the case of preformatted text, you can dispense with the table feature entirely and simply start the lines with a space, and put spaces to position the numbers:
Wiki markup (just spaces!):
432.1
43.21
4.321
As it appears in a browser:
432.1
43.21
4.321
However, there should be a good reason to use pre-formatted text in an article.
Instead of remembering table parameters, you just include an appropriate class after the {|. This helps keep table formatting consistent, and can allow a single change to the class to fix a problem or enhance the look of all the tables that are using it at once. For instance, this: { | border="0" style="margin: auto;" | |
{| style="margin: 1em auto 1em auto;" |
{ cellpadding="2"
| Multiplication table |
{|| Multiplication table |
simply by replacing inline CSS for the table by class="wikitable". This is because the wikitable class in contains a number of table.wikitable style rules. These are all applied at once when you mark a table with the class. You can then add additional style rules if desired. These override the class's rules, allowing you to use the class style as a base and build up on it:
Wiki markup
{|As it appears in a browser:
| Multiplication table |
Notice that the table retains the gray background of the wikitable class, and the headers are still bold and centered. But now the text formatting has been overridden by the local style statement; all of the text in the table has been made italic and 120% normal size, and the wikitable border has been replaced by the red dashed border.
Of course this works only for browsers supporting inline CSS, if it's important use XHTML markup like <big> instead of "font-size:120%", or Wiki markup like <nowiki></nowiki> instead of "font-style:italic".
| Content which starts hidden |
| more hidden content |
Gives:
| Content which starts hidden |
| more hidden content |
{ | class="wikitable sortable mw-collapsible" |
| Content which starts visible | |
| more visible content |
| class="wikitable sortable mw-collapsible mw-collapsed" |
| Content which starts hidden |
| more hidden content |
A long form of abbreviated content can be put as legend outside the table.
Wiki markup
As it appears in a browser:
| Sortable table |
| This |
| column |
| cannot |
| be |
| sorted. |
Wiki markup
|}
As it appears in a browser:
| Sortable and collapsible table |
| This |
| column |
| cannot |
| be |
| sorted. |
If you want the table to default to collapsed state, use the code {| class="wikitable sortable collapsible collapsed" in place of {| class="wikitable sortable collapsible"
{|
<nowiki></nowiki>
Note that each anchor names must be different from every other in the page (this includes heading names), to create valid XHTML.
Example:
Using
|
| ! scope="row" row three, column one row three, column two |
|
| ! scope="row" row three, column one row three, column two |
All three are supported by MediaWiki and create (currently) valid HTML output, but the pipe syntax is the simplest. Also, HTML & wiki-{| syntax (i.e., unclosed |} and {| tags) will not necessarily remain browser-supported in the future, especially on handheld internet-accessible devices.
See also . Note however that the thead, tbody, tfoot, colgroup, and col elements are currently not supported in MediaWiki.
| ! scope="col" XHTML ! scope="col" | Wiki-pipe |
|caption
| caption|- ! scope="row" | Row |
|
|-|- ! scope="row" | Data cell |
|cell1 cell2 cell3
| cell1 || cell2 | cell3|- ! scope="row" | Header cell |
column heading
row heading
| ! scope="col" | column heading
! scope="row" | row heading|- ! scope="row" rowspan="2" | Sample table | colspan="2" |
| 2 |
| 4 |
| 1 | 2 |
| 3 | 4 |
| 2 |
| 4 |
The pipes must start at the beginning of a new line, except when separating parameters from content or when using || to separate cells on a single line. The parameters are optional.
|-
which generates another "<tr>".
Parameters can be added like this:
|- ''params''
which generates "<tr params>".
Note:
|cell1
|cell2
|cell3
or like this:
|cell1||cell2||cell3
which both generate "<td>cell1</td><td>cell2</td><td>cell3</td>". The "||" equals "newline" "|".
Parameters in cells can be used like this:
|''params''|cell1||''params''|cell2||''params''|cell3
which will result in
<td ''params''>cell1</td>
<td ''params''>cell2</td>
<td ''params''>cell3</td>
|}''params''|cell1
| Caption
which generates the HTML
You can also use parameters:
| ''params''|Caption
which will generate
provide a set of templates to configure text and color in cells in a standard way, using phrases such as ''Yes,'' ''No'' or ''n/a.''
Type this:
For this:
Normally, one problem with this approach is that readers are directed to different pages when they click on the images. To eliminate this problem—or to direct readers to a different page—you can use the summary parameter. A column-header can be coded as follows:
|}
The image will wikilink to article "xxxx".
By setting the link to an empty string (e.g. summary), no navigation will occur when visitors click on an image. Note that it might also be a good idea to color the image text blue if you are using the images as links. Also, SVG is the preferred image format in this case because it can be re-scaled to any size without producing artifacts.
A simple framed gallery can be formatted using class="wikitable" to generate the minimal thin-lines around images/photos within the table:
{| cellpadding="2"
| Multiplication table
|-
! scope="col" | &times;
! scope="col" | 1
! scope="col" | 2
! scope="col" | 3
|-
! scope="row" | 1
| 1 || 2 || 3
|-
! scope="row" | 2
| 2 || 4 || 6
|-
! scope="row" | 3
| 3 || 6 || 9
|-
! scope="row" | 4
| 4 || 8 || 12
|-
! scope="row" | 5
| 5 || 10 || 15
|}
Note the result below (with thin-lined cells):
| Nibelungen Bridge to Worms across the Rhine | Worms and its sister cities |
{| class="wikitable" style="font-style:italic; font-size:120%; border: 3px dashed red;"
| Multiplication table
|-
! scope="col" | &times;
! scope="col" | 1
! scope="col" | 2
! scope="col" | 3
|-
! scope="row" | 1
| 1 || 2 || 3
|-
! scope="row" | 2
| 2 || 4 || 6
|-
! scope="row" | 3
| 3 || 6 || 9
|-
! scope="row" | 4
| 4 || 8 || 12
|-
! scope="row" | 5
| 5 || 10 || 15
|}
| 130px]] | 125px]] | 125px]] | 115px]] | |
| Nibelungen Bridge to Worms | Worms and its sister cities | Statue of Liberty | New York City |
''text''
Note the 3 images sized "199x95px" appear identical height, of 95px (4th image purposely smaller). The "95px" forces height, while "199x" fits the various widths (could even be "999x"):
| 199x95px]] | 199x95px]] | 199x95px]] | 100x95px]] | |
| Statue of Liberty | New York City | Star on blue | Bridge to Worms |
{| class="wikitable sortable" border="1"
| Sortable table
|-
! scope="col" | Alphabetic
! scope="col" | Numeric
! scope="col" | Date
! scope="col" class="unsortable" | Unsortable
|-
| d || 20 || 2008-11-24 || This
|-
| b || 8 || 2004-03-01 || column
|-
| a || 6 || 1979-07-23 || cannot
|-
| c || 4 || 1492-12-08 || be
|-
| e || 0 || 1601-08-13 || sorted.
|}
The above wikitable-coding produces the result below, of 6 columns:
| 199x70px]] | 199x70px]] | 199x70px]] | 199x70px]] | 199x70px]] | 199x70px]] |
Once images have been placed in a wikitable, control of formatting can be adjusted when more images are added.
In the example below, note how Col2 uses <center>, but Col3 uses " ":
|-
The above coding generates the table below: note the middle garden image is centered (but not the left image), and the right image has 2 spaces before " View...":
| Dom tower from Brigittenstraat | Cloister garth of the Utrecht Dom Church | View from bell tower |
| style="font-size: 87%;" | View from bell tower
The column attribute, above, uses "style=" to set the font-size for the caption, following the 2nd vertical-bar "|".
A font-size: 65% is very small, while style="font-size: 87%;" is a mid-size font, larger than the tag small.
csv2wp – converts (CSV) format to pipe syntax. You may use this to import tables from Excel etc. (more information)
It is possible in the future that a WYSIWYG editor will be adopted (there has been much discussion about this in the past, however there are many technical hurdles that need to be solved). For the more technically inclined/adventurous tools such as exist, however they do not incorporate the complete WYSIWYG experience and currently do not support tables (although they may do so in the future).