Tables

**This page is currently in creation**
 It is a new article developing through collaboration and successive edits. If you have concerns about it, please comment on the **talk page** of the **this article**
To help avoid **Edit conflicts** and **other confusion**, the creator asks that **for a short time** this page not be edited unnecessarily, or **nominated for deletion** during **this early stage** of development.
There is a lot more that can be done with tables then the insert function allows for. This information has been copied over from https://www.mediawiki.org/wiki/Help:Tables which is an article that I found very useful when I first started thinking about advance page construction.

## Wiki table markup summary

* The above marks must **start on a new line** except the double `||` and `!!` for optionally adding consecutive cells to a line. However, blank spaces at the beginning of a line are ignored.
* **HTML attributes.** Each mark, except table end, optionally accepts one or more HTML attributes. Attributes must be on the same line as the mark. Separate attributes from each other with a single space.
	+ Table and row marks (`{|` and `|-`) do not directly hold content. Do *not* add pipe (`|`) after their optional attributes. If you erroneously add a pipe after attributes for the table mark or row mark the parser will delete it *and* your final attribute if it was touching the erroneous pipe!
* **Content** may (a) follow its cell mark on the same line after any optional HTML attributes or (b) on lines below the cell mark. Content that uses wiki markup that itself needs to start on a new line, such as lists, headings, or nested tables, must be on its own new line.
	+ **Pipe character as content.**

To insert a pipe (`|`) character into a table, use the <nowiki>`|`</nowiki> escaping markup.

## Basics

The following table lacks borders and good spacing but shows the simplest wiki markup table structure.
</translate>

```

```

 <translate> Bread</translate>
 <translate> Butter</translate>

<translate>
The cells in the same row can be listed on one line separated by `||` (two pipe symbols).</translate>
<translate>
If the text in the cell should contain a line break, use <tvar|br>`<br/>`</> instead.
</translate>

```

```

 <translate> Butter</translate> | <translate> Icecream</translate> | <translate> andmore</translate>

<translate>
Extra spaces within cells in the wiki markup, as in the wiki markup below, do not affect the actual table rendering.
</translate>

```

```

 <translate> Butter</translate> | <translate> Ice cream</translate> | <translate> and more</translate>

<translate>
You can have longer text or more complex wiki syntax inside table cells, too:
</translate>

```
consetetur sadipscing elitr,
sed diam nonumy eirmod tempor invidunt
ut labore et dolore magna aliquyam erat,
sed diam voluptua.

At vero eos et accusam et justo duo dolores
et ea rebum. Stet clita kasd gubergren,
no sea takimata sanctus est Lorem ipsum
dolor sit amet.
* Lorem ipsum dolor sit amet
* consetetur sadipscing elitr
* sed diam nonumy eirmod tempor invidunt

```

consetetur sadipscing elitr,
sed diam nonumy eirmod tempor invidunt
ut labore et dolore magna aliquyam erat,
sed diam voluptua.
At vero eos et accusam et justo duo dolores
et ea rebum. Stet clita kasd gubergren,
no sea takimata sanctus est Lorem ipsum
dolor sit amet.
* consetetur sadipscing elitr
* sed diam nonumy eirmod tempor invidunt

<translate>

### Table headers

Table headers can be created by using "`!`" (exclamation mark) instead of "`|`" (pipe symbol).</translate>
<translate>
Headers usually show up bold and centered by default.
</translate>

```
! style="text-align:left;"| <translate><!--T:66--> Item</translate>
! <translate><!--T:67--> Amount</translate>
! <translate><!--T:68--> Cost</translate>
!<translate><!--T:72--> Total</translate>

```

 <translate> Bread</translate>
 <translate> Butter</translate>
 <translate> Total</translate>

A pipe ' | ' is used for separation. Not an exclamation character '!'.

<translate>

### Caption

A **table caption** can be added to the top of any table as follows.
</translate>

```

```

<translate> Food complements</translate>
 <translate> Bread</translate>
 <translate> Butter</translate>

<translate>

### class="wikitable"

Basic styling (light gray background, borders, padding and align left) can be achieved by adding class="wikitable".
</translate>

```
{| class="wikitable"

```

<translate> Food complements</translate>
 <translate> Bread</translate>
 <translate> Butter</translate>

<translate>

### HTML colspan and rowspan

You can use HTML **colspan** and **rowspan** attributes on cells for advanced layout.
</translate>

```
{| class="wikitable"
!colspan="6"|<translate><!--T:120--> Shopping List</translate>

```

 <translate> Cheese</translate>

