This is the template sandbox page for Template:Anchor (diff). See also the companion subpage for test cases. |
This template uses Lua: |
This template is used in system messages, and on approximately 85,000 pages. Changes to it can cause immediate changes to the Wikipedia user interface. To avoid major disruption, 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. Please discuss changes on the talk page before implementing them. Preview message: Transclusion count updated automatically (see documentation). |
This template is used by one or more bots.
If you intend to change this template in any significant way, move it or nominate it for deletion, please inform the bot operators. Thank you. The relevant bots are: User:Cewbot (BRFA). |
The template {{anchor}} inserts one or more invisible anchor names (HTML fragment identifiers) in a page.
The basic format is {{anchor|Anchor name}}
. To link to an anchor from within the same page, use [[#Anchor name|display text]]
. To link to an anchor from another page, use [[Article name#Anchor name|display text]]
. See Help:Link § Section linking (anchors) for more details.
Note that #Anchor name
, used by the MediaWiki software to (usually) direct users to sections within a page, is not a wikitext directive like #redirect
.
Anchors are most useful with sections, since links to a section will not work if a section is renamed. However, anchors can be used as needed anywhere in an article. The anchor name can be arbitrary, but the first letter should generally be capitalized in keeping with header style (see Manual of Style § Section headings for more information).
You can define one or more anchor names, separated by |. This can be useful for alternative spellings, such as "humor" and "humour."
In general, if the intended target of an anchor is a section title, then it should be placed at the end of the section header by substitution:
== Section header{{subst:anchor|Anchor name}} ==
which will be saved in the article as:
== Section header
<span class="anchor" id="Anchor name"></span>
==
Anchor names are case sensitive, so [[#Anchor name]]
and [[#Anchor Name]]
are not equivalent. When making an anchor, in general capitalize the first letter of the anchor name, and follow the same capitalization guidelines as headers (see Manual of Style: Headers for more information).
Character | Code | Template | Magic word | Meaning |
---|---|---|---|---|
" | " "
|
— | — | (double) quotation mark |
# | # #
|
{{hash}}
|
— | hash |
| | | &vertbar;
|
— | {{!}}
|
pipe |
= | = =
|
— | {{=}}
|
equals |
<sup>
and <sub>
(superscript and subscript) cannot be used. Most other characters, including white space and punctuation, are not a problem.#location
links go to the first anchor with that name. Duplicate anchors result in invalid HTML; you can check for duplicate anchors by running the page through the W3C Markup Validation Service.=== Baz{{subst:anchor|Bar}} ===
, link to it with [[pagename#Bar]]
, not [[pagename#bAR]]
. However, because some browsers are not case-sensitive, do not create section titles or anchors that differ only in case from others on the page. That is, do not create both === Abcd{{subst:anchor|Baz}} ===
and === Efgh{{subst:anchor|bAZ}} ===
./* Limitations{{anchor|Issues}} */ New issue
. The editor must manually remove the anchor template from the edit summary window, or else when they save the section, the browser may not return to the section and the section link of that edit in the history page won't work.To see how to set anchors in tables, see Help:Tables and locations § Section link or map link to a row anchor. Only use this template in tables if you need multiple anchors for the same row. |
Anchors may be used within tables, subject to certain restrictions. The {{anchor}}
template may be used in the caption and cells of a table, but not those portions of a table that are outside the caption and cells. Unlike in section headings, the template does not have to be substituted. It is used on the table's caption thus:
|+ {{anchor|FooX}} A table caption
and the following forms of cell are valid:
!{{anchor|Foo1}} A header cell
!style="background:white;" |{{anchor|Foo2}} A header cell with styling
|{{anchor|Foo3}} A data cell
|rowspan=2 |{{anchor|Foo4}} A data cell spanning two rows
You need to ensure that the {{anchor}}
is not in that portion of the markup intended for the classes, styles etc. Thus, {{anchor}}
cannot be placed anywhere on lines that begin with {|
(start of table) or |-
(new row), and the following forms of cell are not valid:
!{{anchor|Foo1}} |A header cell
!style="background:white;" {{anchor|Foo2}} |A header cell with styling
|{{anchor|Foo3}} |A data cell
|rowspan=2 {{anchor|Foo4}} |A data cell spanning two rows
If it is necessary for an anchor to be in any of these positions, a different technique is used—the id=
attribute. This is placed in that portion of the markup where the classes, styles etc. may be used, as follows:
{| id=FooX class=wikitable
|- id=FooY
!id=Foo1 |A header cell
!style="background:white;" id=Foo2 |A header cell with styling
|id=Foo3 |A data cell
|rowspan=2 id=Foo4 |A data cell spanning two rows
The id=
attribute may appear before, between or after any other attributes that may be present, but only one id=
attribute may be used in each of these areas.
If {{anchor}}
is placed at the start of a vertically centered cell (which is the default for tables) then links to the anchor will jump to the start of the displayed content and not the top of the cell. This may require the reader to scroll up to fully see other cells in the row. It can be avoided by instead placing id=
where the row code starts.
Anchors should never be left unsubstituted within a section header, as this violates MOS:HEADINGS and causes technical complications. More specifically: if {{anchor}}
is used without substitution, the anchor will be included in page editing history as part of the section name (see MOS:SECTIONANCHOR for details).
To show why placement in the header is preferred, the following anchor is placed in the Basic format section header:
== Basic format<span class="anchor" id="Foo"></span><span class="anchor" id="In-Foo"></span> ==
Since the anchor is actually used on this documentation page, the links #Basic format, #Foo and #In-Foo all work and can be tested to see the effect.
For contrast, an anchor named #Under-Foo has also been placed underneath the Basic format section header and can be clicked to illustrate how this placement hides the section title when jumping to the linked target on some web browsers:
== Basic format ==
{{anchor|Under-Foo}}
Another anchor named #Above-Foo has been placed above the section header. This anchor does work correctly for standard desktop skins, but because the anchor is technically not in the section but before it, mobile views will not expand the desired section.
{{anchor|Above-Foo}}
== Basic format ==
Reasons for the above being best practice are detailed in the following additional, numbered examples, as well as in § Limitations section:
{{anchor|Foo}}
[[#Foo|...]]
from within the same article (let's call this article "Qux"), [[Qux#Foo|...]]
from other articles and from redirects (where the ellipsis after the word "Foo" here means the words chosen to represent that link in the Wikipedia article, which, of course, could be anything).== Foo ==
within a Wikipedia article titled Qux
: == {{anchor|Foo bar}}
Foo ==
[[Qux#Foo bar]]
would remain valid even if the section were renamed == {{anchor|Foo bar}} On foo and its many friends ==
Foo bar
) should be different than the section (Foo
) to avoid invalid HTML.== Foo{{subst:anchor|Foo bar}}
==
== Foo<span class="anchor" id="Foo bar"></span>
==
{{anchor|Foo|Bar|baz}}
[[#Foo]]
, [[#Bar]]
and [[#baz]]
.== The placement of the tongue when producing Yish Yash vowel sounds ==
[[Yish Yash language#The placement of the tongue when producing Yish Yash vowel sounds|Yish Yash tongue placement]] is particularly interesting.
== Yish Yash vowels and the tongue ==
== The placement of the tongue when producing Yish Yash vowel sounds{{subst:anchor|Tongue}} ==
== Yish Yash vowel–tongue interaction{{subst:anchor|Tongue}} ==
[[Yish Yash language#Tongue|Yish Yash tongue placement]] is particularly interesting.
TemplateData for Anchor
Add HTML anchors to a page. Make a link to your anchor with [[#Anchor on same page]] or [[Page you're linking to#Anchor on that page]]. Every anchor on a page must be different. Do not use the characters " or # or | or =.
Parameter | Description | Type | Status | |
---|---|---|---|---|
First anchor | 1 | Name of anchor
| String | required |
Second anchor | 2 | Name of anchor | String | optional |
Third anchor | 3 | Name of anchor | String | optional |
Fourth anchor | 4 | To add more than four anchors, go to source editing. | String | optional |