Template:Anchor/doc

The template inserts one or more invisible anchor names (HTML fragment identifiers) in a page.

The basic format is. To link to an anchor from within the same page, use. To link to an anchor from another page, use. See Help:Section linking for more details.

Note that  is not a browser instruction like.

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 headers for more information).

Basic format
You can define one or more anchor names, separated by |. This can be useful for alternative spellings, such as "humor" and "humour."

In general, substitute an anchor when used at the end of a section header:

which will be saved in the article as:

Anchor names are case sensitive, so  and   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).

Limitations

 * Anchor names that contain any character shown in the table on the right will not work as expected. However, any of these characters can be replaced with the "&amp;#" codes shown for them here. Or, the pipe symbol and equals sign can be worked around with ! and =, respectively. Markup code such as and  (superscript and subscript) cannot be used. Most other characters, including white space and punctuation, are not a problem.
 * Anchor names must be unique on a page, and must not duplicate any heading titles. Duplicate anchors will not work as expected since the  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.
 * Anchor links are case-sensitive in some browsers, so treat all anchor links as case-sensitive when creating links to them. For example, if you create the anchor with, link to it with  , not  . 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   and.
 * If a template is left unsubstituted inside a section title (which should never be done), then the template code will appear in the edit summary window each time a section edit of that section begins, as in . 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.

Use in tables
Anchors may be used within tables, subject to certain restrictions. The 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: and the following forms of cell are valid: You need to ensure that the is not in that portion of the markup intended for the classes, styles etc. Thus,  cannot be placed anywhere on lines that begin with   (start of table) or   (new row), and the following forms of cell are not valid: If it is necessary for an anchor to be in any of these positions, a different technique is used—the  attribute. This is placed in that portion of the markup where the classes, styles etc. may be used, as follows: The  attribute may appear before, between or after any other attributes that may be present, but only one   attribute may be used in each of these areas.

If  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  where the row code starts.

Rationale for substitution in the header 
To show why substitution in the header is preferred, the following anchor is placed in the Basic format section header:

Since the anchor is actually used on this documentation page, the links, and  all work and can be tested to see the effect.

For contrast, an anchor named 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:

Another anchor named has been placed above the section header. This anchor does work correctly, but because the anchor is technically not in the section but before it, it makes editing counter-intuitive.

Anchors should also never be left unsubstituted within a section header, as this violates MOS:HEADINGS and causes technical complications.

Explanations and examples
Reasons for the above being best practice are detailed in the following additional, numbered examples, as well as in § Limitations section:

could be linked to with  from within the same article (let's call this article "Qux"), or it could be linked to with 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 == Here, links via would remain valid even if the section were renamed A drawback of this approach (as detailed in § Limitations section) is that having a template in the section header causes problems with the edit summary window each time that a section edit is done for this section. The obvious solution is to place the anchor before the section name. This also prevents browsers from hiding the section title from view when jumping to the target. The anchor name should be different than the section  to avoid invalid HTML. == which is saved into the article as: == This provides the stable, linkable anchor, but without the edit problem. The Note above still applies. See § Limitations for details.
 * 1) Anchors can be more suitable for inter-article linking than section titles are, because anchors are more stable. For example a section title  within a Wikipedia article titled  :
 * 1) Within section titles, it may be preferable to simply use direct HTML, which may be achieved by substitution like this:
 * 1) The template can be used to create multiple anchors with a single call. For example,

will create three anchors that can then be linked to with,   and. Say you wrote an article about a recently discovered Indo-European language called "Yish Yash". The title of your article would probably be "Yish Yash language" (if there were already an article titled "Yish Yash" that covered the culture generally). Now let's say that within your article you wished to have a section titled "The placement of the tongue when producing Yish Yash vowel sounds". You would create a section heading that looked like this:
 * 1) Here is a more literal example:

Let's say that you then finished up writing and saved the new article. Now, say you came across another article on Wikipedia titled "Proto-Indo-European vowels" which happened to have a section on the unique tongue placement used in Yish Yash. You decided it might be useful here for readers to be able to quickly access the section of your article on Yish Yash tongue placement when forming vowels; however, you don't want to send them to the beginning of the whole article on the Yish Yash language (you wanted to target them more specifically). So you create a link in the Proto-Indo European vowel article to the section within your article on the placement of the tongue in Yish Yash: you might do so by editing the text of the Proto-Indo-European vowel article and adding something like this to a relevant place within it:

That is some really long code, but it would create a direct link to the relevant section of the new Yish Yash language article and would look like this in the article on Proto-Indo-European vowels: "... Yish Yash tongue placement is particularly interesting..." Now let's say another editor came along and wished to change the heading of this section of your article for some legitimate reason—perhaps to "Yish Yash vowels and the tongue". They could do so by editing your article and making the section heading look like this:

Unbeknownst to that editor, this would mean the link in the article on Proto-Indo-European vowels that you created earlier would now go by default to the top of the Yish Yash article instead of your carefully-chosen subsection! However, if an anchor were placed within the section heading of the Yish Yash article either when you created it or when the other editor came along and changed it—perhaps something like this:

or like this:

and the text of the article on Proto-Indo-European vowels had been changed by you to something like this:

then the link from the Proto-Indo-European article would continue to point to the relevant section of the Yish Yash article, even if the wording of the section heading there had changed completely and without the reader having to sort it out for themselves. The use of anchors can make for a cleaner, more efficient Wikipedia reading experience where section headings are changed—which they not infrequently are.

TemplateData
{	"description": "Add HTML anchors to a page. Make a link to your anchor with or Page you're linking to. Every anchor on a page must be different. Do not use the characters \" or # or | or =.",	"params": {		"1": {			"label": "First anchor",			"type": "string",			"required": true,			"description": "Name of anchor",			"example": "Anchor name 1"		},		"2": {			"label": "Second anchor",			"type": "string",			"required": false,			"description": "Name of anchor"		},		"3": {			"label": "Third anchor",			"type": "string",			"required": false,			"description": "Name of anchor"		},		"4": {			"label": "Fourth anchor",			"description": "To add more than four anchors, go to source editing.",			"type": "string",			"required": false		}	},	"format": "inline" }