| Table with border | BB |
| DD | |
| See other tables shown below. | |
A wikitable is a box of rows and columns used to show data, on a page. The box can be surrounded by lines (a "border") to show the edges of the box. Tables can use many different styles and tricks to show data in colors, or shifted ("aligned") to the left, right or center. This page shows how to make wikitables in Wikipedia.
There are many tables shown below, so perhaps just scroll down the page, or use the browser find-button, to see a table like what is needed. Otherwise, reading all the tables on the whole page could use over 1 hour of time.
| BB |
| DD |
| BB |
| DD |
| BB |
| DD |
| BB |
| DD |
This next table will show lines around each cell in the table.
| BB |
| EF |
| BB |
| EF |
| BB |
| EF |
The other examples, below, have more ways to show text or pictures in a table.
Although HTML table syntax also works, special wikicode markup 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''
'''|-'''
''row code goes here''
|}
{|
| The table's caption
|-
'''|''' ''cell codes go here''
|-
'''|''' ''cells in the next row go here''
'''|''' ''more cells in the same row 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
|}
which is probably not what you want:
| the first 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 |
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 |.
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.
The wiki markup code:
| A | B |
| C | D |
| B |
| D |
As it appears in a browser (note that there are no borders):
| A | B |
| C | D |
| Multiplication table |
As it appears in a browser (see User style):
| Multiplication table |
The wiki markup code:
| 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.):
The wiki markup code:
| ghi |
| pqr |
| yz |
As it appears in a browser:
| ghi |
| pqr |
| 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" option, use style="background: #f2f2f2" for the darker header, and style="background: #f9f9f9" for the lighter body.
See : , , ,
The wiki markup code:
| 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.
The wiki markup code:
| 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, like this:
| 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 |
That can be done by using as in: "{{nowrap|Words to keep together}}".
| 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:
| Green star |
Note only the image cells, here, have individual borders, not the text.
| Green star |
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). For example:
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".
Here's 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.
You can play with these settings in your own table to see what effect they have. Not all of these techniques may be appropriate in all cases; just because you can add colored backgrounds, for example, doesn't mean it's always a good idea. Try to keep the markup in your tables relatively simple -- remember, other people are going to be editing the article too! This example should give you an idea of what is possible, though.
The wiki markup code:
| An example table | ||
| upper left | | right side |
| lower left | lower middle | |
| { 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 | |
| { border="0" | A table in a table | |
| Two Wikipedia logos |
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:
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 |
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.
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.
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
{| border="1"
| α
| style="text-align: center;"| cell2
{| border="2" style="background: #ABCDEF;"
| NESTED
|-
| TABLE
|}
| style="vertical-align:bottom;"| the original table again
| style="width:100px;" |
{| border="2" style="background: #ABCDEF;"
| A
|}
{| border="2" style="background: #ABCDEF;"
| B || B
|}
| style="width:50px;" |
{| border="2" style="background: #ABCDEF; float:left;"
| C
|}
{| border="2" style="background: #ABCDEF; float: right;"
| D
|}
|}
As it appears in a browser:
| α | cell2 { | border="2" style="background: #ABCDEF;" |
| NESTED | ||
| TABLE |
| A |
| B |
| C |
| D |
| 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
| 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. |
| cell2 | cell3 |
As it appears in a browser:
| cell3 |
| HELLO WORLD |
| This is a test table here |
| followed by this text afterward. |
In the first line of table code, after the "
Instead of remembering table parameters, you just include an appropriate style 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:
| |||||
| becomes this: | |||||
{| class="wikitable"
| 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
|}
|
| ||||
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
{| 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
|}
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 |
Tables can be made sortable by adding class="sortable"; for details see Sorting. Since this can be very useful, it is wise to keep the possibilities and limitations of this feature in mind when designing a table. For example:
A long form of abbreviated content can be put as legend outside the table.
Wiki markup
''text''
As it appears in a browser:
| Sortable table |
| This |
| column |
| cannot |
| be |
| sorted. |
Wiki markup
{| 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.
|}
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"
|
| ! 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-<td> syntax (i.e., unclosed <td> and <td> 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" |
| 1 | 2 |
| 3 | 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''
|}
''params''|cell1
| Caption
which generates the HTML "<caption>Caption</caption>".
You can also use parameters:
| ''params''|Caption
which will generate "<caption params>Caption</caption>".
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 link 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. <nowiki></nowiki>), 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:
! style="width:3em;" | [[File:wpvg_vg_project.svg|link=xxxx]]
Note the result below (with thin-lined cells):
| Nibelungen Bridge to Worms across the Rhine | Worms and its sister cities |
{| class="wikitable" border="1"
|-
|[[File:Worms 01.jpg|265px]]
|[[File:Worms Wappen 2005-05-27.jpg|235px]]
|-
|Nibelungen Bridge to Worms<br/>across the [[Rhine]]
|Worms and its sister cities
|}
| 130px]] | 125px]] | 125px]] | 115px]] | |
| Nibelungen Bridge to Worms | Worms and its sister cities | Statue of Liberty | New York City |
"[[
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" border="1"
|-
|[[File:Worms 01.jpg|130px]]
|[[File:Worms Wappen 2005-05-27.jpg|125px]]
|[[File:Liberty-statue-with-manhattan.jpg|125px]]
|[[File:New-York-Jan2005.jpg|125px]]
|-
|Nibelungen Bridge to Worms
|Worms and its sister cities
|Statue of Liberty
|New York City
|}
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 " ":
{| class="wikitable" border="1"
|-
|[[File:Liberty-statue-with-manhattan.jpg|199x70px]]
|[[File:Gold star on blue.gif|199x70px]]
|[[File:New-York-Jan2005.jpg|199x70px]]
|[[File:Gold star on deep red.gif|199x70px]]
|[[File:Worms 01.jpg|199x70px]]
|[[File:Gold star on blue.gif|199x70px]]
|}
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>.
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).