| Linking and page manipulation |
|---|
This page explains how to make links to pages on Wikipedia (wikilinks), to other Wikimedia projects (interwiki links), and to other websites (external links). It also explains how to make anchors within Wikipedia pages. For guidelines on how to use links, see Wikipedia:Manual of Style/Linking.
Wikilinks (internal links)
A "wikilink" is our common name for an internal link, that is, a link from one page to another page within the same Wikipedia (for example, within the French Wikipedia) or within the same Wikimedia project (for example, within Wiktionary).
Basic syntax
A wikilink is enclosed in double square brackets.
On any Wikimedia page, [[Example]] produces a wikilink with the display text Example and the target page Example on the project you're currently on. For instance, here on the English Wikipedia, the wikilink would lead to the following URL (note the "en" in the address): https://en.wikipedia.org/wiki/Example
Section linking
To link to a section in another page, append a hash mark, pound or number sign (#) followed by the section name to the page name:
[[Page name#Section name|Displayed text]]
Note the use of piping, done to hide the # character. This is appropriate in Wikipedia articles.
Alternatively, format such section links with the section sign (§) instead of a # by using the {{Section link}} template (alias {{slink}}):
{{Section link|Page name|Section name}}
Note: you cannot use the § directly.
That is, use section link or Page name § Section name rather than Page name#Section name. A third option is to use a redirect (link to a page which link directly to a section, see MOS:SECTLINK).
Outside of article space, such as in talk page discussions, using the raw # syntax is fine. Wikipedia inherits this syntax from HTML.
These section links work the same regardless of nesting, i.e. whether you link to a section header, a subsection header or a sub-subsection header (sections nestled inside other sections):
[[Page name#Subsection name|Displayed text]]{{Section link|Page name|Subsection name}}
Note that this means that each header title must be unique across the entire page (or your browser will simply link to the first one encountered). You do not and cannot indicate "a section within a section" — [[Page name#Section name#Subsection name|Displayed text]] doesn't work as intended.
To link to a section on the page you're already on, you may omit the page name:
[[#Section name|Displayed text]]{{Section link||Section name}}
Omitting the page name is recommended when linking to a section in the same page because the link will work as expected when previewing changes or after moving the page. It also makes it clear you intend a same-page link.
Note that section names are entirely case sensitive, in contrast to article links, where the first letter is not case sensitive.
The characters [ ] { } | (right and left square bracket, right and left curly braces, and the vertical bar) require encoding when linking to a section. That is, you cannot use these characters inside the [[ ]] of a link. See note.[1]
For more information, see Help:Section. See also Wikipedia:Redirect § Targeted and untargeted redirects.
Alternate display text
Use a vertical bar | (the "pipe" symbol) to create a link with different display text than the name of the target page. Such a link is called a piped link. Within the link brackets [[target|text]], the part preceding the pipe gives the actual title of the link target page, and the part following the pipe gives the link display text:
[[a|b]]appears on the page as b, but, when opened, links to page a:https://en.wikipedia.org/wiki/A
Display text agglutination
Letters and other non-punctuation characters immediately following the closing bracket of a wikilink — with no whitespace in between — get appended to the link display text. The target is unchanged. This syntax provides a shorthand to link to an article by its canonical title while displaying inflected link text that grammatically agrees with the inline text:
- "There are over 7,500 known cultivars of apples."
[[apple]]s gives the display text apples but the target page apple. This shorthand syntax is equivalent to [[apple|apples]].
Illustrative examples of display text agglutination
[[a|b]]cgives bc, equivalent to[[a|bc]].a[[b]]gives ab.
There are no special rules for text preceding a wikilink.- To prepend preceding text to a displayed link:
[[b|ab]]gives ab. [[a]]:bgives a:b.
Punctuation breaks display text agglutination. This is often helpful for possessives: for example,[[Batman]]'sgives Batman's.[[a]]''b''gives ab.
Markup notation — for example, italics delimited by two sequential single quote characters — is also considered punctuation despite not being rendered as such. As a result, italic text immediately following the wikilink is not included in the displayed link.- To append italicized text to a displayed link:
[[a|a''b'']]gives ab. [[a]]<nowiki />bgives b.
The nowiki tag turns off the rule.[[a|b]]<nowiki />cgives c.
Target page
When a wikilink is opened, Wikipedia tries to resolve the Wikilink target title to its canonical target page. See § Conversion to canonical form
When resolving the target page, the target title is treated as case-sensitive except for the first character:
[[atom]]links to Atom:https://en.wikipedia.org/wiki/Atom[[aTom]]would link to "ATom", which does not exist:https://en.wikipedia.org/wiki/ATom
Disambiguation
When an edit is previewed before saving, if the target of a newly made link turns out to be a disambiguation page, such as the Peacemaker page, the link should be changed to one of the choices on that page unless the link is purposely in a hatnote. If necessary, the new link can be piped, such as in [[Peacemaker (character)|Peacemaker]], which appears as Readers should not be directed to disambiguation pages unless there is no other option but to do so.
Nonexistent page (red link)
If the target page of a wikilink does not exist, it is displayed in red font and is called a "red link":
This link is an example of a red link
On hover over the red link, a tool tip provides more information about the red link.
If a red link is opened, the user is taken to a blank page where it is possible to create a page using that red-linked title. While on that blank page, other red links to this (non-existent) title can be detected using the "What links here" feature.
Self link
A self link is a wikilink with a target page identical to the page on which it appears. Instead of producing an actual link, self links behave like regular body text, with no action upon interaction,[2] and are rendered as bolded body text: [[Help:Link]] is a self link to this page, so it appears on this page as Help:Link and has no action upon interaction. This is also true for piped self links: [[Help:Link|piped self links]]. However, with the preference setting "Link underlining", the bolded text is underlined; this can be suppressed by putting the following in your relevant personal CSS page:
:root .mw-selflink { text-decoration: none; }
Bolded self-links are usually undesirable, except within navigation templates, where the self-link-produced boldface helps locate the article within the template. In some cases, such as with templates that are not navigation templates, and that are transcluded into several pages, self-links can be actively suppressed by enclosing the link within the template {{No self link}}.
A link to a section of the same article, even from the same section, does not produce bold text and works as a normal link. For example, [[Help:Link#Self link]]Help:Link#Self link. Such section links should usually be written without the page name ([[#Self link]]#Self link), because this method does not cause the page to reload if the reader initially arrived at the page via a redirect, and is thus more efficient. A useful application is links from article leads or overview sections to detail sections buried deeper in the same article. An automatically generated table of contents has links to sections on the page.
A self-link is indirect if it links to a page that redirects back. In this case, the page name is technically different, so the link is not bolded: [[Self link]]Self link. If the link contains the prefix for the same project, the self-link feature works as intended: [[en:Help:Self link]]en:Help:Self link.
Special wikilinks
Some types of wikilink target pages result in special behavior:
[[File:Mediawiki.png]]renders the linked image on the current page.[[Category:Help]]adds the current page to the linked category.[[fr:Aide:Liens]]creates a meta interlanguage link to the same article within a different language Wikipedia.
When targeting these page types, the special behavior can be suppressed to display a regular wikilink by prepending a colon character : to the target page:
[[:File:Mediawiki.png]]gives a literal link with target page File:Mediawiki.png[[:Category:Help]]gives a literal link with target page Category:Help[[:fr:Aide:Liens]]gives the literal wikilink fr:Aide:Liens, the French Wikipedia page for Help:Link.
Uncommon link target interpretations
Less common ways in which link targets are reinterpreted are described below in #Conversion to canonical form.
Editing tools
When editing source, links are inserted or deleted simply by adding or removing pairs of square brackets enclosing the text concerned (plus handling piped links).
There are some helpful tools:
- When using the visual editor, selecting some text, then clicking the link icon above the text box (two links of a chain) will allow the link to be added, offering a selection of possible matches and the ability to pipe.
- When using the WikEd source editor, selectable from Preferences > Gadgets > Editing, there is a "Wiki link" button (typically the first button on the bottom row). When editing, if some text is highlighted, clicking the Wiki link button will enclose it in double brackets, i.e., Wikilink it. If, however, some text is highlighted that includes one or more internal links—in many cases just a single internal link with its delimiting brackets—they will be removed instead. For a single link without a pipe, the Wiki link button will toggle between linking and unlinking.
Interwiki links
An interwiki link links to a page on another Wikimedia project website, such as Meta or another language Wikipedia. The target site must be on the interwiki map specified for the source wiki. These links have the same [[...]] syntax as wikilinks (see previously), but take a prefix ":x:" which specifies the target site.
For example, [[m:Help:Link]] links to the "Help:Link" page on Meta, while [[:commons:Athens]] links to page "Athens" on Wikimedia Commons as: commons:Athens.
Interwiki links can be piped, just as with wikilinks. Remember that an interlanguage link should be preceded by a colon if it is to be displayed, where it is inserted in the text, as an inline interlanguage link; otherwise it will be displayed in the list of interlanguage links at the side of the page (which is appropriate only if it is the most closely corresponding page in the other language Wikipedia). Thus (incorporating the pipe trick), [[:ja:Wikilink|]] would be used to link to Wikilink on the Japanese Wikipedia. Example: ([[:ja:URL|]] links to URL on Japanese Wikipedia).
Interwiki links (like external links) are displayed in a slightly paler blue than ordinary wikilinks. The MediaWiki page formatting does not detect whether these target pages exist, so they are never displayed in red.
External links
External links use URLs to link directly to any web page. External links are enclosed in single square brackets (rather than double brackets as with internal links), with the optional link text separated from the URL by a space (not a "|" as with internal links). When rendered, external links are followed by an external link icon. For example,
[http://www.example.org/ link text]
will be rendered as
The URL must be specified in full, including the protocol: for example [http://...] or [https://...]. Short form URLs that are accepted in some other (non-Wikimedia) contexts like [example.org/ link text] or [www.example.org/ link text] are not accepted and will not result in a link being generated. Instead, the link generating markup including the square brackets will be copied directly to the marked-up output, thus "[example.org/ link text]" or "[www.example.org/ link text]".
When no link text is specified, external links appear numbered: [http://www.example.org/some-page][http://www.example.org/some-other-page] becomes . Links with no square brackets display in their entirety: http://www.example.org/ displays as http://www.example.org/.
For more detailed information on external linking practices, see Help:URL § Linking to URLs. Also note that Special:LinkSearch can be used to find all pages linking to a given site.
The external link syntax can also be used to link to particular pages within Wikipedia that are not accessible by wikilinks, such as page history, the edit view, an old version of a page, the diff between two versions, etc. It can also be used to create a navigational image.
To display an external link without the arrow icon, place the external link syntax between <span class="plainlinks">...</span> tags. For instance, <span class="plainlinks">[https://en.wikipedia.org/w/index.php?title=Help:Link&action=history this page's history]</span>, or its template equivalent {{Plainlink}} {{plainlink|url=https://en.wikipedia.org/w/index.php?title=Help:Link&action=history|name=this page's history}}, will be rendered as: this page's history. If you make frequent use of this, the CharInsert gadget (which can be activated under Preferences → Gadgets → Editing → CharInsert) has an option to insert this text in its "Wiki markup" mode.
http: and https:
In mid-2015, Wikipedia and all other Wikimedia sites were changed to use HTTPS to encrypt all traffic. Accessing a URL like http://en.wikipedia.org/wiki/Help:Link will result in the webserver redirecting you to https://en.wikipedia.org/wiki/Help:Link. Therefore, when making an external-style link to an internal page (that is, using single square brackets, or a bare URL), https should be specified to avoid the needless redirect, as in https://en.wikipedia.org/w/index.php?title=Help:Link&action=history.
In the past, when Wikipedia could be accessed via either HTTP or HTTPS, a protocol-relative URL could be used to make an external link (or external-style link to an internal page) which would use http: or https: depending on how the page the link appeared on was accessed, as in [//www.mediawiki.org/wiki/Help:Links]. However, as all Wikimedia sites now require HTTPS, this linking style is obsolete and should no longer be used. http: or https: should be explicitly specified as appropriate for the target site (preferring https:, where available).
Anchors
What is an "anchor"?
A link from an origin page points to either a whole target page or to a particular spot on a target page. An "anchor" is the computer code that marks a destination spot on a target page. A link to an anchor is sometimes referred to as an "anchor link".
Wikipedia automatically creates an anchor for each section and subsection heading. As discussed below, editors may also create anchors anywhere on a target page using HTML code or the {{anchor}} template. Renaming a section or subsection changes its automatic anchor, leaving no target for pre-existing anchor links that use the old name. To preserve the old target, editors often create an anchor using the old heading name.
Section anchor
A link to a section title (as in the examples above) points to an HTML anchor that Wikipedia automatically generates on the target page. Editors can create anchors on smaller units of text using the {{Anchor}} template using specific rules for section anchors or the HTML code <span class="anchor" id="Anchor name">...</span>.
Links to anchors can also be added to external URLs and to interwiki links, again using the # syntax.
Section links still work through page names that are redirects. For example, if Danzig redirects to Gdańsk, then Danzig#History will link to the "History" section of the article Gdańsk. It is also possible for the target of a redirect to be defined as a specific section or anchor of a page (these work only if JavaScript is enabled). Indeed, according to the Manual of Style, it may be preferable to define such redirects, and use them when linking to those sections/anchors, rather than linking using the [[Page name#Section or anchor name|displayed text]] or {{Section link|Page name|Section name}} syntax. This way, if the section or anchored text later becomes its own article, links via the redirect won't need to be rewritten.
For example, Wikipedia:Section link redirects specifically to the section Help:Link#Anchors on this page. A quirk of the way this works is that if one were to add a section name when using such a link, it would override the section specified by the redirect. So Wikipedia:Section link#Interwiki links would go to the "Interwiki links" section of this page. Such overriding of section redirects should be avoided.
The {{Visible anchor}} template can be used to create an anchor that is highlighted when it is linked to (click here for an example). The template's first parameter will be used as both the anchor and the display text (|text= can be used to provide different display text).
Duplicate section names
If more than one section on a target page has the same title, a link to the title goes to the first section with that title. If the link should be to another section with the title, or a title that differs only in capitalization (Example vs. EXAMPLE), append to the linked title _2, _3, and so on, without a space (or 2, 3, and so on with a space), counting from the top of the target page and without regard to whether a section is a top-level section or a subsection. For example, multiple sections titled "History" may be linked to as "History", "History_2" (or "History 2"), and so on.
Linking to part of a section
Anchors can also be used to link to any part of a section. For example, if you want to link to the fifth sentence of a section, you place an anchor at the start of that sentence, and you can then link to that anchor in the same way as you would link to any other anchor.
However, just as with section names, duplicate anchor names only link to the first one. Since anchors aren't displayed, you have a much greater freedom in picking unique anchors, such as by appending the current date and time to the anchor name (for example, by naming an anchor for section "ThisSection" like so: {{Anchor|ThisSection_2014-09-22_18-05a1}} ).
Anchors can be placed anywhere, including at the start of a clause, and inside notes and citations, though it is advisable to test first in your sandbox before trying some exotic new kind of location for the first time. Also the anchor has to be placed after any indicators that are only recognized at the start of a line (such as == for new section, * for new bullet point, : for indentation), as the anchor should still work, but the start-of-line indicator usually no longer will (and you may not always notice this, perhaps especially if you are in a hurry).
There are a small number of special anchor names. See § Table row linking.
Table row linking
To create an anchor for a row of a table, see Help:Tables and locations § Section link or map link to a row anchor. However, [[#top]] and [[#toc]] are reserved names that link to the top of a page and the table of contents, respectively.
Piped link
A piped link is an internal link or interwiki link where the link target and link label are both specified. This is needed in the case that they are not equal, while also the link label is not equal to the link target with the last word extended:
[[cheese]](label = target, no pipe needed)- produces cheese, linked to the article Cheese.
[[cheese]]s(label = target + extension ["s"], no pipe needed)- produces cheeses, linked to the article Cheese.
[[blue cheese|cheese]](label = part of target, pipe required)- produces cheese, linked to the article Blue cheese.
[[cheese|blue cheese]](label = target + additional text ["blue"], pipe required)- produces blue cheese, linked to the article Cheese.
[[cheese|that stuff]](label is completely different from target, pipe required)- produces that stuff, linked to the article Cheese.
This allows linking a word or phrase within the text of a page rather than using "see also", even if the wording does not exactly correspond with the name of the target page. With a suitable browser and depending on the preferences set, one can still see the link target: when you point at the link, the name shows up in a hover tooltip and is also shown in the status bar.
For instance:
[[Train station|station]]
will show: station
This is useful where the word "station" is used in an article on trains; from the context, it would be clear that a train station is meant. The piped link is more convenient to the user than a link to station which might be a disambiguation page.
The word piped refers to the use of the pipe character "|" used to separate the good description from the actual link. This character is named after another use of it; see Pipe (computing).
There are various tricks to get the same result with less typing:
- Leave the part to the right empty – the "pipe trick"
- Leave the part to the left empty – the "inverse pipe trick"
- Just attach text to the link, as in "[[train]]s", see MOS:PIPE.
Using a redirect as an alternative
An alternative to a piped link is using a redirect page. For example, it is unnecessary to say [[Mark Twain|Samuel Clemens]]. Samuel Clemens is a redirect to Mark Twain, so saying [[Samuel Clemens]] is sufficient. A minor drawback of redirects is that "Related changes" will only display the changes to the redirect page, not the redirect target.
Pipe trick
The pipe trick uses the pipe character ("|") to automatically convert the label of a piped link for several kinds of wikilinks. This saves time and avoids potential errors. When the last character of a link is the pipe character, the software will remove the parenthesized part of the title and namespace prefixes and handle commas in the title. This processing happens after clicking "Publish", and the generated text is saved with the rest of the page's wiki markup. Just like for the three or four tildes when signing on Talk pages and the use of subst, in a preview, the result already shows up in the preview itself, but the conversion in the edit box is not yet shown. Press "Show changes" to see the change in the wikitext:
- Any word before the first colon (:), as well as the colon itself, is removed. This word may or may not be a namespace prefix (such as "Help:") or an interwiki prefix (such as "commons:"). If the page name is preceded by a colon, "first" refers to "first after this".
- If there is text in parentheses at the end it will be removed.
- If there are no parentheses but there is a comma, the comma and everything after it are removed.
- The link will remain in whatever case is used.
The pipe trick does not work in edit summaries, within <ref> tags, or with section links. In cases where the pipe trick doesn't work, the link has to be written out in full manually:
- between "ref" tags or gallery tags, but works with {{r}} or {{refn}}.
<ref>[[Roger Taylor (author)|]]</ref> renders in the references list as 