Help:Table

From Zoophilia Wiki
Jump to navigationJump to search

A table is an arrangement of columns and rows that organizes and positions data or images. Tables can be created on Zoophilia Wiki pages using special wikitext syntax, or HTML syntax, and many different styles and tricks can be used to customize them.

Tools

Source mode toolbar

Vector toolbar – default. Table icon is circled.
Monobook toolbar. Table icon is on the right end.

To automatically insert a table, click or (Insert a table) on the edit toolbar. In the Vector toolbar, the table icon is in the "Advanced" menu.

The following wikitext is inserted when Insert a table is clicked:

{| class="wikitable"
 |+ Caption text
 ! Header text
 ! Header text
 ! Header text
 |-
 | Example
 | Example
 | Example
 |-
 | Example
 | Example
 | Example
 |-
 | Example
 | Example
 | Example
|}

The sample text ("Header text" or "Example") is intended to be replaced with actual data. Row numbers (1-3) and column letters (A-C) have been substituted below to help visualization.

Wikitext

{| class="wikitable"
 |+ Caption text
 ! Header A !! Header B !! Header C
 |-
 | row 1 A || row 1 B || row 1 C
 |-
 | row 2 A || row 2 B || row 2 C
 |-
 | row 3 A || row 3 B || row 3 C
|}

Produces:

Caption text
Header A Header B Header C
row 1 A row 1 B row 1 C
row 2 A row 2 B row 2 C
row 3 A row 3 B row 3 C

You can fill in the table while in source mode, or use the visual editor (VE). To create more complex table structures in source mode with cells that span multiple rows or columns, see § Colspan and rowspan.

Visual editor

Most table editing is easier in the visual editor than in the wikitext source editor. Find the pencil icon in the toolbar to toggle between wikitext source editing and visual editing.

With the visual editor (VE) you directly fill in the cells without having to go through wikitext. VE makes it easy to add, remove, and rearrange/reorder rows or columns. In VE, this is what shows up when clicking the table icon (in the "Insert" menu):

For more complex table structures, the visual editor offers cell-merging operations; see details here.

In addition, it is usually possible to add or import a table that exists elsewhere (e.g. in a spreadsheet, or on another website) directly into the visual editor by:

  • dragging and dropping a .csv file into the Visual Editor, or
  • selecting, copying, and pasting the table into the Visual Editor.

Using other tools

Other tools, such as those used to create wiki tables from Excel, can be used to create wikitable markup from spreadsheet and database tables. See § External links for a list of some.

Table basics

Tables can be added to articles and other pages using either standard HTML table elements, or with special wikicode markup developed just to facilitate creating tables without prior knowledge of HTML.

Markup

Overview of basic table markup
Table element Wikitext Required Usage notes
Table start {| Required Note: {| Entire table goes here |}
Caption |+ Optional Only between table start and first table row.
Row separator |- Required Placed on its own line, in between rows
Optional before the first row, where it may be omitted.
Header cell ! or !! Optional A new row, and so its first cell, starts on a new line. Row and column header cells begin with one (exclamation) mark (!). Consecutive table header cells may be added on the same line, separated by double exclamation marks (!!) – or start on new lines, each with its own single mark.
Data cell | or || Optional Consecutive table data cells may be added on the same line, separated by two consecutive vertical bar characters (||) – or start on new lines, each with their own single vertical bar character (|).
The vertical bar character is also used to separate HTML attributes from the cell or caption contents that follow.
Table end |} Required
  • The above marks must start on a new line, except the double marks (|| and !!) for optionally adding consecutive cells on a single line.
  • Blank spaces at the beginning of a line are ignored.
  • Content may either follow its cell mark on the same line (after any optional HTML attributes) or on lines below the cell mark (just beware of undesired paragraphs, though). Content that uses wiki markup that itself needs to start on a new line, such as with lists, headings, or nested tables, must be put on its own new line.
  • To insert a vertical bar character (|) into a table caption or cell, use <nowiki>...</nowiki> tags like this to escape them: <nowiki>|</nowiki>

HTML attributes

