Template:Center/doc
This is a documentation subpage for Template:Center It may contain usage information, categories and other content that is not part of the original template page. |
This template is used on 285,000+ pages, or roughly 98% of all pages. To avoid major disruption and server load, any changes should be tested in the template's /sandbox or /testcases subpages, or in your own user subpage. The tested changes can be added to this page in a single edit. Consider discussing changes on the talk page before implementing them. |
This utility template centers text inside an HTML <div>...</div>
box that is wrapped around the <span>...</span>
tags inside which is the text you supplied to the template's single, unnamed parameter, |1=
. The <span>...</span>
tags have 0.75em of padding on all sides and the <div>...</div>
box has margins of 1em set above and below while the left and right margins are automatically sized to be identical (the result of calculating (viewport width - div width) / 2
, which is the mechanism that actually centers the content on the page or inside whatever other smaller container it was placed in).
Usage
[edit source]- {{Center|1=Your text goes here|style=optional inline CSS declarations}}
The |style=
parameter is entirely optional and only intended to provide a way to overcome minor issues with text size and spacing. If used as intended, wrapped around text needing to be centered on the page, with any wikitext style desired applied outside the template, this template should be reliable and fairly versatile.
Example
[edit source]{{Center|1=You have not the power to bind me to either side of the page!}}
which produces:
Caveats
[edit source]While not required, it's good to cultivate the habit of prepending 1=
to the text you want centered, since that eliminates any chance of the template being broken by text that happens to have an equality sign (=
) already present in it. Absent that situation and a few exceedingly rare others, it is perfectly acceptable to call it in its simplest form, e.g. {{Center|Read this in the middle of the page.}}
.
Spacing
[edit source]The default padding and margin choices can be desirable in many cases as it sets off the text nicely from its surroundings, but that assumes it is the last (or only) text on a line—which can adversely affect wikitext using || separators in tables.
Text size
[edit source]It can also have undesirable 'enlarging' effects on the font used as a result of the double nested tag pairs, again, especially in tables. This is a good use for the style parameter; feeding it values of font-size: Xem;
, where X
is a decimal number whose default value is 1.0 (that represents the font size of the template's current output), can correct these issues. When X
< 1, e.g. font-size: 0.95em;
, the font size is reduced in proportion to the amount subtracted from 1 to achieve X
, in this example a reduction of 5%. The reverse holds true for values of X
that are > 1, if you need to enlarge the text instead.
TemplateData
[edit source]TemplateData for Center
Formatting template that centers text on the page or inside of whatever container the template is placed within; a drop-in replacement for the long-deprecated <center>...</center> tags of yore.
Parameter | Description | Type | Status | |
---|---|---|---|---|
Input text | 1 content text | The text you wished to appear centered wherever this template is placed
| String | required |
Inline CSS | style | Any extra inline CSS3 style definitions can be supplied to this parameter for inclusion in the <div>...</div> wrapper tags (don't forget to include the semicolon at the end of each one)
| Line | optional |