Help:Table/Advanced#Colors in tables

{{Short description|How to create and use tables in markup}}

{{Table help}}

{{Wikipedia how to}}

{{shortcut|H:Table/A}}

{{Wiki markup}}

Tables can be used as formatting instrument, but consider using a multi column list instead.

Horizontal alignment in cells

By default, text is aligned to the left of data cells.

By default, text is aligned to the center of header cells.

All of the above is true in both desktop and mobile view.

The alignment of header text in tables with class=wikitable stays centered regardless of global right or left text alignment via style=text-align:VALUE on the top line of table wikitext.

Header text alignment in tables without class=wikitable follows the global text alignment of the table.

Text alignment set in individual cells overrides everything else.

= Aligning text in header cells versus other cells =

Note: For vertical alignment of text see: Help:Table#Vertical alignment in cells.

If there is no global text alignment set in the top line of the table wikitext, then all text is left aligned, except for header cells which are default center aligned.

Only in tables with class=wikitable does the header cell text not follow the global text alignment set in the top line of the table wikitext.

When using class=wikitable header text now stays centered in both desktop and mobile view unless specifically changed per header cell. This is true wherever the header row is located (top, bottom, middle). Global text alignment for non-header cells is done by putting style=text-align:VALUE in the top line of the table wikitext. See example in the next section.

= Aligning the data in data columns to the right =

Both tables below use class=wikitable

The table to the right also aligns the text and data in all cells (except header cells) to the right.

class=wikitable

|+ Basic table

HeaderHeaderHeader
Textdata 12data 12
Textdata 123data 123
Textdata 1234data 1234

class=wikitable style=text-align:right

|+ style=text-align:right

HeaderHeaderHeader
Textdata 12data 12
Textdata 123data 123
Textdata 1234data 1234

If most columns consist of data cells, then you might choose to align the data to the right. It is easy.

Just add style=text-align:right to the top line of the wikitext for the table:

:{| class=wikitable style=text-align:right

or

:{| class="wikitable sortable" style=text-align:right

and so on.

= Decimal point alignment =

There is no easy way to align a column of numbers so that the decimal points align. See multiple ways below.

One way to align columns of numbers at the decimal point is to use two columns, with the first right-justified and the second left-justified.

Wikitext

style="border-collapse: collapse;"

| style="text-align: right;" | 432

.1
style="text-align: right;" | 43.21
style="text-align: right;" | 4.321

Rendered result

style="border-collapse: collapse;"

| style="text-align: right;" | 432

.1
style="text-align: right;" | 43.21
style="text-align: right;" | 4.321

If the column of numbers appears in a table with cell padding or cell borders, you can still align the decimal points without an unsightly gap in the middle, by forcing the border and padding between those two columns off.

Wikitext

class=wikitable

!colspan=2| Heading

style="text-align:right; border-right:none; padding-right:0;" | 432

| style="text-align:left; border-left: none; padding-left: 0;" | .1

style="text-align:right; border-right:none; padding-right:0;" | 43

| style="text-align:left; border-left: none; padding-left: 0;" | .21

style="text-align:right; border-right:none; padding-right:0;" | 4

| style="text-align:left; border-left: none; padding-left: 0;" | .321

Rendered result

class=wikitable

!colspan=2| Heading

style="text-align:right; border-right:none; padding-right:0;" | 432

| style="text-align:left; border-left: none; padding-left: 0;" | .1

style="text-align:right; border-right:none; padding-right:0;" | 43

| style="text-align:left; border-left: none; padding-left: 0;" | .21

style="text-align:right; border-right:none; padding-right:0;" | 4

| style="text-align:left; border-left: none; padding-left: 0;" | .321

Or alternatively the {{tl|decimal cell}} template can be used:

Wikitext

class=wikitable

! colspan=2 |Heading

{{decimal cell|432.1}}
{{decimal cell|43.21}}
{{decimal cell|4.321}}

Rendered result

class=wikitable

!colspan=2 |Heading

{{decimal cell|432.1}}
{{decimal cell|43.21}}
{{decimal cell|4.321}}

Using two columns like this does have the disadvantage that searching the web page (either with a browser or a search engine) will usually not be able to find text that straddles the column boundary.

Also, if the table has cell spacing (and thus border-collapse=separate), meaning that cells have separate borders with a gap in between, that gap will still be visible.

A cruder way to align columns of numbers is to use a figure space   or  , which is intended to be the width of a numeral, though is font-dependent in practice:

Wikitext

432.1
 43.21
  4.321

Rendered result

432.1
 43.21
  4.321

More companions in this line are: punctuation space ({{Code| |html}}) to substitute a period or a comma, {{Code|−|html}} instead of the easily available on the typewriter's keyboard hyphen-dash – this is the same width as the plus sign, also figure dash possibly the most useful for telephone numbers which you obviously will not find on Wikipedia.

When using OpenType fonts one may also alternate between {{Code|font-variant-numeric:tabular-nums|css}} and {{Code|font-variant-numeric:proportional-nums|css}} – this is especially visible in the kerning of Arabic digit ⟨1⟩. In the standard browser sans-serif fonts ⟨1⟩ occupies the same width as other digits, ie. works as if {{Code|font-variant-numerals:tabular-nums|css}} was turned on.

Some may find {{Tl|0}} useful for the alignment.

As a last resort, when using pre-formatted text, you can dispense with the table feature entirely and simply start the lines with a space, and put spaces to position the numbers—however, there should be a good reason to use pre-formatted text in an article:

Wikitext (just spaces!):

432.1

43.21

4.321

Rendered result

432.1

43.21

4.321

= Column alignment =

{{tl|Table alignment}} can be used to align the cells in a whole column without adding code to each cell. For example, left aligning the first column, and center aligning the fourth column. And default aligning all other cells to the right:

:

{{Table alignment}}

class="wikitable sortable col1left col4center defaultright"

Place {{Table alignment}} just before the table and then add some classes to the table.

{| class="wikitable"

! classname

! Purpose

defaultleftAlign all table cells left by default
defaultcenterAlign all table cells center by default
defaultrightAlign all table cells right by default
colNleftAlign the cells in column N left, where N is a number
colNcenterAlign the cells in column N center, where N is a number
colNrightAlign the cells in column N right, where N is a number

The "col" classes never effect the header cells.

The "default" classes also effect the header cells if wikitable class is not used. With the wikitable class header cell content is always centered unless individually adjusted.

See template for more info, limitations, examples.

= Aligning the text in the first column to the left =

Template:Table alignment (see previous section) will not work on columns of row headers. There are some other limitations listed at Template:Table alignment. In these cases you can try the following method for the first column only.

This can be done in the wikitext source editor. In editing preferences check the box labeled: "enable the editing toolbar. This is sometimes called the '2010 wikitext editor'."

In the table section click "edit source" (wikitext editing). Click on "Advanced" in the editing toolbar. Then click on the "search and replace" icon on the right. In the popup form check the box for "Treat search string as a regular expression".

Fill in the "Search for" box with (\|-\n\|)

Fill in the "replace with" box with

:$1style=text-align:left|

Then click "Replace all". All the text in the first column will be aligned to the left of their cells.

If for some reason those cells are header cells, then fill in the "Search for" box with

:(\|-\n\!)

Note the exclamation point for a header cell. Fill in the "replace with" box with

:$1style=text-align:left|

Then click "Replace all".

Side by side tables

Note: See also [https://en.wikipedia.org/w/index.php?title=Together_Again_(Janet_Jackson_song)&oldid=1235924258#Charts this version] of Together Again (Janet Jackson song)#Charts. It uses {{t|col-begin}}, {{t|col-2}}, {{t|col-end}}.

You can place two or more tables side by side. But the tables must wrap (one dropping below the other) in narrow screens if horizontal scrolling is to be avoided. Narrow your browser window to see the tables below wrap. This works in mobile view too. Click on "mobile view" at the bottom of any Wikipedia page. These tables are adapted excerpts from versions of Iceland men's national handball team. Many sport articles have side by side tables.

{{Static row numbers}}

class="wikitable sortable static-row-numbers" border=1 style=text-align:right

|+ Total number of matches played in official competitions only.

Player

!Matches

!Goals

style=text-align:left|Guðmundur Hrafnkelsson

|407

|0

style=text-align:left|Guðjón Valur Sigurðsson

|364

|1,875

{{Static row numbers}}

class="wikitable sortable static-row-numbers" border=1 style=text-align:right

|+ Total number of goals scored in official matches only.

Player

!Goals

!Matches

!Average

style=text-align:left|Guðjón Valur Sigurðsson

|1,875

|364

|5.15

style=text-align:left|Ólafur Stefánsson

|1,570

|330

|4.76

Here is the relevant wikitext below. More info [https://www.w3schools.com/jsref/prop_style_display.asp here]. A blind editor who uses a screen reader says [https://en.wikipedia.org/w/index.php?title=Wikipedia_talk%3AManual_of_Style%2FAccessibility&diff=1196667296&oldid=1196634188 this method is OK].

--Table--

--Table--

The code box below was created by adding the same div around the whole syntaxhightlight box:

--Table--

--Table--

Note that the space between the above handball tables happens because

is on a line by itself. If you want no space use this:

:

style=display:inline-grid can not be added within the table wikitext. It must be added outside the table wikitext. This is because the table captions will not be correctly placed in mobile portrait view, or other narrow mobile screens, when the tables wrap. This is especially noticeable if the caption is longer. In that case when one table drops below the other, then the caption will be severely wrapped above only the first column of the table.

Side by side tables/images

You can add images to the mix too. Add vertical-align:top; to align an item to the top. See [https://www.w3schools.com/cssref/pr_pos_vertical-align.asp CSS vertical-align property] for other options. The tables and images will wrap depending on screen width. Narrow your browser window to see. For example:

class=wikitable

|+Table 1

Name

! Color

Fred

|Orange

Bob

|Green

Lindy

|Yellow

File:New-York-Jan2005.jpg

class=wikitable

|+Table 2

Animal

! State

Raccoon

|Maine

Whale

|Alaska

Manta Ray

|Florida

File:Gold star on blue.gif

Add vertical-align:bottom; to align an item to the bottom. You can choose the alignment for each item. Note the star aligned to the bottom.

class=wikitable

|+Table 1

Name

! Color

Fred

|Orange

Bob

|Green

Lindy

|Yellow

File:New-York-Jan2005.jpg

class=wikitable

|+Table 2

Animal

! State

Raccoon

|Maine

Whale

|Alaska

Manta Ray

|Florida

File:Gold star on blue.gif

You can add indentation by adding margin styling to the first div:

class=wikitable

|+Table 1

Name

! Color

Fred

|Orange

Bob

|Green

Lindy

|Yellow

File:New-York-Jan2005.jpg

class=wikitable

|+Table 2

Animal

! State

Raccoon

|Maine

Whale

|Alaska

Manta Ray

|Florida

File:Gold star on blue.gif

These tables below wrap better with display:inline-table; instead of display:inline-grid;

class=wikitable

|Convert a US list/table to a state-by-state data map. With examples and step-by step instructions. Example:

File:Map of US minimum wage by state.svg.]]

class=wikitable

|Simple map below using another method. See its talk page for info.

File:Medicaid expansion map of US. Affordable Care Act.svg of US Affordable Care Act.]]

Tables and images can also be floated to the right by adding float:right;

File:Female incarceration rates by country and US state.gif

File:World incarceration rates if every U.S. state were a country.png

See example to the right from [https://en.wikipedia.org/w/index.php?title=List_of_U.S._states_and_territories_by_incarceration_and_correctional_supervision_rate&oldid=1235102187#U.S._states_compared_to_countries this version] of List of U.S. states and territories by incarceration and correctional supervision rate.

File:Female incarceration rates by country and US state.gif

File:World incarceration rates if every U.S. state were a country.png

{{clear}}

Scrolling tables

{{anchor|Scrolling tables|scrolling tables}}

A whole table can be placed within a scrolling div so that new table lines appear on the screen as old table lines disappear. See MOS:SCROLL, and Help:Scrolling list, and this article discussion.

=Vertical scrolling table=

class=wikitable
abcdefghi
style="height: 100px;"

| jkl

style="width: 100px;" | mnopqr
stuvwxyz

class=wikitable
abcdefghi
style="height: 100px;"

| jkl

style="width: 100px;" | mnopqr
stuvwxyz

=Horizontal scrolling table=

{{See also|Help:Table#Overflowing tables}}

Adding {{code|-x}} to {{code|overflow:auto}} → {{code|overflow-x:auto}} forces overflowing table data to fit within page's width margin or otherwise predetermined wiki markup.

class=wikitable style="width:25em"
abcdefghi
jklstyle="height: 70px;" | mnopqr
stuvwxyz

class=wikitable style="width:25em"
abcdefghi
jklstyle="height: 70px;" | mnopqr
stuvwxyz

Tables with sticky headers

:History: See most recent Village Pump discussion. And other archived discussions: 1. 2. 3. 4. 5. See Phab:T42763. See also: Meta: Community Wishlist Survey 2022/Reading/floating table headers and meta:Community Wishlist Survey 2021/Reading/Enable sticky table headers.

Template:Sticky header creates a sticky scrolling table in the sense of the vertical scrollbar for the whole page. When you scroll the page the table headers stay visible when the table goes beyond the top of the screen. See also: Template:Sticky table start. It has an option for side sticky headers too. It puts the table in a scrollbox, and the scrollbars are part of that box.

See {{tl|Sticky header}} examples below:

{{sticky header}}

class="wikitable sortable sticky-header"

|+ Caption

ColorAB

! class="unsortable" | C

class=sorttop

| Max

101112
Red123
Lime456
Gold789
Blue101112
class=sortbottom

| Total

222630

{{sticky header}}

class="wikitable sortable sticky-header-multi"

|+ Caption

rowspan=2 | Color

! colspan=3 | Data

AB

! class="unsortable" | C

Red123
Lime456
Gold789
Blue101112
class=sortbottom

| Max

101112
class=sortbottom

| Total

222630

See list of articles transcluding {{tlc|sticky header}}. See [https://templatecount.toolforge.org/index.php?lang=en&namespace=10&name=Sticky_header#bottom transclusion count].

Scrolling tables with sticky column and row headers

Note: Sticky left-side row headers do not work correctly if table is inside a collapsible show/hide box. See [https://en.wikipedia.org/w/index.php?title=Wikipedia_talk:WikiProject_Tennis&oldid=1232355612#Timeshifter_table example]. ("Timeshifter table" section)

See: Template:Sticky table start. It incorporates the old Covid CSS, and it is easier to use. See Special:WhatLinksHere/Template:Sticky table start for examples.

There are several advanced scrolling tables (with row and column headers that stay visible and sticky while scrolling) in COVID-19 pandemic by country and territory and in COVID-19 pandemic deaths. The scrolling and sticky headers work in cell phones, too. Widest scrolling tables are on top of the list below. Narrow your browser window until you see a horizontal scroll bar. Drag it left and right to see the sticky row headers that stay visible.

A totally blind screen reader user noted in a discussion here that the scrolling tables in the related article (COVID-19 pandemic deaths) were not a problem.

Automatically updated scrolling tables with sticky headers

{{Hatnote|Note: Contact User:Tol (talk) for help with automated tables.}}

{{see also|Category:Automatically updated COVID-19 pandemic table templates}}

These scrolling tables linked below with top/side sticky headers are also automatically updated. Narrow browser window to see sticky headers on the side.

See discussion:

Transclude a table from another page

A table can be put in a template. For example, see [https://en.wikipedia.org/wiki/Special:PrefixIndex?prefix=Template%3AList+of+countries+by+life+expectancy%2F&namespace=0 this list of life expectancy table template subpages]. You can search for template subpages:

{{tl|Excerpt}} is the simplest tool for transcluding a table that is not in a template. Go there for many options. The simplest method:

{{Excerpt|Page source of table|Section with the table|this=This table is}}

It transcludes the table to wherever it is placed. It adds the following indented note above it in italics. The page section is linked, and there is an edit link for the source page:

:This table is an excerpt from Page source of table § Section with the table. [edit]

A hidden note just above the transcluded table is helpful. Such as:

:Table below is currently transcluded from here: https://en.wikipedia.org/wiki/Page_source_of_table#Section_with_the_table. If the source article or section name is changed, then the transclusion code below must also be changed.

A hidden note at the source section is helpful too. Such as:

:Table below is transcluded into another page: https://en.wikipedia.org/wiki/Page_with_transcluded_table#Section_with_the_table. Nothing needs to be added here for this to work. As long as the table remains in its own section, and that section name remains the same, then the transclusion works. If the section name here changes, then please change it in the {{excerpt}} template there.

All broken excerpts are automatically tracked at :Category:Articles with broken excerpts and regularly fixed.

Sortable tables

{{anchor|Sortable|Sorting|reason=pld section names}}

{{Main|Help:Sortable tables|mw:Help:Sortable tables}}

See Help:Sortable tables for details of how to make sortable tables. Tables can be made sortable by adding class="wikitable sortable" to the top line of the table wikitext. Individual columns can then be excluded from sorting with class=unsortable in the lowest header cell. Note: that data-sort-type=VALUE must go in the header cell with the sorting icon. That will be the lowest header cell. (See Help:Sortable tables § Forcing a column to have a particular data type).

Collapsible tables

{{see also|Help:Collapsing#Collapsible tables|mw:Manual:Collapsible elements}}

Classes can also be used to collapse tables, so they are hidden by default. Use the class {{nowrap|mw-collapsible}} to enable collapsing behaviour. Collapsible tables can be sortable, too, by also including the sortable class {{See below|{{section link||Sortable tables}}}}. By default, a collapsible table begins expanded. To change this, add the additional class {{nowrap|mw-collapsed}}. Alternatively, you can add autocollapse, instead of {{nowrap|mw-collapsed}}, which will automatically collapse the table if two or more collapsible elements are present on the page.

Note: Previous versions of this article recommended the collapsible class, but {{nowrap|mw-collapsible}} is now preferred. It is a feature of the MediaWiki software, not a local customization, and can be used to make any element collapsible, not just tables. {{nowrap|mw-collapsible}} also does not require a header row in the table, as collapsible did. Tables will show the {{nowrap|"[hide]" / "[show]"}} controls in the first row of the table (whether or not it is a header row), unless a table caption is present.{{See below|{{section link||Tables with captions}}}}

Example with a header row

Wikitext

class="wikitable mw-collapsible mw-collapsed"
Header
Content that starts hidden
More hidden content

Rendered result

class="wikitable mw-collapsible mw-collapsed"
Header
Content that starts hidden
More hidden content

Examples without a header row

Wikitext

class="wikitable mw-collapsible"
First row is always visible
Content that starts visible

Rendered result

class="wikitable mw-collapsible"
First row is always visible
Content that starts visible

Wikitext

class="wikitable mw-collapsible mw-collapsed"
First row is always visible
Other rows start hidden

Rendered result

class="wikitable mw-collapsible mw-collapsed"
First row is always visible
Other rows start hidden

Tables with captions

Tables with captions will collapse to the table caption. The header will not be visible when collapsed. Use {{tl|nowrap}} to keep the caption from being fit into a tiny vertical column when the table is collapsed.

Wikitext

class="wikitable mw-collapsible"

|+{{nowrap|Somewhat long table caption}}

Header
Content starts visible
More visible content

Rendered result.
Click "hide" to see

----

class="wikitable mw-collapsible"

|+{{nowrap|Somewhat long table caption}}

Header
Content starts visible
More visible content

Rendered result
(without {{nowrap}}.
Click "hide" to see

----

class="wikitable mw-collapsible"

|+Somewhat long table caption

Header
Content starts visible
More visible content

{{clear}}

Starting off collapsed:

Wikitext

class="wikitable mw-collapsible mw-collapsed"

|+{{nowrap|Somewhat long table caption}}

Header
Content starts hidden
More hidden content

Rendered result.
Click "hide" to see

----

class="wikitable mw-collapsible mw-collapsed"

|+{{nowrap|Somewhat long table caption}}

Header
Content starts hidden
More hidden content

Rendered result
(without {{nowrap}}.
Click "hide" to see

----

class="wikitable mw-collapsible mw-collapsed"

|+Somewhat long table caption

Header
Content starts hidden
More hidden content

Sorting and collapsing

{{shortcut|WP:TABLECOLLAPSE}}

It is possible to collapse a sortable table. To do so, you need to use this code:

:class="wikitable sortable mw-collapsible"

For example:

Wikitext

class="wikitable sortable mw-collapsible"

|+ Sortable and collapsible table

scope=col | Alphabetic

! scope=col | Numeric

! scope=col | Date

! scope=col class=unsortable | Unsortable

d202008-11-24This
b82004-03-01column
a61979-07-23cannot
c4.21492-12-08be
e01601-08-13sorted.

Rendered result

class="wikitable sortable mw-collapsible"

|+ Sortable and collapsible table

scope=col | Alphabetic

! scope=col | Numeric

! scope=col | Date

! scope=col class=unsortable | Unsortable

d202008-11-24This
b82004-03-01column
a61979-07-23cannot
c4.21492-12-08be
e01601-08-13sorted.

If you want the table to default to collapsed state, use the code

:{| class="wikitable sortable mw-collapsible mw-collapsed"

in place of

:{| class="wikitable sortable mw-collapsible"

Highlight rows on hover

Note: For usage examples, etc. go to {{t|row hover highlight}}.

To highlight rows upon hover, add {{tl|row hover highlight}} (or its alias, {{tl-r|mw-datatable}}) just above the table wikitext.

This enables use of class=mw-datatable and class=hover-highlight. Both add a {{background color|#eaf3ff|light blue}} highlight when you hover your cursor over a table row. class=mw-datatable also makes the background of the non-header cells white. It does not override existing background colors set for cells or rows. (class=wikitable produces a light gray background for data cells.)

Colors in tables

{{Hatnote|Guidelines, help, info: Manual of Style/Tables, MOS:COLOR (guideline), Help:Using colours, List of colors, Web colors.}}

{{hatnote|Link colors: MOS:COLORS (help), Help:Link color, [https://webaim.org/resources/linkcontrastchecker WebAIM: Link Contrast Checker].}}

{{Hatnote|Contrast tools: [https://webaim.org/resources/contrastchecker WebAIM: Contrast Checker], {{t|Color contrast ratio}}, {{t|Greater color contrast ratio}}, {{t|Color contrast conformance}}.}}

{{Hatnote|Templates: {{t|background color}}, {{t|font color}}, {{t|Coltit}}, {{t|Color}}.}}

{{Hatnote|Value-dependent color: {{t|cell color}}.}}

{{Hatnote| Night mode: mw:Recommendations for night mode compatibility on Wikimedia wikis.}}

Background colors are common in table cells. In many sports articles for example. See here. For the accessibility reasons stated in WP:COLOR, information should not be communicated by the use of color alone.

Two ways of specifying color of text and background for a single cell are as follows:

Wikitext

style="background-color: red; color: white;"|abc

| def

| style="background-color: red;"|ghi

| jkl

Produces

style="background-color: red; color: white;"|abc

| def

| style="background-color: red;"|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.

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.{{which}}

Wiki markup

style="background-color: yellow; color: green;"
stustyle="background-color: silver;" | vwxyz
style="background-color: red; color: white;"

| stu

style="background-color: silver;" | vwxyz
stustyle="background-color: silver;" | vwxyz

Produces

style="background-color: yellow; color: green"
stustyle="background-color: silver;" | vwxyz
style="background-color: red; color: white;"

| stu

style="background-color: silver;" | vwxyz
stustyle="background-color: silver;" | vwxyz

To force a cell to match one of the default colors of the class=wikitable template, use style="background-color:#EAECF0;" {{Legend inline|#EAECF0|outline=#A2A9B1}} for the darker header, and style="background-color:#F8F9FA;" {{Legend inline|#F8F9FA|outline=#A2A9B1}} for the lighter body. #A2A9B1 is the wikitables border color.

=Avoid background:none or transparent=

= Background colors for column headers =

style="background-color:…" works in sortable header cells. style="background:…" does not. It breaks sorting in that cell. See Help:Sortable tables. So use style="background-color:…" for all column header cells whether currently sortable or not. Someone may attempt to make them sortable later.

= Breaking up tables without losing colors =

Normally, copying and pasting columns or rows removes the inline CSS styling such as cell colors. There is a way to break up a table (a too-wide table for example) into more tables without losing all the background colors, and other inline styling. Copy the table to 2 sandboxes (or one sandbox, and in the article itself). Then delete the columns not needed on one of the new tables. Repeat in the other sandbox (or in the article) except delete different columns.

= Copying off-wiki tables with colored cells to wikis =

There are many off-wiki tables with useful coloring that meet WCAG access standards. Currently, there does not seem to be a way to copy those tables to a wiki and keep styling such as colors (background or text color). It is possible to convert PDF tables to Excel and keep the colors. Or to HTML tables and keep the colors. But there does not seem to be a way to copy any of those colored tables (PDF, Excel, HTML, etc.) to a wiki. If there is a way, please leave a note on Help talk:Table.

If desired one can keep the coloring by copying the table as an image. This may be necessary for frequently updated colored tables where it would be too time consuming to add color to many cells after each update. There is no problem with copyright for most data tables, colored or not. They are in the public domain. See Commons:Template:PD-chart.

Other table syntax

The types of table syntax that MediaWiki supports are:

  1. Wikicode  |  syntax
  2. HTML (and XHTML)
  3. Mixed XHTML and wikicode (Do not use)

All three are supported by MediaWiki and create (currently) valid HTML output, but the § Wikicode syntax is the simplest. Mixed HTML and wikicode  |  syntax (i.e., unclosed  |  and |- tags) don't necessarily remain browser-supported in the future, especially on mobile devices.

See also HTML element#Tables.

= Unsupported Html elements =

Note, however, that the thead, tbody, tfoot, colgroup, and col elements are currently not supported in MediaWiki, {{as of|lc=y|2025|01}}.

= Table syntax comparison =

{{mw-datatable}}

class="wikitable mw-datatable"

|+ Table syntax comparison

!

! scope="col" | XHTML

! scope="col" | Wiki-pipe

scope="row" | Table

| {{tag|table}}

| {|
...

|-

! scope="row" | Caption

| {{tag|caption|content={{var|caption}}}}

| |+ {{var|caption}}

|-

! scope="row" | Header cell

| {{tag|th|params=scope="col"|content={{var|column header}}}}

{{tag|th|params=scope="row"|content={{var|row header}}}}

| ! scope="col" | {{var|column header}}

! scope="row" | {{var|row header}}

|-

! scope="row" | Row

| {{tag|tr}}

| |-

|-

! scope="row" | Data cell

| {{tag|td|content={{var|cell1}}}}{{tag|td|content={{var|cell2}}}}
{{tag|td|content={{var|cell3}}}}

| | {{var|cell1}} || {{var|cell2}} || {{var|cell3}}

or

| {{var|cell1}}

| {{var|cell2}}

| {{var|cell3}}

|-

! scope="row" | Cell attribute

| {{tag|td|attribs=style="font-size: 87%;"|content={{var|cell1}}}}

| | style="font-size: 87%;" | {{var|cell1}}

|-

! scope="row" | Sample table

|

1 2
3 4

|

12
34

class="wikitable" style="margin: auto;"
12
34

|- style="vertical-align: top;"

! scope="row" | Pros

|

  • Can preview or debug with any XHTML editor
  • Can be indented for easier reading
  • Well-known
  • Insensitive to newlines
  • No characters like "|", which can collide with template and parser function syntax

|

  • Easy to write
  • Easy to read
  • Takes little space
  • Can be learned quickly

|- style="vertical-align: top;"

! scope="row" | Cons

|

  • Tedious
  • Takes a lot of space
  • Difficult to read quickly
  • Debugging more difficult because of tag pairing requirements
  • Indented code might not match nesting.
  • Confusing newline behaviour as they only occasionally break cells.

|

  • Unfamiliar syntax for experienced HTML editors
  • Rigid structure
  • Cannot be indented for clarity
  • HTML tag text may be easier to read than pipes, plus signs, dashes, etc.
  • Requires using {{tlx|!}} to pass a  |  character in a parameter.
  • Sensitive to newlines; see Help:Newlines and spaces.

|}

See also

  • Help:Table for general information about using tables. It also has many links in its "See also" and "External links" sections. Rather than duplicating them here.

{{Help navigation}}

{{Wikipedia technical help|collapsed}}

Category:Wikipedia how-to

Category:Wikipedia text help