Each mark, except the table end (|}), optionally accepts one or more attributes, which must be on the same line as the mark.

  • Cells and captions (| or ||, ! or !!, and |+) hold content—separate any attribute from a cell's content using a single vertical bar (|), with attributes always preceding content.
  • Table and row marks ({| and |-) do not directly hold content. Do not add a vertical bar (|) after any attributes.

Commonly included attributes used with tables include: class, for example class="wikitable"; or style for CSS styling. Other attributes have row or column scope, e.g. scope for row and column header cells, rowspan, to extend cells across more than one row and colspan to extend cells over more than one column.

Wikicode syntax tutorial

For a history of the development of wikicode table syntax, see History of pipe syntax development.

A table may be created entirely in wikicode using special table markup developed for the purpose. No knowledge of HTML is required.

Begin and end delimiters

Use {| to begin a table, and |} to end it. Each one needs to be on its own line:

{|
  caption/rows go here
|}

Optional parameters like class may be placed on the Begin-table delimiter line. See § Class below.

Caption

An optional table caption is included with a line starting with a vertical bar and plus sign (|+) and the caption inserted after it:

{|
 |+ The table's caption
  rows go here
|}

Row start

To start a new table row, type a vertical bar and a hyphen on its own line: |-. The characters for creating the cells in that row should start on the next line.

{|
 |+ The table's caption
 |-
   row 1 cells go here
 |-
   row 2 cells go here
|}

For details about rows, see § Row operations below.

Cells

Type the characters for each table cell in the next row, starting with a vertical bar:

{|
 |+ The table's caption
 | Row 1 cell 1
 | Row 1 cell 2
 |-
 | Row 2 cell 1
 | Row 2 cell 2
|}

Cells can be separated with either a new line and a single vertical bar, or by a double bar (||) on the same line; both produce the same output:

Wikitext

{|
 |+ The table's caption
 | Cell 1 || Cell 2 || Cell 3
 |-
 | Cell A
 | Cell B
 | Cell C
 |-
 | Cell x
 | Cell y || Cell z
|}

Produces

The table's caption
Cell 1 Cell 2 Cell 3
Cell A Cell B Cell C
Cell x Cell y Cell z

For details about table cells, see § Cell operations below.

Optional declarations

Optional declarations can modify the display and styling of cells, rows, or the entire table. The simplest way to add styling is to set the wikitable CSS class, which in Zoophilia Wiki's external style sheet, is defined to apply a gray color scheme and cell borders to tables that declare it:

Wikitext

{| class="wikitable"
 |+ The table's caption
 ! Column header 1
 ! Column header 2
 ! Column header 3
 |-
 ! Row header 1
 | Cell 2 || Cell 3
 |-
 ! Row header A
 | Cell B
 | Cell C
|}

Produces

The table's caption
Column header 1 Column header 2 Column header 3
Row header 1 Cell 2 Cell 3
Row header A Cell B Cell C

The table parameters and cell parameters are the same as in HTML, see the WHATWG HTML Living Standard v5 § 4.9.1 "The table element" and Table (HTML). However, the <thead>, <tbody>, <tfoot>, <colgroup> and <col> elements are currently not supported in MediaWiki as of December 2021.

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 attributes, turning the table into a diagram, like this Square 8x8 pentomino example on Meta-Wiki. An "image" in the form of a table is much more convenient to edit than an uploaded image.

If all the cells in a row are empty, the cells still show up. If the header cell is also empty for that row, all the cells show up, but they are narrow. That can be fixed with a simple <br /> in one of the cells. That is what is done here:

{{Sort under}} is simpler for putting the sorting arrows below the header text in order to narrow a table.

With colspan and rowspan, cells can span several columns or rows; see § Colspan and rowspan below.

Displaying a pipe character

Displaying a pipe character as part of the text of a table cell requires a workaround. See § Rendering the pipe.

Scope

Column headers are identified by  ! scope="col" | instead of |.

Row headers are identified by  ! scope="row" | instead of |.

Each header cell should be on a separate line in the wiki markup. The scope="col" and scope="row" markup should be used for column and row headers in all tables, because it explicitly associates the header with the corresponding cells, helping to ensure a consistent experience for readers making use of screen readers or other assistive technologies. The Zoophilia Wiki Manual of Style requires the presence of the scope attribute for all column and row headers.

For complex tables, when a header spans two columns or rows, use  ! scope="colgroup" colspan="2" | or  ! scope="rowgroup" rowspan="2" | respectively to clearly identify the header as a column header of multiple columns or a row header of multiple rows. When headers are unclear, this can cause accessibility issues; therefore, use id= to set a unique value containing no whitespace on each header, then reference the id(s) on the data cells that have unclear headers using the headers= attribute, separating each id with a space.

Header cells typically render differently from regular cells, though this ultimately depends on the web browser in use. They are often rendered in a bold font and the text is centered within the cell. If this rendering is not desired from an aesthetic point of view, the table can be styled with the "plainrowheaders" class, which left-aligns the row headers and removes the bolding. Left-alignment of row headers only occurs if class="wikitable" and scope="row" are both used.

A typical example may be marked up like this:

Wikitext

{| class="wikitable plainrowheaders"
 |+ The table's caption
 ! scope="col" | Column header 1
 ! scope="col" | Column header 2
 ! scope="col" | Column header 3
 |-
 ! scope="row" | Row header 1
 | Cell 2 || Cell 3
 |-
 ! scope="row" | Row header A
 | Cell B || Cell C
|}

Produces

The table's caption
Column header 1 Column header 2 Column header 3
Row header 1 Cell 2 Cell 3
Row header A Cell B Cell C

Examples

Minimalist table

Both of these generate the same output. Choose a style based on the number of cells in each row and the total text inside each cell.

Wikitext

{|
 | A
 | B
 |-
 | C
 | D
|}
{|
 | A || B
 |-
 | C || D
|}

Produces (without borders).

A B
C D

Multiplication table

In this example class="wikitable" is used to style the table with Wikipedia's external style sheet for tables. It adds borders, background shading, and bold header text.

Wikitext

{| class=wikitable style="text-align: center;"
 |+ Multiplication table
 ! scope="col" | ×
 ! scope="col" | 1
 ! scope="col" | 2
 ! scope="col" | 3
 |-
 ! scope="row" | 1
 | 1 || 2 || 3
 |-
 ! scope="row" | 2
 | 2 || 4 || 6
|}

Produces

Multiplication table
× 1 2 3
1 1 2 3
2 2 4 6

Whole table operations

Class

One or more classes may be added to the § Begin-table delimiter line at the top of the table, and may be used to supply predefined styling to the entire table. The wikicode table class attribute corresponds directly to the "class" attribute of the HTML <table> element. To add multiple classes to a table, place them all on the same line, wrapped in double quotes and each separated by a space:

{| class="wikitable sortable mw-collapsible"

Some predefined classes are:

A sortable wikitable
breed ht wt
Labrador Retriever 23 70
French Bulldog 12 25
German Shepherd 27 78
Golden Retriever 23 71
English Bulldog 14 45
  • wikitable – provides column headers in bold type on a shaded background, and other common style. See here for details. This class should be used for almost all tables, unless there is a reason not to.
  • sortable – adds the ability to click on column headers and sort the table data based on the values in that column. See sortable tables.
  • mw-collapsible – See collapsible tables.[note 1]
  • plainrowheaders – applies left-aligned and normal-weight formatting of row headers. See Table header layout. Must be placed after wikitable if they both appear in the class declaration.
  • floatright – same as applying style="clear: right; float: right; margin-left: 8px;" to the entire table.
  • floatleft – same as applying style="clear: left; float: left; margin-right: 8px;" to the entire table.

Note: Template:Table may also be used to apply classes to the § Begin-table delimiter line.

Captions and summaries

Explicit table captions (or titles) are recommended for data tables as a best practice; the Zoophilia Wiki Manual of Style considers them a high priority for accessibility reasons (screen readers), as a caption is explicitly associated with the table, unlike a normal wikitext heading or introductory sentence. All data tables on Zoophilia Wiki require captions. A caption is provided with the |+ markup, similar to a table row (|-), but it does not contain any cells and is not within the table border. Captions are always displayed, appearing as a title centered (in most browsers) above the table. A caption can be styled (with inline CSS declarations) like any other cell and may include wikilinks, reference citations and most other types of content.

Many article editors dislike table captions when the table is directly below, or not far away from, a similar article heading. But screen reader users still need a table caption to quickly browse from table to table. In this case, add the popular {{Screen reader-only}} template to the table caption, and then only screen reader users will see it. For example:

 |+ {{Screen reader-only|Example table caption…}}

For current table caption and summary guidelines, see the W3C Web Accessibility Initiative (WAI) page: Table Caption & Summary Tutorial. The summary info in the paragraph below is out of date:

A summary provides an overview of the data of a table for text and audio browsers, and does not normally display in graphical browsers. The summary (also a high Manual of Style priority for tables) is a synopsis of content, and does not repeat the caption text; think of it as analogous to an image's alt description. A summary is added with summary="Summary text here.", on the same line as the {| that opened the table, along with any class="…" and other attributes for the table as a whole. The summary="…" attribute is, however, obsolete in HTML 5.

Wiki markup example showing left-aligned caption with a source citation:

{| class="wikitable"
 |+ style="text-align: left;" | Data reported for 2014–2015, by region
 ! scope="col" | Year
 ! scope="col" | Africa
 ! scope="col" | Americas
 ! scope="col" | Asia & Pacific
 ! scope="col" | Europe
 |-
 ! scope="row" | 2014
 | 2,300 || 8,950 || ''9,325'' || 4,200
 |-
 ! scope="row" | 2015
 | 2,725 || ''9,200'' || 8,850 || 4,775
|}

Produces

Data reported for 2014–2015, by region[99]
Year Africa Americas Asia & Pacific Europe
2014 2,300 8,950 9,325 4,200
2015 2,725 9,200 8,850 4,775

Colspan and rowspan

It is possible to create cells that stretch over two or more columns. For this, one uses  | colspan="n" | content. Similarly, one can create cells that stretch over two or more rows. This requires  | rowspan="n | content. In the table code, one must leave out the cells that are covered by such a span. The resulting column and row counting must fit.

Wikitext

{| class="wikitable" style="text-align: center;"
 ! scope="col" | col1
 ! scope="col" | col2
 ! scope="col" | col3
 ! scope="col" | col4
 |-
 ! scope="row" | row1
 | colspan="2" | A
<!-- Column counting: cell 'B' can not exist… -->
 | C
 |-
 ! scope="row" | row2
 | AA
 | BB
 | CC
 |-
 ! scope="row" | row3
 | AAA
 | rowspan="2" | BBB
 | CCC
 |-
 ! scope="row" | row4
 | AAAA
<!-- Row counting: cell 'BBBB' can not exist… -->
 | CCCC
|}

Produces

col1 col2 col3 col4
row1 A C
row2 AA BB CC
row3 AAA BBB CCC
row4 AAAA CCCC

In the code, the cell | colspan="2" | A spans two columns. In the next column, a cell expected to contain "B" does not exist.

Similar: in the code, cell | rowspan="2" | BBB spans two rows. A cell expected to contain "BBBB" does not exist.

Wikitext <syntaxhighlight lang=wikitext line highlight=14>

Column 1 Column 2 Column 3
A B
C D
E F
G
H
</syntaxhighlight>

Produces

Column 1 Column 2 Column 3
A B
C D
E F
G
H

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.

Below is the same table with the order of the declared rows and cells shown in parentheses. The uses of rowspan and colspan are also shown.

Wikitext <syntaxhighlight lang=wikitext>

Column 1
(row 1 cell 1)
Column 2
(row 1 cell 2)
Column 3
(row 1 cell 3)
A
(row 2 cell 1)
rowspan=2
B
(row 2 cell 2)
colspan=2
C
(row 3 cell 1)
D
(row 3 cell 2)
E
(row 4 cell 1)
F
(row 4 cell 2)
rowspan=2 colspan=2
G
(row 5 cell 1)
H
(row 6 cell 1)
colspan=3
</syntaxhighlight>

Produces

Column 1
(row 1 cell 1)
Column 2
(row 1 cell 2)
Column 3
(row 1 cell 3)
A
(row 2 cell 1)
rowspan=2
B
(row 2 cell 2)
colspan=2
C
(row 3 cell 1)
D
(row 3 cell 2)
E
(row 4 cell 1)
F
(row 4 cell 2)
rowspan=2 colspan=2
G
(row 5 cell 1)
H
(row 6 cell 1)
colspan=3

Although cell C is in column 2, C is the 1st cell declared in row 3, because column 1 is occupied by cell A, which was declared in row 2. Cell G is the only cell declared in row 5, because cell F occupies the other columns but was declared in row 4.

Table style

A style element may be added to apply to the entire table, to all the cells § in a row, or just to individual cells in the table. Adding a style to a column requires a template such as {{table alignment}} (for horizontal alignment of text).

To add style to the entire table, add the style element to the § Begin-table delimiter line at the top of the table. in some cases, it may be better to use the style encapsulated in one of the predefined classes; see § Class.

Horizontal text alignment

Template:More Text alignment (right/center/left) for the whole table (except the headers in a table using class=wikitable) can be done at the top line of the table wikitext: <syntaxhighlight lang=wikitext highlight=1 class=gridbox>

...

</syntaxhighlight>

Text alignment for a column can be done with {{table alignment}}.

Height

The height of the whole table can be specified using standard CSS style properties on the § start table indicator line:

<syntaxhighlight lang=wikitext highlight=1,6 class=gridbox>

. . .

</syntaxhighlight>

You may also specify the § height of individual rows, and if they add up to more than the table height you specified or if word wrapping increases row height, the table height you specified will be ignored and the table height increased as needed to accommodate all the rows (except on mobile where the bottom of the table will be cut off).

Borders

Note: Wikipedia:HTML 5#Table attributes. CSS to replace obsolete attributes for borders, padding, spacing, etc.

Add a border around a table using the CSS property border: thickness style color;, for example border:3px dashed red. This example uses a solid (non-dashed) gray border that is one pixel wide:

Wikitext <syntaxhighlight lang=wikitext>

Left Center Right
Red star Orange star Green star
</syntaxhighlight>

Produces

Left Center Right
Red star Orange star Green star

Note the bottom-row texts are centered by style="text-align: center;" to match the centering of the stars in their cells.

As long as the File: specs omit the parameter |thumb they don't 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 (as in style="border: 1px solid darkgreen;") or use a hex-color (such as: #DDCCBB).

Border-collapse: conflicting or double borders

Wikitext <syntaxhighlight lang=wikitext>

A B C
D E F
</syntaxhighlight>

Produces

A B C
D E F

If all cells have the same border color, the resulting double borders may not be wanted; add the border-collapse: collapse; CSS property on the table opening tag to reduce them to single ones (cellspacing=... is obsolete).

Additionally, the W3C allows the use of the otherwise obsolete border= attribute on the table root ({|) if its value is "1". This adds a one-pixel border, in the default color, to the table and all of its cells at once:

Using the border-collapse property to combine the double borders, as described above:

Wikitext <syntaxhighlight lang=wikitext>

A B C
D E F
</syntaxhighlight>

Produces

A B C
D E F

Float table left or right

Two table classes floatleft and floatright (case sensitive) help floating the table and adjusting table margins so that they do not stick to the text. floatleft floats the table to the left and adjusts right margin. floatright does the opposite. Example:

Wikitext <syntaxhighlight lang=wikitext highlight=3,13> This paragraph is before the table.

Caption text
Header A Header B Header C
row 1 A row 1 B row 1 C
row 2 A row 2 B row 2 C
Caption text
Header A Header B Header C
row 1 A row 1 B row 1 C
row 2 A row 2 B row 2 C

... Lorem text after table </syntaxhighlight>

As it appears in a browser:

This paragraph is before the table.

Caption text
Header A Header B Header C
row 1 A row 1 B row 1 C
row 2 A row 2 B row 2 C
Caption text
Header A Header B Header C
row 1 A row 1 B row 1 C
row 2 A row 2 B row 2 C

Template:Lorem ipsum span


Alternatively, you can use CSS to get the same result:
{| class="wikitable" style="float:left; clear:left; margin-right:8px;"
{| class="wikitable" style="float:right; clear:right; margin-left:8px;"

This paragraph is before the table.

Caption text
Header A Header B Header C
row 1 A row 1 B row 1 C
row 2 A row 2 B row 2 C
Caption text
Header A Header B Header C
row 1 A row 1 B row 1 C
row 2 A row 2 B row 2 C

Template:Lorem ipsum span

Centering tables

To center a table horizontally, use style margin: auto, which applies to the left and right margins. Text does not flow around centered tables as it does for floated tables; that is, no text appears to either side:

Wikitext <syntaxhighlight lang=wikitext highlight=2> Text before table...

Centered table
Duis aute irure
dolor in reprehenderit in voluptate velit
esse cillum dolore eu fugiat nulla pariatur.

...text after table </syntaxhighlight>

As it appears in a browser:

Text before table...

Centered table
Duis aute irure
dolor in reprehenderit in voluptate velit
esse cillum dolore eu fugiat nulla pariatur.

...text after table.

Style margin:auto may be combined with top and bottom margin in the standard way for CSS, e.g. <syntaxhighlight lang=wikitext inline>style="margin:1em auto"</syntaxhighlight> defines top and bottom margins of 1em, and automatic (centered) left and right margins.

Tip: For Android Chrome, use:

{| style="margin: auto; border: none;"[note 2]

Note: align="center" is deprecated in HTML5, and does not work well in Mediawiki software. For example, it will not override the left alignment of tables via class=wikitable.

Static ('sticky') headers

Headers can be frozen so they're always at the top (or left) as one scrolls through a large table. See {{Sticky header}} and {{Sticky table start}}.

Nested tables

Note: because they cause accessibility issues, header cells in nested tables should be avoided whenever possible. For accessibility, any complicated table must be carefully designed to maintain normal flow, i.e. the ordering of content in the page code should match the order in which it is to be presented.

Nesting data tables with header cells makes it difficult for assistive screen readers to parse them sensibly.

Editors sometimes use headerless tables as an aid to content layout, especially where it is easier than the equivalent use of divs and CSS styling. For complex layouts, rowspan and colspan may be used, but again it is sometimes simpler and more maintainable to use nested tables.

Nested tables must start on a new line.

In the following example, five different tables are shown nested inside the cells of a sixth, main table. None has any header cells. 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 schematics.

α cell2
NESTED
TABLE
the original table again
A
B B
C
D

Wikitext: <syntaxhighlight lang=wikitext line highlight="4-8,11-17,19-24">

α cell2
NESTED
TABLE
the original table again
A
B B
C
D
</syntaxhighlight>

Column operations

There are column and cell operations for width. See Help:Width of tables, columns, and cells.

There are also column, cell, and table operations for text alignment (right, left and center alignment). See Help:Table/Advanced#Column alignment. It is part of a much larger section of info on aligning text in individual table cells, or the table as a whole.

See also: {{table alignment}}. This template allows easy aligning of text in a column, or multiple columns.

To insert, remove, or rearrange whole columns, see Help:Creating tables#Move/delete row/column. This is much faster and easier to do in the visual editor than in the wikitext editor.

To sort some or all columns in a table see Help:Sortable tables.

Width

This is a complex subject. Please see the main page:

Row operations

Table rows are added after the § table start indicator, and after any optional § whole table markup such as a caption, table summary, or § column scope attributes.

Starting a new row

To start a new table row, type a vertical bar and a hyphen on its own line: "|-". The codes for the cells in that row start on the next line. An id for § anchoring in-links, and § row style may be included on the same line.

<syntaxhighlight lang=wikitext class=gridbox>

row code goes here
The table's caption

</syntaxhighlight>

Row style

Row style (height, width, borders, text alignment, background color, bolding, italics, etc.) may be added to a wikitable row by appending CSS style properties to the row start line after the |- indicator.

Here is an example increasing the height of the middle row. The top row has italic text. The last row has bold text and a yellow background. Either the word yellow can be used, or the hex-color (such as: #FFFF00):

Wikitext <syntaxhighlight lang=wikitext highlight=4,6,8>

Left Center Right
Top left Top center Top right
Middle left Middle center Middle right
Bottom left Bottom center Bottom right
</syntaxhighlight>

Produces

Left Center Right
Top left Top center Top right
Middle left Middle center Middle right
Bottom left Bottom center Bottom right

The row also contains an id attribute; this will be explained later in the section about linking directly to a row.

Row headers

With row headers you need to use a separate row in the wikitext for the row header cell. Here below is what a table looks like if the data cell wikitext is on the same line as the row header wikitext. The data cell text is bolded, and the data cell backgrounds are the same shade of gray as the column and row headers.

Wikitext <syntaxhighlight lang="wikitext" highlight=5,7>

The table's caption
Column 1 Column 2 Column 3
Row header 1 Cell 2 Cell 3
Row header A Cell B Cell C
</syntaxhighlight>

Produces

The table's caption
Column 1 Column 2 Column 3
Row header 1 Cell 2 Cell 3
Row header A Cell B Cell C

Here is the table with a separate wikitext row for each row header cell. The data cells have plain unbolded text, and a lighter background.

Wikitext <syntaxhighlight lang="wikitext" highlight=5,8>

The table's caption
Column 1 Column 2 Column 3
Row header 1 Cell 2 Cell 3
Row header A Cell B Cell C
</syntaxhighlight>

Produces

The table's caption
Column 1 Column 2 Column 3
Row header 1 Cell 2 Cell 3
Row header A Cell B Cell C

Row numbers

Table rows may be numbered with the assistance of templates provided for the purpose. See Help:Sortable tables sections on row numbers, and these templates:

Template:Sh

You can link directly to a row in a wikicode table, by including an id attribute on the line with the § row start indicator whose value is the anchor for the link. For example, you could code:

|- id="mid"

and then link to it using The [[#mid|middle row]] is the tallest one. which produces:

The middle row is the tallest one.     (Click to try it out!)Template:Hairspace

Row template

Regardless of whether wikitable format or HTML is used, the wikitext of the rows within a table, and sometimes even within a collection of tables, may have much in common, e.g.:

  • the basic code for a table row
  • code for color, alignment, and sorting mode
  • fixed texts such as units
  • special formats for sorting

In such a case, it can be useful to create a template that produces the syntax for a table row, with the data as parameters. This can have many advantages:

  • easily changing the order of columns, or removing a column
  • easily adding a new column if many elements of the new column are left blank (if the column is inserted and the existing fields are unnamed, use a named parameter for the new field to avoid adding blank parameter values to many template calls)
  • computing fields from other fields, e.g. population density from population and area
  • duplicating content and providing span tags with display: none; for the purpose of having one format for sorting and another for display
  • easy specification of a format for a whole column, such as color and alignment

Example:

Using {{Help:Table/example row template}}

Wikitext <syntaxhighlight lang="wikitext" style="display: inline-block;">

a b a/b

Help:Table/example row template Help:Table/example row template Help:Table/example row template

</syntaxhighlight>

Conditional table row

For a conditional row in a table, we can have:

Wikitext <syntaxhighlight lang="wikitext" style="display: inline-block;">

row one, column one row one, column two
row three, column one row three, column two
</syntaxhighlight>

Produces

row one, column one row one, column two
row three, column one row three, column two

With comments to explain how it works, where note how the second row is missing:

Wikitext <syntaxhighlight lang="wikitext" style="display: inline-block;">

row one, column one row one, column two
row three, column one row three, column two
</syntaxhighlight>

Produces

row one, column one row one, column two
row three, column one row three, column two

Cell operations

Setting cell parameters

At the start of a cell, add your parameter followed by a single pipe. For example, style="width: 300px;"| sets that cell to a width of 300 pixels. To set more than one parameter, leave a space between each one.

Wikitext <syntaxhighlight lang="wikitext">

cell1 cell2 cell3
</syntaxhighlight>

Produces

cell1 cell2 cell3

Vertical alignment in cells

Note: The valign=... attribute is deprecated and MediaWiki may stop using it. See: Help:HTML in wikitext#Tables.
Note: Use {{Table vertical alignment}} to align all rows or cells in a column at once.

By default, text is aligned to the vertical middle of the cell (2nd column in table below). CSS can be used to vertically align individual cells, or single rows.

Demo of vertical alignment of individual cells
Three
lines
ofTemplate:Nbsptext
No alignment Top-aligned Middle-aligned Bottom-aligned

Relevant wikitext: <syntaxhighlight lang=wikitext highlight=1-3> |style=vertical-align:top |Top-aligned |style=vertical-align:middle |Middle-aligned |style=vertical-align:bottom |Bottom-aligned

</syntaxhighlight>

The example below illustrates the need for top alignment of a row.

Row header A longer piece of text. 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.

Imagine someone scrolling down the page, seeing the tops of "empty" columns, and wondering why they're empty.

Short text

To align the text to the top of each cell in the row, apply the style="vertical-align: top;" CSS to the row.

Wikitext <syntaxhighlight lang=wikitext highlight=2>

Row header A longer piece ... Short text

</syntaxhighlight>

Produces

Row header A longer piece of text. 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. Short text

Documentation and more options for the CSS vertical-align property is here.

Cell content indenting and padding

The contents of a cell can be indented or padded on any side. Also, the text can be aligned. In the third row the text is aligned to the right. See the following examples.

Wikitext <syntaxhighlight lang="wikitext">

Cell content that is not indented or padded
style="padding-left: 2em;"
style="text-align:right; padding-right: 2em;"
style="padding-top: 2em;"
style="padding-bottom: 2em;"
style="padding: 3em 5%;"      (Top and Bottom: 3em. Left and Right: 5%)
style="padding: 3em 4em 5%;"      (Top: 3em. Left and Right: 4em. Bottom: 5%)
style="padding: 3%;"      (Top, Right, Bottom, and Left: all 3%)
style="padding: 1em 20px 8% 9em;"      (Top: 1em. Right: 20px. Bottom: 8%. and Left: 9em.)
</syntaxhighlight>

Produces

Cell content that is not indented or padded
style="padding-left: 2em;"
style="text-align:right; padding-right: 2em;"
style="padding-top: 2em;"
style="padding-bottom: 2em;"
style="padding: 3em 5%;"      (Top and Bottom: 3em. Left and Right: 5%)
style="padding: 3em 4em 5%;"      (Top: 3em. Left and Right: 4em. Bottom: 5%)
style="padding: 3%;"      (Top, Right, Bottom, and Left: all 3%)
style="padding: 1em 20px 8% 9em;"      (Top: 1em. Right: 20px. Bottom: 8%. and Left: 9em.)

Pattern for arguments: The arguments to style="padding: " can be seen as being ordered by a 12-hour clock, starting at noon and going clockwise, in the following sense: "top" is associated with noon (i.e. 12 o'clock, the top of a clock), "right" is 3 o'clock, "bottom" is 6 o'clock, and "left" is 9 o'clock. The arguments are ordered clockwise starting at noon: top → right → bottom → left (see this[note 3] footnote for an example with an explanation).

This same order is also used elsewhere, such as when specifying § cell borders with border-style: .

Setting default cell padding

Use cellpadding= to set the default padding for each cell in a table. If class=wikitable is used then cellpadding is ignored. The default space between cells can be changed using cellspacing=.

If cellpadding is not used

Wikitext <syntaxhighlight lang="wikitext">

Cell Cell
Cell Cell
</syntaxhighlight>

Produces

Cell Cell
Cell Cell

Using cellpadding=10:

Wikitext <syntaxhighlight lang="wikitext">

Cell Cell
Cell Cell
</syntaxhighlight>

Produces

Cell Cell
Cell Cell

Using cellpadding=0:

Wikitext <syntaxhighlight lang=wikitext>

Cell Cell
Cell Cell
</syntaxhighlight>

Produces

Cell Cell
Cell Cell

Using cellpadding=0 and cellspacing=0:

Wikitext <syntaxhighlight lang=wikitext>

Cell Cell
Cell Cell
</syntaxhighlight>

Produces

Cell Cell
Cell Cell

Individual cell borders

The same § CSS used for tables can be used in a cell's format specifier (enclosed in |...|) to put a border around each cell:

Wikitext <syntaxhighlight lang=wikitext highlight=6,8,10>

Left Center Right

Red star Orange star Green star
</syntaxhighlight>

Produces

Left Center Right

Red star Orange star Green star

Only the image cells have individual borders, not the text. The lower hex-colors (such as: #616161) are closer to black. Typically, all borders in a table would be one specific color.

Border styles

The style='border:' and style='border-style:' properties can accept the following arguments:

Argument Cell border Additional notes
none style="border-style: none;"
solid style="border-style: solid;"
double style="border-style: double;"
dashed style="border-style: dashed;"
dotted style="border-style: dotted;"
ridge style="border:5px ridge red;" 3D ridged border
groove style="border:5px groove blue;" 3D grooved border
inset style="border: 5px inset yellow;" 3D inset border
outset style="border: 5px outset cyan;" 3D outset border
inherit style="border-style: inherit;" Inherit value from parent
initial style="border-style: initial;" Set to default value
Borders of a cell using border-top, border-right, border-bottom, border-left

Wikitext <syntaxhighlight lang=wikitext>

style="border-top: solid;"
border-top: solid 2px red;
border-right: dashed 3px green;
border-bottom: double 5px blue;
border-left: dotted 6px yellow;
</syntaxhighlight>

Produces

style="border-top: solid;"
border-top: solid 2px red;
border-right: dashed 3px green;
border-bottom: double 5px blue;
border-left: dotted 6px yellow;
Top, right, bottom, and left borders of a cell using style='border-style:'

To set the left, right, bottom, or top border of a single cell, one may use style='border-style:' which takes between 1 and 4 arguments, each of which is either none, solid, double, dotted, dashed, groove, ridge, inset, outset, inherit, or initial.

These arguments are ordered according to the § pattern described here. For instance, style="border-style: solid none solid none;" where the four parameters correspond respectively to the
Script error: No such module "in5".'border-style: top right bottom left;'
borders of the cell. For reasons described after this example, there are many ways to change the following code that would not result in any changes to the table that is actually displayed.

Wikitext <syntaxhighlight lang=wikitext>

Top_Left Top_Center Top_Right
Middle_Left Middle_Center Middle_Right
Bottom_Left Bottom_Center Bottom_Right
</syntaxhighlight>

Produces

Top_Left Top_Center Top_Right
Middle_Left Middle_Center Middle_Right
Bottom_Left Bottom_Center Bottom_Right

Note, however, that in the following table, none of the central cell's (i.e. Middle_Center's) borders are removed despite the code style="border-style: none none none none;":

Wikitext <syntaxhighlight lang=wikitext>

Top_Left Top_Center Top_Right
Middle_Left Middle_Center Middle_Right
Bottom_Left Bottom_Center Bottom_Right
</syntaxhighlight>

Produces

Top_Left Top_Center Top_Right
Middle_Left Middle_Center Middle_Right
Bottom_Left Bottom_Center Bottom_Right

This happens because the code class="wikitable" places a border (top, right, bottom, and left) around every cell in the table so that, for instance, there are actually two borders between the cells "Middle_Center" and "Middle_Right". So to remove the border between cells "Middle_Center" and "Middle_Right", it is necessary to remove both the right border of "Middle_Center" and the left border of "Middle_Right":

Wikitext <syntaxhighlight lang=wikitext>

Top_Left Top_Center Top_Right
Middle_Left Middle_Center Middle_Right
Bottom_Left Bottom_Center Bottom_Right
</syntaxhighlight>

Produces

Top_Left Top_Center Top_Right
Middle_Left Middle_Center Middle_Right
Bottom_Left Bottom_Center Bottom_Right

To remove selected external borders of a wikitable, both remove them from the adjacent cells and begin the whole table with code like {| class="wikitable" style="border: none;".

Replacing {| class="wikitable" with
Script error: No such module "in5".{| style="border-collapse: collapse;"
has the effect of removing all cell borders that would otherwise appear by default around every cell in the table. With this change, you must insert a single cell border between two adjacent cells rather than remove two cell borders.

Table cell templates

See {{Table cell templates}} for a large set of templates to configure text and color in cells in a standard way, producing stock output. For example: "Yes" ({{Yes}}), "No" ({{No}}), "—" ({{N/A}}), "N/A" ({{N/A|N/A}}), "?" ({{dunno}}), on colored backgrounds.

Template output for selected table cell templates
Template usage Using template Without template
{{Yes}} Yes Yes
{{No}} No No
{{Dunno}} ? ?
{{N/A}} Template:N/A
{{N/A|N/A}} Template:N/A N/A
{{n/a|n/a}} n/a n/a

For example, see Comparison of text editors, which makes frequent use of table cell templates.

Tooltips

You can add tooltips to columns by using the {{Tooltip}} template. Simply replace the column-title with {{Tooltip|Column title|The tool tip}}, which makes it appear like so: Column title. Use {{abbr}} (same format) for abbreviations. For example: Pop.

Workarounds

Scrolling tables

See Help:Table/Advanced § Scrolling tables and the following sections for scrolling, sticky headers, and combinations thereof.

Overflowing tables

Note: Template:Sticky table start does the same thing, and also shortens the table vertically too via a vertical scrollbar. Such a scroll box is a problem though if the sticky headers are too large. In some cases, only a horizontal scrollbar (as below) may be desired. In that case Template:Sticky header may be preferred as long as the top sticky header is not too tall. The overflow code below can not be used with it, or sticky will not work. {{Sticky header}} scrolling is via the whole page, not just for the table.

A horizontal scrollbar for the whole page shows up for any wikitable that is too wide for the screen. To create a scrollbar just for the table the following code may be used. Place the following code above a wikitable initialization:

<syntaxhighlight lang="html" highlight="2" class=gridbox>

</syntaxhighlight>

Then, after the closing bracket for the wikitable, place the following code: <syntaxhighlight lang="html" highlight="2" class=gridbox>

</syntaxhighlight>

This will prevent the table from causing the entire page to scroll when scrolling through the table horizontally.

For more info see: Template:Sticky header#Known issues.

Non-rectangular tables

{{diagonal split header|HEADER-FOR-ROW-HEADERS|HEADER-FOR-COLUMN-HEADERS}} can be used to diagonally split a header cell, as in the top-left cell in the rendered result below:[note 4]

Wikitext <syntaxhighlight lang="wikitext" highlight="2">

Template:Diagonal split header Solid Liquid Gas
Solid Solid-solid transformation Melting Sublimation
Liquid Freezing Boiling/evaporation
Gas Deposition Condensation
</syntaxhighlight>

Produces

Template:Diagonal split header Solid Liquid Gas
Solid Solid-solid transformation Melting Sublimation
Liquid Freezing Boiling/evaporation
Gas Deposition Condensation

Cell borders can be hidden by adding border: none; background: none; to the style attributes of either the table or the cell,[note 5] though this may not work in older browsers. Another use case for this is for implementing aligned multi-column tables:

Wikitext <syntaxhighlight lang="wikitext" highlight="2" style="white-space: pre-wrap;">

To
Solid Liquid Gas
From Solid Solid–solid transformation Melting Sublimation
Liquid Freezing Boiling/evaporation
Gas Deposition Condensation
</syntaxhighlight>

Produces

To
Solid Liquid Gas
From Solid Solid–solid transformation Melting Sublimation
Liquid Freezing Boiling/evaporation
Gas Deposition Condensation

The removal of the link on an image is dependent on it being purely decorative (as it will be ignored by assistive devices).

Wikitext <syntaxhighlight lang="wikitext" style="white-space: pre-wrap;">

Year Size Year Size Year Size
1990 1000
(est)
2000 1357 2010 1776
1991 1010 2001 1471 2011 1888
1999 1234 2009 1616 2019 1997
(est)
</syntaxhighlight>

Produces

Year Size Year Size Year Size
1990 1000
(est)
2000 1357 2010 1776
1991 1010 2001 1471 2011 1888
1999 1234 2009 1616 2019 1997
(est)

Rendering the pipe

When cell content that contains a pipe character does not render correctly, simply add an empty format for that cell. The second pipe character in a line of |cell code will not display; it is reserved for adding a format. Wikicode between the first and second pipe is a format, but since emptiness or an error there is ignored, it just disappears. When this happens, add a dummy format.