<translate>

## HTML attributes

You can add **HTML attributes** to tables.</translate>
<translate>
For the authoritative source on HTML attributes, see [<tvar|url>https://www.w3.org/TR/html401/struct/tables.html</> the W3C's HTML Specification page on tables].

### Attributes on tables

Placing attributes after the table start tag (`{|`) applies attributes to the entire table.</translate>

```
{| class="wikitable" style="text-align: center; color: green;"

```

 <translate> Bread</translate>
 <translate> Butter</translate>

<translate>

### Attributes on cells

You can put attributes on individual **cells**.</translate>
<translate>
For example, numbers may look better aligned right.</translate>

```
{| class="wikitable"

```

 <translate> Bread</translate>
 <translate> Butter</translate>

<translate>
You can also use **cell** attributes when you are listing multiple **cells** on a single line.</translate>
<translate>
Note that the **cells** are separated by `||`, and within each **cell** the attribute(s) and value are separated by `|`.</translate>

```
{| class="wikitable"

```

 <translate> Butter</translate> | <translate> Ice cream</translate> | 1.00

<translate>

### Attributes on rows

You can put attributes on individual **rows**, too.
</translate>

```
{| class="wikitable"

```

 <translate> Bread</translate>
 <translate> Butter</translate>

<translate>

### Simple one-pixel table border

An example of a one-pixel table border:
</translate>

```
{| border="1" style="border-collapse:collapse"

```

 <translate> Bread</translate>

<translate>

### Border width

If "border-width:" has only one number, it is for all four border sides:
</translate>

```
{|style="border-style: solid; border-width: 20px"
<translate><!--T:218--> Hello</translate>

```

<translate>
If "border-width:" has more than one number, the four numbers are for **top, right, bottom, left (REMEMBER clockwise order <tvar|clockwise>↑→↓←</>)**:</translate>

```
{|style="border-style: solid; border-width: 10px 20px 100px 0"
<translate><!--T:223--> Hello</translate>

```

<translate>

When there are fewer than 4 values :</translate>
* <translate> three values i.e. <tvar|3val>`top`, `right`, `bottom`</>: then the default value for <tvar|left>`left`</> is the one of <tvar|right>`right`</> (second value). Width is then the same on left and right side.</translate>

<translate>
Another method to define the widths of the four sides of a cell is to use *"border-left", "border-right", "border-top" and "border-bottom"*:</translate>

```
{|style="border-left:solid 10px black;border-right:solid 20px black;border-top:solid 30px black;border-bottom:solid 40px black;" align="center"
<translate><!--T:229--> Hello</translate>

```

<translate> The HTML attributes (such as "width=", "border=", "cellspacing=", "cellpadding=") do not need any length unit (the pixel unit is assumed).</translate> <translate> They are also invalid in HTML 5.</translate>

<translate>
"Cellpadding" is for setting the space between the cell wall and the cell content.</translate>

<translate>

The CSS style properties (which override the HTML attributes) require an explicit length unit (if the value is not 0) such as "px" for the pixel.</translate>

<translate>

### With HTML attributes and CSS styles

Template:Ll style attributes can be added with or without other HTML attributes.</translate>

```
{| class="wikitable" style="color:green; background-color:#ffffcc;" cellpadding="10"

```

 <translate> Bread</translate>
 <translate> Butter</translate>

### Padding

```
{|class=wikitable

```

 <translate> Example of <tvar|1>style="padding:100px"</></translate>

<translate>

#### Attributes

**Attributes** can be added to the caption and headers as follows.
</translate>

```
{| class="wikitable"

```

<translate> *Food complements*</translate>
 <translate> Bread</translate>
 <translate> Butter</translate>

<translate>

#### Column width

**Column width** can be added as follows.

You type:
</translate>

```
{| class="wikitable" style="width: 85%;"

```

<translate>
You get:</translate>

 <translate> **This column is 30% counted from 85% of the screen width**</translate>

<translate>

### Accessibility of table header cells

Table header cells do not explicitly specify which table data cells they apply to (those on their right on the same row, or those below them on the same column).</translate>
<translate>
When the table is rendered in a visual 2D environment, this is usually easy to infer.

However when tables are rendered on non-visual media, you can help the browser to determine which table header cell applies to the description of any selected cell (in order to repeat its content in some accessibility helper) using a scope="row" or scope="col" attribute on table header cells.</translate>
<translate>
In most cases with simple tables, you'll use scope="col" on all header cells of the first row, and scope="row" on the first cell of the following rows:
</translate>

```
{| class="wikitable"
! scope="col"| <translate><!--T:284--> Item</translate>
! scope="col"| <translate><!--T:285--> Quantity</translate>
! scope="col"| <translate><!--T:286--> Price</translate>
! scope="row"| <translate><!--T:287--> Bread</translate>
! scope="row"| <translate><!--T:288--> Butter</translate>
! scope="row" colspan="2"| <translate><!--T:289--> Total</translate>

```

 <translate> Butter</translate>
 <translate> Total</translate>

<translate>

## Alignment

### Table alignment

Table alignment is achieved by using CSS.</translate>
<translate>
The table alignment is controlled by margins.</translate>
<translate>
A fixed margin on one side will make the table to be aligned to that side, if on the opposite side the margin is defined as *auto*.</translate>
<translate>
To have a table center aligned, you should set both margins to *auto*</translate>

<translate>
For example, a right-aligned table:</translate>

```
{| class="wikitable" style="margin-left: auto; margin-right: 0px;"

```

 <translate> Bread</translate>
 <translate> Butter</translate>

<translate>
And a center-aligned table:</translate>

```
{| class="wikitable" style="margin: auto;"

```

 <translate> Bread</translate>
 <translate> Butter</translate>

<translate>

### Table floating around text

If you align a table to the right or the left side of the page, the text that comes after the table starts at the end of it, leaving an empty space around the table.</translate>
<translate>
You can make the text to be wrapped around the table by making the table to *float* around the text instead of just aligning it.</translate>
<translate>
This can be achieved using the `float` CSS attribute, which can specify where the table floats to the right side or to the left.</translate>
<translate>
When using *float*, margins doesn't control table alignment and can be used to specify the margin between the table and the surrounding text.</translate>

```
{| class="wikitable" style="float:right; margin-left: 10px;"

Lorem ipsum dolor sit amet, consectetuer adipiscing
elit, sed diam nonummy nibh euismod tincidunt ut
laoreet dolore magna aliquam erat volutpat. Ut wisi
enim ad minim veniam, quis nostrud exerci tation
ullamcorper suscipit lobortis nisl ut aliquip ex ea
commodo consequat. Duis autem vel eum iriure dolor
in hendrerit in vulputate velit esse molestie consequat,
vel illum dolore eu feugiat nulla facilisis at vero
eros et accumsan et iusto odio dignissim qui blandit
praesent luptatum zzril delenit augue duis dolore te
feugait nulla facilisi.

```

 <translate> Bread</translate>
 <translate> Butter</translate>

Lorem ipsum dolor sit amet, consectetuer adipiscing
elit, sed diam nonummy nibh euismod tincidunt ut
laoreet dolore magna aliquam erat volutpat. Ut wisi
enim ad minim veniam, quis nostrud exerci tation
ullamcorper suscipit lobortis nisl ut aliquip ex ea
commodo consequat. Duis autem vel eum iriure dolor
in hendrerit in vulputate velit esse molestie consequat,
vel illum dolore eu feugiat nulla facilisis at vero
eros et accumsan et iusto odio dignissim qui blandit
praesent luptatum zzril delenit augue duis dolore te
feugait nulla facilisi.

<translate>

### Cell contents alignment

The alignment of cell contents can be controlled with 2 different CSS properties: `text-align` and `vertical-align`.</translate>
<translate>
`text-align` can be specified at the table, row or individual cells, while `vertical-align` only can be specified at individual rows or cells.</translate>

```
{| class="wikitable"

```

 D
 G

<translate>

## Caveats

### Negative numbers

If you start a cell on a new line with a negative number with a minus sign (or a parameter that evaluates to a negative number), your table can get broken, because the characters `|-` will be parsed as the wiki markup for table row, not table cell.</translate>
<translate>
To avoid this, insert a space before the value (`| -6`) or use in-line cell markup (`|| -6`).

### CSS vs attributes

Table borders specified through CSS rather than the border attribute will render incorrectly in a small subset of text browsers.

### Common attributes for columns, column groups and row groups

<translate>
Those standard HTML elements are not accepted even in their HTML or XHTML syntax.</translate>

<translate>
All the rows and cells (header or data) of the table are rendered within a single implicit row group (HTML element `<tbody></tbody>`) without any attributes or styles.

## See also

* [[<tvar|1>Special:MyLanguage/Help:Sorting#Sorting rows of a table</>|Sorting rows of a table]]
* <translate> m:Help:Sorting</translate>
* w:Help:Tables
* Easy tool that helps generating tables