सहायता:तालिका - विकिपीडिया
सामग्री पर जाएँ
मुक्त ज्ञानकोश विकिपीडिया से
How to create and use tables in markup
साँचा:SHORTDESC:How to create and use tables in markup
साँचा:Table help
इस पृष्ठ पर हिन्दी विकिपीडिया के अभ्यास या प्रक्रिया का विवरण करती
मार्गदर्शिका
है। यह
विकिपीडिया की नीतियों या दिशा-निर्देशों
में से एक नहीं है।
लघु पथ
H:TABLE
साँचा:Simple
साँचा:Wiki markup
Page
सहायता:तालिका/styles.css
must have content model "Sanitized CSS" for TemplateStyles (current model is "विकिटेक्स्ट").
एक
टेबल
स्तंभों और पंक्तियों की एक व्यवस्था है जो डेटा या छवियों को व्यवस्थित और स्थानबद्ध करती है। विकिपीडिया पृष्ठों पर विशेष
विकिटेक्स्ट
सिंटैक्स, या
एचटीएमएल सिंटैक्स
का उपयोग करके टेबल बनाई जा सकती हैं, और उन्हें अनुकूलित करने के लिए कई अलग-अलग शैलियों और ट्रिक्स का उपयोग किया जा सकता है।
टूल
संपादित करें
स्रोत मोड टूलबार
संपादित करें
Vector
toolbar – default. Table icon
is circled.
Monobook
toolbar. Table icon
is on the right end.
स्वचालित रूप से तालिका सम्मिलित करने के लिए,
संपादन टूलबार
पर
या
(तालिका सम्मिलित करें) पर क्लिक करें। वेक्टर टूलबार में तालिका चिह्न "एडवांस्ड" मेनू में होता है।
Insert a table
पर क्लिक करने पर निम्नलिखित विकिटेक्स्ट सम्मिलित किया जाता है।
{|
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
आप स्रोत मोड में रहते हुए तालिका भर सकते हैं। या यथादृश्य संपादिका का उपयोग करें। स्रोत मोड में कई पंक्तियों या स्तंभों में फैले कक्षों के साथ अधिक जटिल तालिका संरचनाएँ बनाने के लिए,
सहायता:तालिका §
Notes
देखें।
Visual editor
संपादित करें
See:
Help:Tables and VisualEditor
. And:
Help:Creating tables#Tables and visual editor
With the
visual editor
(VE) you directly fill in the cells without having to go through wikitext. VE makes it easy to add or delete rows or columns. In VE this is what shows up when clicking the table icon (in the "Insert" menu):
For more complex table structures, 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, 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
संपादित करें
ये भी देखें:
Help:Creating tables § Spreadsheet/database tables to wikitables
, और
Wikipedia:Tools § Importing (converting) content to Wikipedia (MediaWiki) format
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 a knowledge of HTML.
Markup
संपादित करें
ये भी देखें:
Help:Basic table markup
साँचा:Mw-datatable
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 double (pipeline) marks (
||
) – or start on new lines, each with their own single (pipeline) marks (
).
The pipeline symbol is also used to separate pertaining
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 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 a
pipe character
) into a table caption or cell, use the
nowiki
/nowiki
escaping markup.
HTML attributes
संपादित करें
Each mark, except table end (
|}
), optionally accepts one or more
attributes
. Attributes must be on the same line as the mark.
Cells
and
captions
or
||
or
!!
, and
|+
) hold
content
—separate any attribute from its content with a single pipe (
), with attributes preceding content.
Table
and
row
marks (
{|
and
|-
) do not directly hold content. Do
not
add a pipe (
) after any attributes.
Commonly included attributes with table scope include:
class
, for example
class="wikitable"
; or
style
for
CSS
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; and
colspan
, to extend cells by more than one column.
Wikicode syntax tutorial
संपादित करें
पृष्ठ
सहायता:Table/styles.css
रिक्त है
मुख्य पृष्ठ:
Help:Basic table markup
a history of the development of wikicode table syntax के लिए,
/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
सहायता:तालिका §
Notes
below.
Caption
संपादित करें
An optional
table
caption
is included with a line starting with a vertical bar and plus sign "
|+
" and the caption 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 codes for the cells in that row start on the next line.
{|
|+
The table's caption
|-
row 1 cells go here
|-
row 2 cells go here
|}
For details about rows, see
सहायता:तालिका §
Notes
below.
Cells
संपादित करें
Type the codes for each
table cell
in the next row, starting with a 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 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
सहायता:तालिका §
Notes
below.
Optional parameters
संपादित करें
Optional
parameters
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 Wikipedia's
external style sheet
is defined to apply a gray color scheme and cell borders to tables using 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
and
Table (HTML)
. However, the
thead
tbody
tfoot
colgroup
, and
col
elements are currently
not supported in MediaWiki
दिसम्बर 2021 के अनुसार
update
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, like
meta: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
in one of the cells. That is what is done here:
साँचा:Oldid2
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 below
Displaying a pipe character
संपादित करें
Displaying a
pipe
character as part of the text of a table cell requires a workaround. See
सहायता:तालिका §
Notes
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 data tables because it explicitly associates the header with the corresponding cells, which helps ensure a consistent experience for screen readers. The Manual of Style
requires the use of scope for 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 two columns or a row header of two rows. When headers are unclear, this can cause accessibility issues; therefore, use
id=
to set a unique value without spaces on each header, then reference the id(s) on the data cells that have unclear headers using
headers=
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 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
{|
|-
|-
|}
{|
|-
||
|-
||
|}
Produces (note that there are no borders).
Multiplication table
संपादित करें
Note that 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
|-
|-
||
||
|-
||
||
|}
Produces
Multiplication table
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 style to the 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, 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. See
here
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. 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="float:right; clear:right; margin-left:8px"
to the entire table
floatleft
– same as applying
style="float:left; clear: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
संपादित करें
इस विषय पर अधिक जानकारी हेतु,
Wikipedia:Manual of Style/Accessibility/Data tables tutorial#Proper table captions and summaries
पर जाएँ
Explicit table
captions
(or
titles
) are recommended for data tables as a best practice; the Wikipedia 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 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. But
screen 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:
|+
{{
sro
Table caption
}}
For current table caption and summary guidelines see the w3.org page:
Caption & Summary, in Tables Tutorial
Web Accessibility Initiative
(WAI). The summary info in the paragraph below is out of date:
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 parameters for the table as a whole.
The
summary=
attribute is, however,
obsolete in HTML
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
साँचा:Dummy ref
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=
content
Similarly, one can create cells that stretch over two or more rows. This requires
|rowspan=
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;"
col1
col2
col3
col4
|-
row1
colspan
|-
row2
AA
BB
CC
|-
row3
AAA
rowspan
BBB
CCC
|-
row4
AAAA
CCCC
|}
Produces
col1
col2
col3
col4
row1
row2
AA
BB
CC
row3
AAA
BBB
CCC
row4
AAAA
CCCC
In the code, the cell
| colspan="2" | A
spans two columns. Note that, 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
colspan
style
"text-align: center;"
|-
|-
rowspan
colspan
style
"text-align: center;"
|-
|-
colspan
style
"text-align: center;"
|}
Produces
Column 1
Column 2
Column 3
Note that using
rowspan=2
for cell
combined with
rowspan=3
for cell
to get another row below
and
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
{|
class
wikitable
|-
Column 1
(row 1 cell 1)
!!
Column 2
(row 1 cell 2)
!!
Column 3
(row 1 cell 3)
|-
rowspan
br
(row 2 cell 1)
br
><
code
rowspan=2
code
colspan
style
"text-align: center;"
br
(row 2 cell 2)
br
><
code
colspan=2
code
|-
br
(row 3 cell 1)
br
(row 3 cell 2)
|-
br
(row 4 cell 1)
rowspan
colspan
style
"text-align: center;"
br
(row 4 cell 2)
br
><
code
rowspan=2 colspan=2
code
|-
br
(row 5 cell 1)
|-
colspan
style
"text-align: center;"
br
(row 6 cell 1)
br
><
code
colspan=3
code
|}
Produces
Column 1
(row 1 cell 1)
Column 2
(row 1 cell 2)
Column 3
(row 1 cell 3)
(row 2 cell 1)
rowspan=2
(row 2 cell 2)
colspan=2
(row 3 cell 1)
(row 3 cell 2)
(row 4 cell 1)
(row 4 cell 2)
rowspan=2 colspan=2
(row 5 cell 1)
(row 6 cell 1)
colspan=3
Note that although cell
is in column 2,
is the 1st cell declared in row 3, because column 1 is occupied by cell
, which was declared in row 2. Cell
is the only cell declared in row 5, because cell
occupies the other columns but was declared in row 4.
Table style
संपादित करें
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. Note that in some cases, it may be better to use the style encapsulated in one of the predefined classes; see
सहायता:तालिका §
Notes
Horizontal text alignment
संपादित करें
इस विषय पर अधिक जानकारी हेतु,
Help:Table/Advanced#Horizontal alignment in cells
पर जाएँ
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:
{|
class
wikitable
style
text-align:right;
...
|}
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:
{|
class
wikitable
style
height:14em;
. . .
|}
Note that 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
{|
style
"border-spacing: 2px; border: 1px solid darkgray;"
style
"width: 140px;"
Left
style
"width: 150px;"
Center
style
"width: 130px;"
Right
|-
[[
File
Starred.svg
120px
center
]]
[[
File
Star full.svg
120px
center
]]
[[
File
Stargreen.svg
120px
center
]]
|-
style
"text-align: center;"
Red star
||
Orange star
||
Green star
|}
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
{|
border
|-
||
||
|-
||
||
|}
Produces
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
{|
border
style
"border-collapse: collapse;"
|-
||
||
|-
||
||
|}
Produces
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
This paragraph is before the table.
[[
File
Starred.svg
120px
right
]]
{|
class
"wikitable floatleft"
|+
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
|}
{|
class
"wikitable floatright"
|+
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
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
साँचा: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
साँचा:Lorem ipsum span
Centering tables
संपादित करें
Shortcut
HELP:TABLECENTER
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
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.
Style
margin: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.
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
Wikitext:
{|
style
"border: 1px solid black;"
style
"border: 1px solid black;"
α
style
"border: 1px solid black; text-align:center;"
cell2
{|
style
"border: 2px solid black; background: #ffffcc;"
style
"border: 2px solid darkgray;"
NESTED
|-
style
"border: 2px solid darkgray;"
TABLE
|}
style
"border: 1px solid black; vertical-align: bottom;"
the original table again
style
"border: 1px solid black; width:100px"
{|
style
"border: 2px solid black; background: #ffffcc"
style
"border: 2px solid darkgray;"
|}
{|
style
"border: 2px solid black; background: #ffffcc"
style
"border: 2px solid darkgray;"
style
"border: 2px solid darkgray;"
|}
style
"border: 1px solid black; width: 50px"
{|
style
"border: 2px solid black; background:#ffffcc; float:left"
style
"border: 2px solid darkgray;"
|}
{|
style
"border: 2px solid black; background:#ffffcc; float:right"
style
"border: 2px solid darkgray;"
|}
|}
Column operations
संपादित करें
There are column and cell operations for width. See the
Width
section that follows.
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 move or delete columns see
Help:Creating tables#Move/delete row/column
To sort some or all columns in a table see
Help:Sortable tables
Width
संपादित करें
ये भी देखें:
Help:Table/Width
Note:
width=X
is obsolete in
HTML 5
, and so it could eventually be ignored by
MediaWiki
. See:
Wikipedia: HTML 5#Table attributes
. Use CSS styles or line breaks (
) instead.
Template:Sticky table start
is helpful. It makes both the top header and the left-side column sticky. It works on mobile too. This makes wide tables visible on narrow screens via scrolling. Look at the examples in the documentation to understand. In some cases breaking up tables is a better solution.
Vertical headers
संपादित करें
Sometimes it is desirable to rotate header text such that it proceeds from top to bottom or bottom to top instead of from left to right or right to left. This can be done with CSS but the easiest way on Wikipedia is to enclose the text of headings in a vertical header template. Note that line breaks
may be placed in vertical headers. This allows cell phones in landscape view to see the table, and not just the headers. Note that if using a 2-column vertical header there must be at least one cell below it with a minimum of 3 characters. See
vertical header
for more info and tips.
{{
vertical header
|[[
Wikipedia
WikiProject Video games/Article guidelines
VG: Article
br
guidelines
]]}}
If the text includes an equals sign then replace it with
{{=}}
Rotated column headers using
{{
vertical header
}}
साँचा:Vertical header
साँचा:Vertical header
साँचा:Vertical header
साँचा:Vertical header
साँचा:Vertical header
साँचा:Vertical header
साँचा:Vertical header
साँचा:Vertical header
साँचा:Vertical header
साँचा:Vertical header
05/08
4266
7828
7282
1105
224
161
916
506
231
04/08
4127
6190
6487
1139
241
205
1165
478
301
If you want to use
sticky headers
with vertical headers it is important to make the sticky header less tall for cell phone use.
abbr
is one way. Also by moving some info to the table caption. See example with various methods at
vertical header
Line breaks in headers
संपादित करें
An editor who is blind says line breaks
are fine in this discussion
here
. If it is just two words in the column header, then a line break is simplest. Or if you want three words on separate lines in the header. But for longer header text, max-width is sometimes better, because when the viewport is narrow enough the browser may narrow the header to be less than the max-width setting. The browser often does this better than what line breaks allow in a narrow viewport.
Max-width
संपादित करें
Narrowing columns with
max-width
style is fine; such as
style="max-width:Xpx;"
or
style="max-width:Xem;"
or
other CSS units
. The number by itself without units defaults to pixels.
See width examples on this
subpage
. There it is easier to narrow the browser window and not lose one's place as on a long page such as here on Help:Table. Overall table width does not act the same on Wikipedia mobile view as it does on mobile view on webpages outside Wikipedia. See the subpage examples.
Setting strict widths (
style="width:Xpx;"
or
style="width:Xem;"
) is discouraged for the most part on Wikipedia because it interferes with the ability of the browser to adjust content to suit the browser window, device size, portrait view, landscape view, zoom settings, user-end font size choices, and other constraints. Verbose notes columns are almost always a problem, especially when there are more than a few other columns. Editors sometimes try to make the notes column wider, which messes up the other columns. For this reason, verbose notes columns should be avoided, or the notes should be shortened and links to longer notes below the table should be added instead.
style=max-width:Xem
can be used in table headers. The following table excerpt is adapted from
this version
of
List of countries by wealth per adult
. The goal is to
narrow the data columns,
and have the
country names spread out on one line each
. All of this makes it easier when scanning down a country list. But the country names have to wordwrap if needed (in narrow portrait views on some cell phones, etc.). So
style=max-width:Xem
was used in selected column heads.
Em units
are good because they increase in size along with the zoom setting. It is important to check if the max-width you have chosen also works correctly in cell phones, and is not breaking words. You may need to increase it a bit. Here is the relevant header wikitext:
Wikitext
{{
static row numbers
}}{{
sticky header
}}{{
table alignment
}}
{|
class
"wikitable sortable static-row-numbers sticky-header col1left"
style
text-align:right
|+
Median and mean wealth per adult ([[USD]]) by country
|-
Location
style
max-width:4em
Median wealth
style
max-width:4em
Mean wealth
...
Produces
साँचा:Sticky header
Median and mean wealth per adult (
USD
) by country
Location
Median wealth
Mean wealth
साँचा:DRC
382
1,084
मोज़ाम्बीक
352
880
sort under
narrows the table columns further:
Wikitext
{{
static row numbers
}}{{
sticky header
}}{{
sort under
}}{{
table alignment
}}
{|
class
"wikitable sortable static-row-numbers sticky-header sort-under col1left"
style
text-align:right
Produces
साँचा:Sticky header
साँचा:Sort under
Median and mean wealth per adult (
USD
) by country
Location
Median wealth
Mean wealth
साँचा:DRC
382
1,084
मोज़ाम्बीक
352
880
If using
sticky header
, then for cell phones even narrower headers are better:
साँचा:Sticky header
साँचा:Sort under
Median
and
mean
wealth per adult (
USD
) by country
Location
Median
Mean
साँचा:DRC
382
1,084
मोज़ाम्बीक
352
880
Here below is what the table looks like without
style=max-width:Xem
and without a
caption
Narrow your browser window to see how the table below contracts versus the ones above. The table above (even if some more columns are added) maintains one line per country for narrower browser and screen widths. So it is therefore more readable and scannable in long country tables. The table format below can greatly increase in number of lines, and require more vertical scrolling, especially if more columns are added.
साँचा:Sticky header
Location
Median wealth per adult (
USD
Mean wealth per adult (
USD
साँचा:DRC
382
1,084
मोज़ाम्बीक
352
880
Other width methods
संपादित करें
Note:
Fixed widths are not recommended for tables. Max-width is better. See previous section
To force initial column widths to specific requirements, rather than accepting the width of the widest text element in a column's cells, follow this example. Note that
wrap-around of text
is forced for columns where the width requires it. Do not use
min-width:Xpx;
Wikitext
{|
class
wikitable
|-
scope
"col"
style
"width: 50px;"
Name
scope
"col"
style
"width: 250px;"
Effect
scope
"col"
style
"width: 350px;"
Games found in
|-
Poké Ball
||
Regular Poké Ball
||
All versions
|-
Great Ball
||
Better than a Poké Ball
||
All versions
|}
Produces
Name
Effect
Games found in
Poké Ball
Regular Poké Ball
All versions
Great Ball
Better than a Poké Ball
All versions
To set column widths in a table without headers, specify the width in the first cell for each column.
Wikitext
{|
class
wikitable
|-
style
"width: 100pt;"
This column is 100 points wide
style
"width: 200pt;"
This column is 200 points wide
style
"width: 250pt;"
This column is 250 points wide
|-
blah
||
blih
||
bluh
|}
Produces
This column is 100 points wide
This column is 200 points wide
This column is 250 points wide
blah
blih
bluh
You can also use percentages, such as
style="width: 50%;"
to equalize the widths of a two-column table.
One application of setting the widths is aligning columns of consecutive tables. The following are separate tables, with columns set to 350px and 225px.
Wikitext
{|
class
wikitable
|-
scope
col
style
"width: 350px;"
Country
scope
col
style
"width: 225px;"
Capital
|-
Netherlands
||
Amsterdam
|}
{|
class
wikitable
|-
scope
col
style
"width: 350px;"
Country
scope
col
style
"width: 225px;"
Capital
|-
France
||
Paris
|}
Produces
Country
Capital
Netherlands
Amsterdam
Country
Capital
France
Paris
Nowrap
संपादित करें
A column will be as wide as its widest cell. To keep a cell from wrapping use
style="white-space: nowrap;"
If the cell is too wide though this may not be a good idea in cell phones. Part of the table may extend past the screen (especially in portrait view).
Without
nowrap
, as it appears in a browser:
Wikitext
{|
class
"wikitable sortable"
|-
scope
col
Episode
scope
col
Date
scope
col
Summary
|-
"The Journey Begins"
January 1, 2010
|{{
lorem ipsum
}}
...
|}
Produces
Episode
Date
Summary
"The Journey Begins"
January 1, 2010
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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
With
nowrap
, on both the Episode and Date columns, as it appears in a browser:
Wikitext
{|
class
"wikitable sortable"
|-
scope
col
Episode
scope
col
Date
scope
col
Summary
|-
style
"white-space: nowrap;"
"The Journey Begins"
style
"white-space: nowrap;"
January 1, 2010
|{{
lorem ipsum
}}
...
|}
Produces
Episode
Date
Summary
"The Journey Begins"
January 1, 2010
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. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
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.
{|
|+
The table's caption
|-
row
styling
goes
here
row code goes here
|}
Row style
संपादित करें
अधिक जानकारी:
#Height
और
#Setting borders
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:
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
Note that the row also contains an
id
attribute; this will be explained later in the section about
linking directly to a row
Row headers
संपादित करें
Note that 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. Note that the data cell text is bolded, and the data cell backgrounds are the same shade of gray as the column and row headers.
Wikitext
{|
class
wikitable
|+
The table's caption
Column 1
!!
Column 2
!!
Column 3
|-
Row header 1
||
Cell 2
||
Cell 3
|-
Row header A
||
Cell B
||
Cell C
|}
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
{|
class
wikitable
|+
The table's caption
Column 1
!!
Column 2
!!
Column 3
|-
Row header 1
Cell 2
||
Cell 3
|-
Row header A
Cell B
||
Cell C
|}
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:
Static row numbers
Row numbers
Link directly to a row
संपादित करें
साँचा: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!)
Row template
संपादित करें
adding a dynamic row number as a table column के लिए,
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 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
{|
class
"wikitable sortable"
|-
scope
col
scope
col
scope
col
a/b
{{
Help
Table/example row template
50
200
}}
{{
Help
Table/example row template
11
}}
{{
Help
Table/example row template
1000
81
}}
|}
Produces
a/b
सहायता:Table/example row template
सहायता:Table/example row template
सहायता:Table/example row template
Conditional table row
संपादित करें
मुख्य पृष्ठ:
Wikipedia:Conditional tables
For a conditional row in a table, we can have:
Wikitext
{|
class
wikitable
{{
#if
|{{
}}
! scope=row
{{
}}
row one, column one
{{
}}
row one, column two
}}
{{
#if
|{{
}}
! scope=row
{{
}}
row two, column one
{{
}}
row two, column two
}}
|-
scope=row {{!}} row three, column one
row three, column two
|}
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
{|
class
wikitable
{{
#if
|{{
}}
! scope=row
{{
}}
row one, column one
{{
}}
row one, column two
}}
{{
#if
|{{
}}
! scope=row
{{
}}
row two, column one
{{
}}
row two, column two
}}
|-
scope=row {{!}} row three, column one
row three, column two
|}
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
{|
style
"color: white;"
|-
style
"background-color: red;"
cell1
style
"width: 300px; background: blue;"
cell2
style
"background-color: green;"
cell3
|}
Produces
cell1
cell2
cell3
Vertical alignment in cells
संपादित करें
ये भी देखें:
Help:Table/Advanced §
Horizontal alignment in cells
Note:
The
valign=...
attribute is
deprecated
and MediaWiki may stop using it. See:
Help:HTML in wikitext#Tables
Note:
Use
Vertical align rows
to align all rows 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
of
text
No alignment
Top-aligned
Middle-aligned
Bottom-aligned
Relevant wikitext:
|style=vertical-align:top |Top-aligned
|style=vertical-align:middle |Middle-aligned
|style=vertical-align:bottom |Bottom-aligned
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
{|
class
wikitable
style
width:400px
|-
style
vertical-align:top
scope
row
style
width:10%
Row header
style
width:70%
A longer piece ...
style
width:20%
Short text
|}
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.
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 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
{|
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
}}
(Top and Bottom: 3em. Left and Right: 5%)
|-
style
"padding: 3em 4em 5%;"
code
style="padding: 3em 4em 5%;"
code
{{
space
}}
(Top: 3em. Left and Right: 4em. Bottom: 5%)
|-
style
"padding: 3%;"
code
style="padding: 3%;"
code
{{
space
}}
(Top, Right, Bottom, and Left: all 3%)
|-
style
"padding: 1em 20px 8% 9em;"
code
style="padding: 1em 20px 8% 9em;"
code
{{
space
}}
(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 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
{|
style
"border:1px solid black"
|-
Cell
||
Cell
|-
Cell
||
Cell
|}
Produces
Cell
Cell
Cell
Cell
Using
cellpadding=10
Wikitext
{|
cellpadding
10;
style
"border:1px solid black"
|-
Cell
||
Cell
|-
Cell
||
Cell
|}
Produces
Cell
Cell
Cell
Cell
Using
cellpadding=0
Wikitext
{|
cellpadding
0;
style
"border:1px solid black"
|-
Cell
||
Cell
|-
Cell
||
Cell
|}
Produces
Cell
Cell
Cell
Cell
Using
cellpadding=0
and
cellspacing=0
Wikitext
{|
cellpadding
0;
cellspacing
0;
style
"border:1px solid black"
|-
Cell
||
Cell
|-
Cell
||
Cell
|}
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
{|
style
"border-spacing: 2px; border: 1px solid darkgray;"
style
"width: 140px;"
Left
style
"width: 150px;"
Center
style
"width: 130px;"
Right
|-
style
"text-align: center;"
style
"border: 1px solid blue;"
[[
File
Starred.svg
120px
]]
style
"border: 1px solid #777777;"
[[
File
Star full.svg
120px
]]
style
"border: 1px solid #22AA55;"
[[
File
Stargreen.svg
120px
]]
|-
style
"text-align: center;"
Red star
||
Orange star
||
Green star
|}
Produces
Left
Center
Right
Red star
Orange star
Green star
Note that 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
{|
style
"border-top: solid;"style="border-top: solid;"
|-
style
"border-top: solid 2px red; border-right: dashed 3px green; border-bottom: double 5px blue; border-left: dotted 6px yellow;"
|<
pre
border-top: solid 2px red;
border-right: dashed 3px green;
border-bottom: double 5px blue;
border-left: dotted 6px yellow;
pre
|}
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
'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
{|
class
wikitable
|-
Top_Left
style
"border-style: solid solid none none;"
Top_Center
Top_Right
|-
style
"border-style: none none solid solid;"
Middle_Left
style
"border-style: none none none none;"
Middle_Center
style
"border-style: solid solid none none;"
Middle_Right
|-
Bottom_Left
style
"border-style: none none solid solid;"
Bottom_Center
Bottom_Right
|}
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
{|
class
wikitable
|-
Top_Left
||
Top_Center
||
Top_Right
|-
Middle_Left
style
"border-style: none none none none;"
Middle_Center
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
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
{|
class
wikitable
|-
Top_Left
||
Top_Center
||
Top_Right
|-
Middle_Left
style
"border-style: none none none none;"
Middle_Center
style
"border-style: none none none none;"
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
{| class="wikitable" style="border: none;"
Note that replacing
{| class="wikitable"
with
{| 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
single
cell border between two adjacent cells rather than remove
two
cell borders.
Table cell templates
संपादित करें
ये भी देखें:
Template:Shade
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
No
नहीं
No
Dunno
N/A
N/A
N/A
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:
div
class
"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.
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
{|
class
wikitable
{{diagonal split header|From|To}}
Solid
!!
Liquid
!!
Gas
|-
Solid
Solid-solid transformation
||
Melting
||
Sublimation
|-
Liquid
Freezing
||
{{
sdash
}}
||
Boiling/evaporation
|-
Gas
Deposition
||
Condensation
||
{{
sdash
}}
|}
Produces
To
From
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
{|
class
wikitable
style
"border: none; background: none;"
colspan
rowspan
style
"border: none; background: none;"
[[File:Pfeil_SO.svg |none|link=|20px]]
colspan
To
|-
Solid
!!
Liquid
!!
Gas
|-
rowspan
From
Solid
Solid–solid transformation
||
Melting
||
Sublimation
|-
Liquid
Freezing
||
{{
sdash
}}
||
Boiling/evaporation
|-
Gas
Deposition
||
Condensation
||
{{
sdash
}}
|}
Produces
To
Solid
Liquid
Gas
From
Solid
Solid–solid transformation
Melting
Sublimation
Liquid
Freezing
Boiling/evaporation
Gas
Deposition
Condensation
Note that the removal of the link on an image is
dependent on it being purely decorative (as it will be ignored by assistive devices)
Wikitext
{|
class
wikitable
style
"border: none; background: none;"
scope
col
Year
scope
col
Size
rowspan
style
"border: none; background: none;"
scope
col
Year
scope
col
Size
rowspan
style
"border: none; background: none;"
scope
col
Year
scope
col
Size
|-
1990
||
1000
br
(est)
||
2000
||
1357
||
2010
||
1776
|-
1991
||
1010
||
2001
||
1471
||
2011
||
1888
|-
colspan
style
"text-align: center;"
colspan
style
"text-align: center;"
colspan
style
"text-align: center;"
|-
1999
||
1234
||
2009
||
1616
||
2019
||
1997
br
(est)
|}
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.
(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.
Wikitext
{|
class
wikitable
|-
''
formatting
''
P|i|p|e|
e|l|l|2|
|-
''
formatting
''
P|i|p|e
||
''
formatting
''
C|e|l|l|2|
|-
||
P|i|p|e|s
||
e|l|l|2|
|}
Produces
P|i|p|e|
e|l|l|2|
P|i|p|e
C|e|l|l|2|
P|i|p|e|s
e|l|l|2|
The third and later pipe characters will render, but to display two
adjacent
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
#124;
or
#x7C;
. Each line of cell code in the following table has one wikicode pipe.
Displaying adjacent pipes
Wikitext
{|
class
wikitable
|-
|<
nowiki
nowiki
Pipes34:
nowiki
||
nowiki
|-
|
Pipes34:
||
|}
Produces
Pipes34:
||
Pipes34:
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 not
escape
the second pipe, as
#124 and
nowiki
nowiki
did above:
Common mechanisms that do not work in tables.
Wikitext
{|
class
wikitable
|-
|<
nowiki
/>
| Pipe3:|
|-
Pipe2:
{{
}}
Pipe3:
{{
}}
|}
Produces
Pipe3:|
Pipe3:
Classes
संपादित करें
साँचा:See Also
There are several other
CSS
classes, besides the basic
class=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 in
MediaWiki:Common.css
(for example, on this and some other projects there is or was the class wikitable, later moved to
shared.css
separately per skin in
MediaWiki:Monobook.css
etc.
individually on one wiki in a user subpage
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:
Wikitext
{|
style
"border-spacing: 2px;"
|+
Multiplication table
|-
scope
col
×
scope
col
scope
col
scope
col
|-
scope
row
||
||
|-
scope
row
||
||
|}
Produces
Multiplication table
becomes this:
Wikitext
{|
class
wikitable
|+
Multiplication table
|-
scope
col
×
scope
col
scope
col
scope
col
|-
scope
row
||
||
|-
scope
row
||
||
|}
Produces
Multiplication table
simply by replacing inline CSS for the table by
class=wikitable
. This is because the
wikitable
class in
MediaWiki:Common.css
contains a number of
table.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:
Wikitext
{|
class
wikitable
style
"font-style: italic; font-size: 120%; border: 3px dashed red;"
|+
Multiplication table
|-
scope
col
×
scope
col
scope
col
scope
col
|-
scope
row
||
||
|-
scope
row
||
||
|}
Produces
Multiplication table
Notice that the table retains the gray background of the
wikitable
class, and the headers are still bold and centered. But now the text formatting has been overridden by the local
style=
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.
Indenting tables
संपादित करें
While tables should not normally be indented, when their surrounding paragraphs are also indented, you can indent tables using
margin-left
To achieve the same indentation as a colon, use
margin-left:1.6em
Wikitext
{|
class
"wikitable"
style
"margin-left:1.6em;"
|-
Header 1
Header 2
|-
row 1, cell 1
row 1, cell 2
|-
row 2, cell 1
row 2, cell 2
|}
Produces
Header 1
Header 2
row 1, cell 1
row 1, cell 2
row 2, cell 1
row 2, cell 2
Tables on talk pages
संपादित करें
Note:
Concerning colons on talk pages, see comments
here
from a blind editor (Graham87) who uses a
screen reader
. Scroll down to the table comments. It also verifies the previous section above.
Note that indentation applied to only the
first line
of the table wikitext (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.
Public domain image tables
संपादित करें
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.
See
Commons: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, and
upload
it to the
Wikimedia Commons
. Add
{{PD-chart}}
to it.
See also
संपादित करें
Note:
See
top of page
for more links to table help pages.
Category:Wikipedia tables
: lists even more table help pages.
Help:Introduction to tables with Wiki Markup
Wikipedia:Manual of Style/Tables
: the Manual of Style indicates best practices for tables.
Wikipedia:Table dos and don'ts
: a quick guide to the Manual of Style for tables.
mw:Help:Tables
User:Dcljr/Tables
: table tutorials.
Table (HTML)
: tags used for HTML tables.
Category:Lists
: vast category tree of pages with tables.
Templates
संपादित करें
Category:Table templates
: templates that affect or use tables.
Category:Multi-column templates
: templates for using columns without tables.
Category:Chart, diagram and graph templates
Category:Chart, diagram and graph formatting and function templates
Category:Wikipedia template editors
List to table
: template and its maintenance category:
Category:Articles requiring tables
Horizontal TOC
: good for country lists in table format.
Diagonal split header
: for identifying both rows and columns, in a diagonally split top-left cell (also:
Diagonal split header 2
Table
: template for specifying table CSS classes such as "wikitable" and "collapsible"
Alternating rows table
Screen reader-only
: for a table caption directly below a section heading, or table description.
Aligned table
: for specifying tables as a template, allowing inclusion in other templates and areas where table syntax is problematic.
Examples:
Chess diagram
: chess board template.
Goban
: Go board template.
Some commonly used table templates using
TemplateStyles
Sticky header
: makes top header rows sticky.
Sticky table start
and
Sticky table end
: makes top and side header rows sticky, and puts table in scroll box.
Sort under
: puts sorting arrows below headers.
Mw-datatable
: rows highlighted via mouse hover. White background otherwise.
Table alignment
: aligns text in selected columns.
Static row numbers
: adds column of fixed row numbers.
Notes
संपादित करें
Collapsible tables: the class
collapsible
is available, but no longer recommended; use
mw-collapsible
instead. See
here
for further details.
border: none;
to avoid an empty column in tables narrower than the browser window in Android Chrome.
In
style="padding: 3em 4em 5%;"
, the value
4em
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. In
style="padding: 3em 5%;"
, the value
3em
is used for both the "top" and "bottom" padding while the value
5%
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 to
style="padding: 1em 20px 8% 9em;"
, and
style="padding: 3%;"
A simplified version of
Template:Table_of_phase_transitions
Applying
background: none
to the entire table will, perhaps predictably, subtly alter its color palette.
External links
संपादित करें
Table tools
at
toolhub.wikimedia.org
Convert range of cells from Excel to wiki text
Excel2Wiki - copy/paste Excel-to-Wiki converter
at
Toolforge
(in-browser copy and paste)
VBA-Macro for EXCEL tableconversion
(macro requiring quick installation)
Tab2Wiki
at
Toolforge
(in-browser copy and paste)
Tables Generator
, a WYSIWYG table generator for Mediawiki markup
Wikitable Editor
, a table editor of wiki code that outputs visual preview quickly
HTML2Wiki Converter
at
toolforge.org
HTML-WikiConverter
, various versions and languages
pywikipediabot
, can convert HTML tables to wiki
Table of CSS color names and HEX codes
Phabricator request
for floating table headers
tabulate
, Python module for converting data structures to wiki table markup
wikitables
, Python module for reading wiki table markup
H63: Using the scope attribute to associate header cells and data cells in data tables | Techniques for WCAG 2.0
Tables | Usability & Web Accessibility
Yale University
Tables with Multi-Level Headers
Web Accessibility Initiative
W3C
. Also shows alternatives to complex tables.
Wikimedia sister projects
संपादित करें
यह विकीपीडिया पेज है
यह विकीपीडिया पेज है
mw:Help:Tables
: MediaWiki help page on tables.
mw:Help:Sortable tables
: MediaWiki help page on sortable tables.
mw:Table background colors
: MediaWiki help page on table background colors.
Commons:Chart and graph resources
: Chart and graph resources at Commons
Commons:Convert tables and charts to wiki code or image files
: includes information on converting table markup.
Commons:Template:SVG Chart
. Convert list/table to
SVG
line chart
Commons.
Convert US list/table to state-by-state SVG map
साँचा:Introduction/navigation
साँचा:Help navigation
साँचा:Wikipedia technical help
" से प्राप्त
श्रेणियाँ
Pages with TemplateStyles errors
Wikipedia tables
Wikipedia how-to
Wikipedia text help
छुपी हुई श्रेणी:
Wikipedia shortcut box first parameter needs fixing
सहायता
तालिका
विषय जोड़ें
US