Atable is an arrangement of columns and rows that organizes and positions data or images. Tables can be created on Wikipedia pages using specialwikitext syntax, orHTML syntax, and many different styles and tricks can be used to customise them.
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.
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.
Most table editing is easier in thevisual editor than in the wikitext source editor. Find the pencil icon in the toolbar to toggle between wikitext source editing and visual editing.
With thevisual 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 detailshere.
In addition, it is usually possible to add or import a table that exists elsewhere (e.g., in a spreadsheet, 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.
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.
Tables can be added to articles and other pages using either standardHTML table elements, or with specialwikicode markup developed just to facilitate creating tables without a knowledge of HTML.
Placed on its own line, in betweenrows – Optionalbefore 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 double (pipeline) marks (||) – or start on new lines, each with their own single (pipeline) marks (|). The pipeline symbol is also used to separate pertainingHTML attributes from the cell or caption contents that follow.
Table end
|}
Required
The above marks muststart on a new line, except the double marks (|| and!!) for optionally adding consecutive cells to 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 (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 apipe character (|) into a table caption or cell, use the<nowiki>|</nowiki> escaping markup.
Each mark, except table end (|}), optionally accepts one or moreattributes. Attributes must be on the same line as the mark.
Cells andcaptions (| or||,! or!!, and|+) holdcontent—separate any attribute from its content with a single pipe (|), with attributes preceding content.
Table androw marks ({| and|-) do not directly hold content. Donot add a pipe (|) after any attributes.
Commonly included attributes with table scope include:class, for exampleclass="wikitable"; orstyle forCSS styling. Other attributes have row- or column scope, e.g.,scope, to indicate row or column header cells;rowspan, to extend cells by more than one row; andcolspan, to extend cells by more than one column.
Optionalparameters can modify the display and styling of cells, rows, or the entire table. The simplest way to add styling is to set thewikitableCSS class, which in Wikipedia'sexternal style sheet is defined to apply a gray color scheme and cell borders to tables using it:
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, likemeta:Template talk:Square 8x8 pentomino example. 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:
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. Thescope="col" andscope="row" markup should be used for column and row headers in all data tables because it explicitly associates the header with the corresponding cells, which helps ensure a consistent experience for screen readers. The Manual of Stylerequires the use of scope for column and row headers.
Forcomplex 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 two columns or a row header of two rows. When headers are unclear, this can cause accessibility issues; therefore, useid= to set a unique value without spaces on each header, then reference the id(s) on the data cells that have unclear headers usingheaders= with a space separating each id.
Header cells typically render differently from regular cells, depending on the browser. They are often rendered in a bold font and centered. 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 ifclass=wikitable andscope=row are both used.
In this exampleclass="wikitable" is used to style the table with Wikipedia's external style sheet for tables. It adds borders, background shading, and bold header text.
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 style to the table. The wikicode tableclass attributecorresponds directly to the "class"attribute of the HTML<table> element. To add multiple classes to a table, place them all on the same line, embedded in double quotes and 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 with bold font on shaded background, and other common style. Seehere for details. This class should be used for almost all tables, unless there is a reason not to.
sortable – adds up & down icons to column headers which enable sorting the table on a given column. Seesortable tables.
plainrowheaders – applies left-aligned and normal-weight formatting of row headers. SeeTable header layout. Must be placed afterwikitable if they both appear in the class declaration.
floatright – same as applyingstyle="float:right; clear:right; margin-left:8px" to the entire table
floatleft – same as applyingstyle="float:left; clear:left; margin-right:8px" to the entire table
Explicit tablecaptions (ortitles) are recommended for data tables as a best practice; the Wikipedia Manual of Styleconsiders 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 Wikipedia 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, not block, CSS), and may include wikilinks, reference citations, etc.
Many article editors dislike table captions when the table is directly below, or not far away from, a similar article heading. Butscreen reader users still need a table caption to quickly browse from table to table. In this case use the popular{{sro}} template:Template:Screen reader-only. Add the template to the table caption, and then only screen reader users will see it. Example:
Asummary 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'salt description. A summary is added withsummary="Summary text here.", on the same line as the{| that opened the table, along with anyclass= and other parameters for the table as a whole.Thesummary= 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<ref name="Garcia 2005"/>|-!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|}
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=m |content. In the table code, one mustleave out the cells that are covered by such a span. The resulting column- and row-counting must fit.
Wikitext
{|class=wikitablestyle="text-align: center;"!col1!col2!col3!col4|-!row1|colspan=2| A<!-- column counting: cell 'B' can not exist -->|C|-!row2|AA|BB|CC|-!row3|AAA|rowspan=2| BBB|CCC|-!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
{|class=wikitable|-! Column 1!! Column 2!! Column 3|-|rowspan=2| A|colspan=2style="text-align: center;"| B<!-- column 3 of this row occupied by cell B (which is to the left) -->|-<!-- column 1 of this row occupied by cell A (above) -->| C| D|-| E|rowspan=2colspan=2style="text-align: center;"| F<!-- column 3 of this row occupied by cell F (to the left) -->|-| G<!-- columns 2 and 3 of this row occupied by cell F (above) -->|-|colspan=3style="text-align: center;"| H<!-- columns 2 and 3 of this row occupied by cell H (to the left) -->|}
Produces
Column 1
Column 2
Column 3
A
B
C
D
E
F
G
H
Usingrowspan=2 for cellG combined withrowspan=3 for cellF to get another row belowG andF 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 ofrowspan andcolspan are also shown.
Although cellC is in column 2,C is the 1st cell declared in row 3, because column 1 is occupied by cellA, which was declared in row 2. CellG is the only cell declared in row 5, because cellF occupies the other columns but was declared in row 4.
Astyle 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 thestyle 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.
Text alignment (right/center/left) for the whole table (except the headers in a table usingclass=wikitable) can be done at the top line of the table wikitext:
{|class=wikitablestyle=text-align:right; ...|}
Text alignment for a column can be done with{{table alignment}}.
The height of the whole table can be specified using standard CSS style properties on the§ start table indicator line:
{|class=wikitablestyle=height:14em; . . .|}
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).
Add a border around a table using the CSS propertyborder:thickness style color;, for exampleborder:3px dashed red. This example uses a solid (non-dashed) gray border that is one pixel wide:
Note the bottom-row texts are centered bystyle="text-align: center;" to match the centering of the stars in their cells.
As long as theFile: specs omit the parameter|thumb they don't show the caption lines in the table (only during mouse-over). The border colordarkgray matches typical tables or infoboxes in articles; however, it could be any color name (as instyle="border: 1px solid darkgreen;") or use ahex-color (such as:#DDCCBB).
If all cells have the same border color, the resulting double borders may not be wanted; add theborder-collapse: collapse; CSS property on the table opening tag to reduce them to single ones (cellspacing=... isobsolete).
Additionally, theW3Callows the use of the otherwise obsoleteborder= 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 theborder-collapse property to combine the double borders, as described above:
Two table classesfloatleft andfloatright (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:
Vestibulum sapien nisl, ornare auctor, consectetuer quis, posuere tristique, odio. Fusce ultrices ullamcorper odio. Ut augue nulla, interdum at, adipiscing non, tristique eget, neque. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Ut pede est, condimentum id, scelerisque ac, malesuada non, quam. Proin eu ligula ac sapien suscipit blandit. Suspendisse euismod. Ut accumsan, neque id gravida luctus, arcu pede sodales felis, vel blandit massa arcu eget ligula. Aenean sed turpis. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Donec sem eros, ornare ut, commodo eu, tempor nec, risus. Donec laoreet dapibus ligula. Praesent orci leo, bibendum nec, ornare et, nonummy in, elit. Donec interdum feugiat leo. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Pellentesque feugiat ullamcorper ipsum. Donec convallis tincidunt urna.
Alternatively, you can useCSS to get the same result: {| {|
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
Vestibulum sapien nisl, ornare auctor, consectetuer quis, posuere tristique, odio. Fusce ultrices ullamcorper odio. Ut augue nulla, interdum at, adipiscing non, tristique eget, neque. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Ut pede est, condimentum id, scelerisque ac, malesuada non, quam. Proin eu ligula ac sapien suscipit blandit. Suspendisse euismod. Ut accumsan, neque id gravida luctus, arcu pede sodales felis, vel blandit massa arcu eget ligula. Aenean sed turpis. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Donec sem eros, ornare ut, commodo eu, tempor nec, risus. Donec laoreet dapibus ligula. Praesent orci leo, bibendum nec, ornare et, nonummy in, elit. Donec interdum feugiat leo. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Pellentesque feugiat ullamcorper ipsum. Donec convallis tincidunt urna.
To center a table horizontally, use stylemargin: 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
Text before table...{|class="wikitable"style="margin: auto; border: none;"|+ Centered table|-!scope="col"| Duis!scope="col"| aute!scope="col"| irure|-| dolor|| in reprehenderit|| in voluptate velit|-| esse cillum dolore|| eu fugiat nulla|| pariatur.|}...text after table
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.
Stylemargin:auto may be combined with top and bottom margin in the standard way for CSS, e.g.style="margin:1em auto" defines top and bottom margins of 1em, and automatic (centered) left and right margins.
Note:align="center" isdeprecated in HTML5, and does not work well in Mediawiki software. For example, it will not override the left alignment of tables viaclass=wikitable.
Note: because they causeaccessibility 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 assistivescreen 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 andcolspan 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.
There are also column, cell, and table operations for text alignment (right, left and center alignment). SeeHelp: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, seeHelp:Creating tables#Move/delete row/column. This is much faster and easier to do in the visual editor than in the wikitext editor.
To start a newtablerow, type a vertical bar and ahyphen on its own line: "|-". The codes for the cells in that row start on the next line. Anid for§ anchoring in-links, and§ row style may be included on the same line.
{||+ The table's caption|-rowstylinggoeshere row code goes here|}
Row style (height, width, borders, text alignment, background color, bolding, italics, etc.) may be added to a wikitable row by appendingCSS 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:
Wikitext
{|class=wikitable|-! Left!! Center!! Right|-style=font-style:italic;| Top left|| Top center|| Top right|-style=height:9em;id=mid| Middle left|| Middle center|| Middle right|-style="font-weight:bold; background-color:yellow;"| Bottom left|| Bottom center|| Bottom right|}
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 anid attribute; this will be explained later in the section aboutlinking directly to a row.
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.
Table rows may be numbered with the assistance of templates provided for the purpose. SeeHelp:Sortable tables sections on row numbers, and these templates:
You can link directly to a row in a wikicode table, by including anid attribute on the line with the§ row start indicator whose value is theanchor for the link. For example, you could code:
|-
and then link to it usingThe [[#mid|middle row]] is the tallest one.which produces:
Themiddle row is the tallest one. (Click to try it out!)
For adding a dynamic row number as a table column, see§ Row numbers.
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 withdisplay: none; for the purpose of having one format forsorting and another for display
easy specification of a format for a whole column, such as color and alignment
With comments to explain how it works, where note how the second row is missing:
Wikitext
{|class=wikitable<!-- Row one is shown because the '1' evaluates to TRUE. -->{{#if:1|{{!}}- ! scope=row{{!}} row one, column one<!-- Any {{!}}'s are evaluated to the pipe character '|' since the template '!' just contains '|'. -->{{!}}row one, column two}}<!-- Row two is NOT shown because the space between the ':' and the '|' evaluates to FALSE. -->{{#if:|{{!}}- ! scope=row{{!}} row two, column one{{!}}row two, column two}}<!-- Row three is shown. -->|- ! scope=row {{!}} row three, column one | row three, column two|}
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.
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.
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 thestyle="vertical-align: top;" CSS to the row.
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
Documentation and more options for the CSSvertical-align property ishere.
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
{|class=wikitable|-| Cell content that is not indented or padded|-|style="padding-left: 2em;"|<code>style="padding-left: 2em;"</code>|-|style="text-align:right; padding-right: 2em;"|<code>style="text-align:right; padding-right: 2em;"</code>|-|style="padding-top: 2em;"|<code>style="padding-top: 2em;"</code>|-|style="padding-bottom: 2em;"|<code>style="padding-bottom: 2em;"</code>|-|style="padding: 3em 5%;"|<code>style="padding: 3em 5%;"</code>{{space|4}} (Top and Bottom: 3em. Left and Right: 5%)|-|style="padding: 3em 4em 5%;"|<code>style="padding: 3em 4em 5%;"</code>{{space|4}} (Top: 3em. Left and Right: 4em. Bottom: 5%)|-|style="padding: 3%;"|<code>style="padding: 3%;"</code>{{space|4}} (Top, Right, Bottom, and Left: all 3%)|-|style="padding: 1em 20px 8% 9em;"|<code>style="padding: 1em 20px 8% 9em;"</code>{{space|4}} (Top: 1em. Right: 20px. Bottom: 8%. and Left: 9em.)|}
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 tostyle="padding: " can be seen as being ordered by a12-hour clock, starting atnoon and goingclockwise, in the following sense: "top" is associated with noon (i.e. 12 o'clock, the top of aclock), "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 withborder-style:.
Setting default cell padding
Usecellpadding= to set the default padding for each cell in a table. Ifclass=wikitable is used thencellpadding is ignored. The default space between cells can be changed usingcellspacing=.
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
Thestyle='border:' andstyle='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 usingborder-top,border-right,border-bottom,border-left
Top, right, bottom, and left borders of a cell usingstyle='border-style:'
To set the left, right, bottom, or top border of a single cell, one may usestyle='border-style:' which takes between 1 and 4 arguments, each of which is eithernone,solid,double,dotted,dashed,groove,ridge,inset,outset,inherit, orinitial.
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 'border-style: top right bottom left;' borders of the cell.For reasons described after this example, there are many ways to change the followingcode that wouldnot result in any changes to the table that is actuallydisplayed.
Note, however, that in the following table, none of the central cell's (i.e.Middle_Center's) borders are removed despite the codestyle="border-style: none none none none;":
This happens because the codeclass="wikitable" places a border (top, right, bottom, and left) aroundevery cell in the table so that, for instance, there are actuallytwo 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
{|class=wikitable|-| Top_Left|| Top_Center|| Top_Right|-| Middle_Left<!-- 'border-style: top right bottom left;' -->|style="border-style: none none none none;"| Middle_Center|style="border-style: none none none none;"| Middle_Right<!-- In the above line, the three left-most "none" arguments can be replaced with "solid" (or other valid arguments) and there would be no change to the table that is displayed. Only the fourth argument, which is Middle_Right's left border, needs to be "none". For example, the line above could be replaced with:| | Middle_Right-->|-| Bottom_Left|| Bottom_Center|| Bottom_Right|}
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{|.
Replacing{| with {| has the effect of removing all cell borders that would otherwise appear by default around every cell in the table.With this change, you mustinsert asingle cell border between two adjacent cells rather than removetwo cell borders.
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.
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.
Note:Template:Sticky table start does the same thing, and also shortens the table vertically too via a verticalscrollbar. 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 caseTemplate: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:
<divclass="overflowbugx"style="overflow-x:auto;">
Then, after the closing bracket for the wikitable, place the following code:
</div>
This will prevent the table from causing the entire page to scroll when scrolling through the table horizontally.
{{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]
Cell borders can be hidden by addingborder: 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:
When cellcontent that contains apipe 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.(For a real format, see§ HTML attributes.) Use a third pipe character to render your first pipe character.
Rendering the first pipe when it is the third pipe in the cell code.
The third and later pipe characters will render, but to display twoadjacent pipe characters in a cell, (instead of having them act as the first pipe at the start of a new cell), other pipe-rendering options are needed. Instead of using a dummy format to render a pipe, you can render it directly by 1)<nowiki>|</nowiki> (preferred) or 2) html:| or|. Each line of cell code in the following table has one wikicode pipe.
Template{{!}}, because of the order in which things are parsed, is equivalent to typing in a single | pipe character. The single<nowiki />| parser-tag does not apply here. See how they do notescape the second pipe, as | and<nowiki>|</nowiki> did above:
There are several otherCSS classes, besides the basicclass=wikitable, documented§ above.
In the first line of table code, after the{|, instead of specifying a style directly, you can also specify a CSS class, which may be used to apply styles. The style for this class can be specified in various ways:
in the software itself, per skin (for example the class§ sortable)
collectively for all users of one wiki inMediaWiki:Common.css (for example, on this and some other projects there is or was the class wikitable, later moved toshared.css)
individually, but jointly for tables of the class concerned on all web pages, on the local computer of the user.
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:
simply by replacing inline CSS for the table byclass=wikitable. This is because thewikitable class inMediaWiki:Common.css contains a number oftable.wikitable CSS 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:
Notice that the table retains the gray background of thewikitable class, and the headers are still bold and centered. But now the text formatting has been overridden by the localstyle= 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.
Note: Concerning colons on talk pages, see commentshere from a blind editor (Graham87) who uses ascreen reader. Scroll down to the table comments. It also verifies the previous section above.
Indentation applied to only thefirst line of the table wiki text, (the line that begins with "{|") is sufficient to indent the entire table.
:::{| class=wikitable
Do not attempt to use colons for indentation anywhere within the rest of the table code (not even at the beginning of a line), as that will prevent the MediaWiki software from correctly reading the code for the table.
It may be difficult or time-consuming to convert a table on the web to a wikitable. Especially if it can't be copied and pasted into the visual editor or a spreadsheet. Even more time-consuming if it is both difficult and regularly updated.
SeeCommons:Template:PD-chart. All image tables and charts are in the public domain unless they contain copyrightable things such as photos, etc.. Those can be removed.
So if necessary, take a screenshot, crop out the table with any image editor, andupload it to theWikimedia Commons. Add {{PD-chart}} to it.
^Collapsible tables: the classcollapsible prevents editing collapsed tables using theVisual editor; usemw-collapsible instead. Seehere for further details.
^border: none; to avoid an empty column in tables narrower than the browser window in Android Chrome.
^Instyle="padding: 3em 4em 5%;", the value4em is used for both the "left" padding and the "right" padding, so the order going clockwise is: top (3em) → right [and hence also left] (4em) → bottom (5%); there is no "→ left" in this case because the "left" padding has already been defined. Instyle="padding: 3em 5%;", the value3em is used for both the "top" and "bottom" padding while the value5% is used for both the "left" and "right" padding, so the order going clockwise is: top [and hence also bottom] (3em) → right [and hence also left] (5%); there is no "→ bottom" nor is there "→ left" in this case because the "bottom" and "left" padding have already been defined. The same reasoning also applies tostyle="padding: 1em 20px 8% 9em;", andstyle="padding: 3%;".