Template:Navbox
Warning | This template is used on approximately 2,950,000 pages, or roughly 244813% 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. |
File:Handheld devices no.svg | This template does not display in the mobile view of Wikipedia; it is desktop only. Read the documentation for an explanation. |
File:Lua-Logo.svg | This template uses Lua: |
Navbox suite |
---|
|
Related pages |
---|
This template allows a navigational template to be set up relatively quickly by supplying it with one or more lists of links. It comes equipped with default styles that should work for most navigational templates. Changing the default styles is possible, but not recommended. Using this template, or one of its "Navbox suite" sister templates, is highly recommended for standardization of navigational templates, and for ease of use.
Templates using the classes class=navbox
({{navbox}}) or class=nomobile
({{sidebar}}) are not displayed on the mobile web site of English Wikipedia. Mobile page views account for approximately 68% of all page views (90-day average as of September 2024[update]). Briefly, these templates are not included because they are 1) not well designed for mobile, and 2) because they significantly increase page sizes—bad for mobile downloads—in a way that is not useful for the mobile use case. You can review/watch phab:T124168 for further discussion.
Usage
Please remove the parameters that are left blank.
<syntaxhighlight lang="wikitext" style="overflow: auto;"></syntaxhighlight>
Parameter list
The navbox uses lowercase parameter names, as shown in the box (above). The required name and title will create a one-line box if other parameters are omitted.
Notice "group1" (etc.) is optional, as are sections named "above/below".
The basic and most common parameters are as follows (see below for the full list):
name
– the name (Wikipedia location) of the template.title
– text in the title bar, such as: [[Widget stuff]].listclass
– a CSS class for the list cells, usuallyhlist
for horizontal lists. Alternatively, use bodyclass for the whole box.state
– controls when a navbox is expanded or collapsed.titlestyle
– a CSS style for the title-bar, such as:background: gray;
groupstyle
– a CSS style for the group-cells, such as:background: #eee;
above
– text to appear above the group/list section (could be a list of overall wikilinks).image
– an optional right-side image, coded as the whole image, such as:[[File:XX.jpg|80px|alt=Alternate text]]
- Note that most of such images don't comply with MOS:DECOR and should be removed at sight.
imageleft
– an optional left-side image (code the same as the "image" parameter).groupn
– the left-side text before list-n (if group-n omitted, list-n extends to the left edge of the box, and defaults totext-align:center
styling).listn
– text listing wikilinks using a wikilist format.below
– optional text to appear below the group/list section.
Parameter descriptions
The following is a complete list of parameters for using {{Navbox}}. In most cases, the only required parameters are name
, title
, and list1
, though child navboxes do not even require those to be set.
{{Navbox}} shares numerous common parameter names with its sister templates, {{Navbox with columns}} and {{Navbox with collapsible groups}}, for consistency and ease of use. Parameters marked with an asterisk (*) are common to all three master templates.
Setup parameters
- name*
- The name of the template, which is needed for the "V • T • E" ("View • Talk • Edit") links to work properly on all pages where the template is used. You can enter
{{subst:PAGENAME}}
for this value as a shortcut. The name parameter is only mandatory if atitle
is specified, and theborder
parameter is not set, and thenavbar
parameter is not used to disable the navbar. - state* [
autocollapse, collapsed, expanded, plain, off
] -
- Defaults to
autocollapse
. A navbox withautocollapse
will start out collapsed if there are two or more collapsible elements on the same page. Otherwise, the navbox will be expanded. For the technically minded, see MediaWiki:Common.js (search for "autocollapse"). - If set to
collapsed
, the navbox will always start out in a collapsed state. - If set to
expanded
, the navbox will always start out in an expanded state. - If set to
plain
, the navbox will always be expanded with no [hide] link on the right, and the title will remain centered (by using padding to offset the V • T • E links). - If set to
off
, the navbox will always be expanded with no [hide] link on the right, but no padding will be used to keep the title centered. This is for advanced use only; the "plain" option should suffice for most applications where the [show]/[hide] button needs to be hidden.
- Defaults to
- To show the box when standalone (non-included) but then auto-hide contents when in an article, put "expanded" inside
<noinclude>...</noinclude>
tags. This setting will force the box to be visible when standalone (even when followed by other boxes), displaying "[hide]", but then it will auto-collapse the box when stacked inside an article:| state =
<noinclude>expanded</noinclude>
- Often times, editors will want a default initial state for a navbox, which may be overridden in an article. Here is the trick to do this:
- In your intermediate template, create a parameter also named "state" as a pass-through like this:
| state = {{{state<includeonly>|your_desired_initial_state</includeonly>}}}
- The
<includeonly>
|
will make the template expanded when viewing the template page by itself.- Example 1: {{Peso}} with autocollapse as the default initial state. Catalan peseta transcludes it and has only one navbox; thus, the peso navbox shows. Chilean peso has more than two navboxes; thus, the peso navbox collapses.
- Example 2: {{Historical currencies of Hungary}} with expanded as the default initial state, as such:
| state = {{{state<includeonly>|expanded</includeonly>}}}
All transcluding articles show the content by default, unless there is a hypothetical article that specifies{{templatename|state=collapsed}}
when transcluding. - Example 3: {{Tourism}} with collapsed as the default initial state, as such:
| state = {{{state<includeonly>|collapsed</includeonly>}}}
All transcluding articles will show the template as collapsed by default, but the template will still be uncollapsed when displayed on its own page.
- The template {{Collapsible option}} explains how to use the
state
parameter. It can be added to a<noinclude>...</noinclude>
section after the template definition or to the instructions on the {{documentation subpage}}.
- In your intermediate template, create a parameter also named "state" as a pass-through like this:
- navbar*
- If set to
plain
, the V • T • E links on the left side of the titlebar will not be displayed, and padding will be automatically used to keep the title centered. Useoff
to remove the V • T • E links, but not apply padding (this is for advanced use only; the "plain" option should suffice for most applications where a navbar is not desired). It is highly recommended that one not hide the navbar, in order to make it easier for users to edit the template, and to keep a standard style across pages. - border*
- See later section on using navboxes within one another for examples and a more complete description. If set to
child
orsubgroup
, then the navbox can be used as a borderless child that fits snugly in another navbox. The border is hidden and there is no padding on the sides of the table, so it fits into the list area of its parent navbox. If set tonone
, then the border is hidden and padding is removed, and the navbox may be used as a child of another container (do not use thenone
option inside of another navbox; similarly, only use thechild
/subgroup
option inside of another navbox). If set to anything else (default), then a regular navbox is displayed with a 1px border. An alternate way to specify the border to be a subgroup style is like this (i.e. use the first unnamed parameter instead of the named border parameter): {{Navbox|child|...}}
Cells
- title*
- Text that appears centered in the top row of the table. It is usually the template's topic, i.e. a succinct description of the body contents. This should be a single line, but if a second line is needed, use
{{-}}
to ensure proper centering. This parameter is technically not mandatory, but using {{Navbox}} is rather pointless without a title. - above*
- A full-width cell displayed between the titlebar and first group/list, i.e. above the template's body (groups, lists and image). In a template without an image, above behaves in the same way as the list1 parameter without the group1 parameter.
- groupn*
- (i.e. group1, group2, etc.) If specified, text appears in a header cell displayed to the left of listn. If omitted, listn uses the full width of the table.
- listn*
- (i.e. list1, list2, etc.) The body of the template, usually a list of links. Format is inline, although the text can be entered on separate lines if the entire list is enclosed within
<div> </div>
. At least one list parameter is required; each additional list is displayed in a separate row of the table. Each listn may be preceded by a corresponding groupn parameter, if provided (see below). - Entries should be separated using a newline and an asterisk (*). If instead two asterisks are used, it provides nesting within the previous entry by enclosing the entry with brackets. Increasing the number of asterisks used increases the number of brackets around entries.
- Set to the keyword
child
orsubgroup
to denote that the list is using the inline #Child navboxes (does not work with {{Navbox with columns}} or {{Navbox with collapsible groups}}). - image*
- An image to be displayed in a cell below the title and to the right of the body (the groups/lists). For the image to display properly, the list1 parameter must be specified. The image parameter accepts standard wikicode for displaying an image, e.g.:
[[File:</nowiki><var>XX</var><nowiki>.jpg|80px|link=|alt=]]
nb: including "|right" will produce the usual left margin to provide separation from the list items and zebra striping. - Note that most of such images don't comply with MOS:DECOR and should be removed at sight. A rare example of a correct usage would be this one: a map shows (in green) the location of a region within the state of Kazakhstan, and this is consistently implemented for all state's regions.
- imageleft*
- An image to be displayed in a cell below the title and to the left of the body (lists). For the image to display properly, the list1 parameter must be specified and no groups can be specified. It accepts the same sort of parameter that image accepts.
- below*
- A full-width cell displayed below the template's body (groups, lists and image). In a template without an image, below behaves in the same way as the template's final listn parameter without a groupn parameter. For an example of the below parameter in use, see this version of {{Lists of the provinces and territories of Canada}}. {{icon}} is often used for non-article links, for example
{{icon|category}} [[:Category:name|Category]]
.
Style parameters
Styles are generally advised against, to maintain consistency among templates and pages in Wikipedia; but the option to modify styles is given.
- bodystyle*
- Specifies CSS styles to apply to the template body. This option should be used sparingly as it can lead to visual inconsistencies. Examples:
bodystyle = background: #nnnnnn;
bodystyle = width: N [em/%/px or width: auto];
bodystyle = float: [left/right/none];
bodystyle = clear: [right/left/both/none];
- basestyle*
- CSS styles to apply to the title, above, below, and group cells all at once. The styles are not applied to list cells. This is convenient for easily changing the basic color of the navbox without having to repeat the style specifications for the different parts of the navbox. Example:
basestyle = background: lightskyblue;
- titlestyle*
- CSS styles to apply to title, most often the titlebar's background color:
titlestyle = background: #nnnnnn;
titlestyle = background: name;
titlestyle = background: none;
— for no background color
- groupstyle*
- CSS styles to apply to the groupN cells. This option overrides any styles that are applied to the entire table. Examples:
groupstyle = background: #nnnnnn;
groupstyle = text-align: [left/center/right];
groupstyle = vertical-align: [top/middle/bottom];
- groupnstyle*
- CSS styles to apply to a specific group, in addition to any styles specified by the groupstyle parameter. This parameter should only be used when absolutely necessary in order to maintain standardization and simplicity. Example:
group3style = background: red; color: white;
- groupwidth
- A number and unit specifying a uniform width for the group cells, in cases where little content in the list cells may cause group cells to be too wide. No default. However, may be overridden by the group(n)style parameter. Example:
groupwidth = 9em
- liststyle*
- CSS styles to apply to all lists. Overruled by the oddstyle and evenstyle parameters (if specified) hereafter. When using backgound colors in the navbox, see the note hereafter.
- listnstyle*
- CSS styles to apply to a specific list, in addition to any styles specified by the liststyle parameter. This parameter should only be used when absolutely necessary in order to maintain standardization and simplicity. Example:
list5style = background: #ddddff;
- listpadding*
- A number and unit specifying the padding in each list cell. The list cells come equipped with a default padding of 0.25em on the left and right, and 0 on the top and bottom. Due to complex technical reasons, simply setting "liststyle = padding: 0.5em;" (or any other padding setting) will not work. Examples:
listpadding = 0.5em 0;
(sets 0.5em padding for the top/bottom, and 0 padding for the left/right.)listpadding = 0;
(removes all list padding.)
- oddstyle
- evenstyle
- Applies to odd/even list numbers. Overrules styles defined by liststyle. The default behavior is to add striped colors (white and gray) to odd/even rows, respectively, in order to improve readability. These should not be changed except in extraordinary circumstances.
- evenodd
[swap, even, odd, off]
- If set to
swap
, then the automatic striping of even and odd rows is reversed. Normally, even rows get a light gray background for striping; when this parameter is used, the odd rows receive the gray striping instead of the even rows. Setting toeven
orodd
sets all rows to have that striping color. Setting tooff
disables automatic row striping. - abovestyle*
- belowstyle*
- CSS styles to apply to the top cell (specified via the above parameter) and bottom cell (specified via the below parameter). Typically used to set background color or text alignment:
abovestyle = background: #nnnnnn;
abovestyle = text-align: [left/center/right];
belowstyle = background: #nnnnnn;
belowstyle = text-align: [left/center/right];
- imagestyle*
- imageleftstyle*
- CSS styles to apply to the cells where the image/imageleft sits. These styles should only be used in exceptional circumstances, usually to fix width problems if the width of groups is set and the width of the image cell grows too large. Example:
imagestyle = width:5em;
Default styles
The style settings listed here are those that editors using the navbox change most often. The other more complex style settings were left out of this list to keep it simple. Most styles are set in MediaWiki:Common.css.
<syntaxhighlight lang="css">
bodystyle = background: #fdfdfd; width: 100%; vertical-align: middle;
titlestyle = background: #ccccff; padding-left: 1em; padding-right: 1em; text-align: center;
abovestyle = background: #ddddff; padding-left: 1em; padding-right: 1em; text-align: center;
belowstyle = background: #ddddff; padding-left: 1em; padding-right: 1em; text-align: center;
groupstyle = background: #ddddff; padding-left: 1em; padding-right: 1em; text-align: right;
liststyle = background: transparent; text-align: left/center;
oddstyle = background: transparent;
evenstyle = background: #f7f7f7;
</syntaxhighlight>
Since liststyle and oddstyle are transparent, odd lists have the color of the bodystyle, which defaults to #fdfdfd (white with a hint of gray). A list defaults to text-align: left;
if it has a group, if not it defaults to text-align: center;
. Since only bodystyle has a vertical-align all the others inherit its vertical-align: middle;
.
Advanced parameters
- bodyclass
- aboveclass
- groupclass
- listclass
- belowclass
- This enables attaching a CSS class to group or list cells. The most common use for listclass is to give it the
hlist
class that will cause lists to render horizontally. All these parameters accept thehlist
class, but if more than one parameter is used forhlist
, use|bodyclass=hlist
instead. - {{navbox}} automatically adds the class
nowraplinks
which can be overridden, for example with
.|listclass=wraplinks
- innerstyle
- A very advanced parameter to be used only for advanced meta-templates employing the navbox. Internally, the navbox uses an outer table to draw the border, and then an inner table for everything else (title/above/groups/lists/below/images, etc.). The style/bodystyle parameter sets the style for the outer table, which the inner table inherits, but in advanced cases (meta-templates) it may be necessary to directly set the style for the inner table. This parameter provides access to that inner table so styles can be applied. Use at your own risk.
- nowrapitems
- Setting
|nowrapitems=yes
applies nowrap to each line in a list item, and to anyabove
orbelow
item. - orphan
- Setting
|orphan=yes
in a child navbox fixes odd/even striping and removes Category:Navbox orphans.
Microformats
- bodyclass
- This parameter is inserted into the "class" attribute for the navbox as a whole.
- titleclass
- This parameter is inserted into the "class" attribute for the navbox's title caption.
This template supports the addition of microformat information. This is done by adding "class" attributes to various data cells, indicating what kind of information is contained within. To flag a navbox as containing hCard information about a person, for example, add the following parameter:
| bodyclass = vcard
and
| titleclass = fn
or (for example):
| title = The books of <span class="fn">[[Iain Banks]]</span>
...and so forth.
See Wikipedia:WikiProject Microformats for more information on adding microformat information to Wikipedia, and microformat for more information on microformats in general.
Layout of table
Without image, above and below
Table generated by {{Navbox}} without image, above and below parameters (gray list background color added for illustration only):
With image, above and below
Table generated by {{Navbox}} with image, above and below parameters (gray list background color added for illustration only):
With image and without groups
Table generated by {{Navbox}} with image, imageleft, lists, and without groups, above, below (gray list background color added for illustration only):
Examples
No image
<syntaxhighlight lang="wikitext" style="overflow: auto;">
</syntaxhighlight>
It is possible to place multiple navboxes within a single border. These can either be specified inline or by using a nested navbox template, although the latter method can result in a signifcantly large post-expand include size.
To specify child navboxes inline, set the listn
parameter to child
or subgroup
. Elements of the child navbox can be specified by prepending childn_
, subgroupn_
, or just n_
to the parameter names (e.g. 1_list1
). Child navboxes can be nested by adding an additional prefix (e.g. 1_1_list1
). The basic code for doing this is as follows (which adds a subgroup for the first group/list area):
{{Navbox | name = {{subst:PAGENAME}} | title = Title | group1 = [optional] | list1 = child | 1_title = [optional] | 1_group1 = [optional] | 1_list1 = child | 1_1_title = [optional] | 1_1_group1 = [optional] | 1_1_list1 = ...list contents... ... ... }}
To specify child navboxes using a nested template, use "child" as the first parameter or set the border parameter. The basic code for doing this is as follows (which adds a subgroup for the first group/list area):
{{Navbox | name = {{subst:PAGENAME}} | title = Title | group1 = [optional] | list1 = {{Navbox|child ...child navbox parameters... }} ... }}
Subgroups example
This example shows two subgroups and a sub-subgroup created using child
and subgroup
keywords (both are interchangible). The striping is alternated automatically. To remove the striping altogether, you can set childn_liststyle = background:transparent;
in each.
Multiple show/hides in a single container
The example below is generated using a regular navbox for the main container, then its list1, list2, and list3 parameters each contain the child
keyword. The view (v), talk (t), edit (e) navbar links are hidden automatically because the "child" or "subgroup" keyword is used, so using navbar = plain
for each of them is not necessary. The code <syntaxhighlight lang="wikitext" inline>N_state = collapsed</syntaxhighlight> is used to replicate the <syntaxhighlight lang="wikitext" inline>abbrN = ABBREVIATION</syntaxhighlight> functionality of {{Navbox with collapsible groups}}.
This navbox template works in conjunction with two other templates: {{Navbox with columns}} and {{Navbox with collapsible groups}}. All three of these templates share common parameters for consistency and ease of use (such parameters are marked with an asterisk (*) in the parameter descriptions list hereinbefore). Most importantly, each template can be used as a child of one another (by using the |border=child
parameter, or by specifying the first unnamed parameter to be child
. For example: {{Navbox|child ...}}
, {{Navbox with columns|child ...}}
or {{Navbox with collapsible groups|child ...}}
.)
Technical details
- The Template:Navbar. If you have a question about them, it is probably best to ask at Template talk:Navbar. links are produced by
- The 2px wide border between groups and lists is drawn using the border-left property of the list cell. Thus, if you wish to change the background color of the template (for example
bodystyle = background:purple;
), then you'll need to make the border-left-color match the background color (i.e.liststyle = border-left-color: purple;
). If you wish to have a border around each list cell, then the 2px border between the list cells and group cells will disappear; you'll have to come up with your own solution. - Adjacent navboxes have only a 1 pixel border between them. If you set the top or bottom margin of
style/bodystyle
, then this will not work. - The default margin-left and margin-right of the outer navbox table are set to "auto;". If you wish to use navbox as a float, you need to manually set the margin-left and margin-right values, because the auto margins interfere with the float option. For example, add the following code to use the navbox as a float:
bodystyle = width: 22em; float: right; margin-left: 1em; margin-right: 0;
- This template calls {{#invoke:Navbox|navbox}}, which can double the post-expand include size when navbox templates are used on pages. When child navboxes are used by nesting templates, this can cause the size to quadruple or more. To reduce the include size, in addition to specifying child navboxes inline instead of nesting templates, you can invoke the module directly, e.g.:
<syntaxhighlight lang="wikitext"> Lua error in Module:Navbar at line 58: Invalid title {{subst:PAGENAME}}. </syntaxhighlight>
Copying to other projects or wikis
If you are trying to copy {{Navbox}} to your local wiki, there are several other things that must be installed or copied over as well:
- The Scribunto and TemplateStyles extensions must be installed.
- Module:Navbox and its module and TemplateStyles dependencies, listed at Module:Navbox/doc
- Optionally, the
Add support to mw-collapsible for autocollapse, innercollapse and outercollapse
script from MediaWiki:Common.js may be copied, if autocollapsing is desired.
TemplateData
TemplateData for Navbox
Creates a navigational box for links to other pages. Does not display in mobile.
Parameter | Description | Type | Status | |
---|---|---|---|---|
Name | name | The name of the template. Needed for "View • Talk • Edit" links to work properly.
| String | suggested |
Title | title | Text in the title bar; centered in the top row of the table. Usually the template's topic.
| Unknown | suggested |
Group 1 | group1 | If specified, text appears in a header cell displayed to the left of list 1. If omitted, list 1 uses the full width of the table. | Unknown | suggested |
List 1 | list1 | Body of the template; usually a list of links. Format is inline. At least one list parameter is required; each additional list is displayed in a separate row of the table. Each listn may be preceded by a corresponding groupn parameter. Entries should be separated using a newline and an asterisk. If two asterisks are used, it provides nesting within the previous entry with brackets. | Unknown | required |
List class | listclass | CSS class for the list cells, usually hlist for horizontal lists. Alternatively, use bodyclass for the whole box.
| String | optional |
State | state | Controls when a navbox is expanded or collapsed
| Unknown | suggested |
Above | above | Full-width cell displayed between the titlebar and first group/list, i.e. above the template's body (groups, lists and image) | String | suggested |
Below | below | Full-width cell displayed below the template's body. | Unknown | suggested |
Image | image | Image to be displayed in a cell below the title and to the right of the body
| File | suggested |
group2 | group2 | no description | Unknown | suggested |
list2 | list2 | no description | Unknown | suggested |
group3 | group3 | no description | Unknown | suggested |
list3 | list3 | no description | Unknown | suggested |
group4 | group4 | no description | Unknown | optional |
list4 | list4 | no description | Unknown | optional |
Image left | imageleft | Image to be displayed in a cell below the title and to the left of the body. For the image to display properly, list1 parameter must be specified and no groups can be specified.
| File | optional |
Navbar status | navbar | no description
| String | optional |
Border status | border | no description
| String | optional |
bodystyle | bodystyle | no description | Unknown | optional |
basestyle | basestyle | no description | Unknown | optional |
titlestyle | titlestyle | no description | Unknown | optional |
groupstyle | groupstyle | no description | Unknown | optional |
liststyle | liststyle | no description | Unknown | optional |
group1style | group1style | no description | Unknown | optional |
list1style | list1style | no description | Unknown | optional |
groupwidth | groupwidth | no description | Unknown | optional |
listpadding | listpadding | no description | Unknown | optional |
oddstyle | oddstyle | no description | Unknown | optional |
evenstyle | evenstyle | no description | Unknown | optional |
evenodd | evenodd | no description
| Unknown | optional |
abovestyle | abovestyle | no description | Unknown | optional |
belowstyle | belowstyle | no description | Unknown | optional |
imagestyle | imagestyle | no description | Unknown | optional |
imageleftstyle | imageleftstyle | no description | Unknown | optional |
See also
- {{Navboxes}} — groups several navigation boxes together.
- {{Nobold}} — To display text at normal font-weight within a context where the default font-weight is bold, e.g. header cells in tables.
- {{Sidebar}} — Vertically-aligned navigation templates.
- {{Navbox documentation}} — Shows the standard documentation using {{Documentation}}.
- Template:Navbox/testcases — For additional examples of template code.
- Wikipedia:Line-break handling — The how-to guide about how to handle word wraps (line breaks) on Wikipedia, such as the wrapping of the link lists used in navboxes.
- Wikipedia:Template documentation — Guideline to creating the accompanying documentation
- {{Nowrap begin}}, {{·}} and {{•}} are deprecated in favor of the
hlist
class for formatting lists. See Flatlist for a technical explanation of howhlist
works.
Tracking categories
- Category:Navbox orphans (10)
- Category:Navigational boxes without horizontal lists (0)
- Category:Navboxes using background colours (11)
- Category:Potentially illegible navboxes (0)
- Category:Navboxes using borders (0)
Template | Collapsible | Image | Groups | Style (body) parameter/s |
---|---|---|---|---|
{{Navbox}} | collapsible | Left/right of body | Yes | Yes |
{{Navbox with collapsible groups}} | collapsible | Left/right of body and/or in each list | Yes | Yes |
{{Navbox with columns}} | collapsible | Left/right of columns | No | Yes |
Type | CSS classes | JavaScript | Collapses when | Custom initial state |
Nesting |
---|---|---|---|---|---|
Collapsible tables | mw-collapsible | jQuery.makeCollapsible | 2 or more autocollapse on page | Yes | Yes |
- Pages with script errors
- Pages with broken file links
- Lua-based templates
- Sidebars with styles needing conversion
- Navigational boxes without horizontal lists
- Templates using TemplateData
- Navigational box metatemplates
- Templates generating microformats
- Templates that are not mobile friendly
- Collapse templates