Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

Tables

Syntax

For consistency and compatibility of tables, please use the following table syntax styles. These rules are required to ensure that tables print correctly in all contexts, including when they are part of a form field.

Normal pages

{|
! head 1
! head 2
! head 3
|-
| column a1
| column a2
| column a3
|-
| column b1
| column b2
| column b3
|}

This results in the following table:

head 1head 2head 3
column a1column a2column a3
column b1column b2column b3

Form-based pages

Tables in a template or form-based page must use the “pipe hack” instead of the | character:

{{!}}

Thus, the same table in a form would use the following (ugly) syntax:

{{{!}}
! head 1
! head 2
! head 3
{{!}}-
{{!}} column a1
{{!}} column a2
{{!}} column a3
{{!}}-
{{!}} column b1
{{!}} column b2
{{!}} column b3
{{!}}}

Do not do this!

Do not use the single-line row syntax.

{|
| head 1    !! column 2  !! column 3
|-
| column a1 || column a2 || column a3
|-
| column b1 || column b2 || column b3
|}

Sortable tables

MediaWiki has the ability to create sortable tables, simply by adding the class sortable:

{| class="sortable"
! head 1
! head 2
! head 3
|-
| apple a1
| peach a2
| blueberry a3
|-
| ape b1
| dog b2
| fish b3
|}

This results in the following table:

head 1head 2head 3
apple 1peach 2blueberry 3
ape 1dog 2zebra 3

Other, less styled variant

This variant has been found by mix-matching class names. Consider this as a hack if you really need to put data in a table without being forced to use first row as the table heading cell.

{| class="mw-datatable os-suggest-results filehistory"
|+Unstyled table, and showing table caption cell syntax
|-
|Column one
|Column two
|Column three
|-
|'''Column one and row one'''
|Column two:
* Lists
* works
* that way
|Column three
|-
|'''Column one and row two'''
|Column two, row two
|Column three, row two
|}

This results in the following table:

Unstyled table, and showing table caption cell syntax
Column one Column two Column three
Column one and row one Column two:
  • Lists
  • works
  • that way
Column three
Column one and row two Column two, row two Column three, row two