Wikipedia:Citation templates and reference anchors

Citation templates are often used to format the citations that show in the reference list. Many of these templates can create anchors that allow links from reference templates that are placed in-text with the content to the full citation in the reference list. These links are a convenience and are not a requirement; the use of reference and citation templates is also not required.

The in-text links are formatted manually or automatically as #CITEREF normally followed by the author name(s) and the year of publication. The citation template then creates an anchor using an HTML id manually or automatically formatted as CITEREF followed by the author last name(s) and the year. For citations without an author, the anchor can be customized.

Anchor support across citation templates is not standardized, and not all templates support anchors.

This page discusses only general citation templates and does not include any of the hundreds of specific-source templates. See Category:Specific-source templates, although many of these may be in Category:Citation templates or not properly categorized. Many specific-source templates use a general citation template as a meta-template.

Types of anchorsEdit

  • Plain anchor— the anchor is the defined text
  • CITEREF anchor— the anchor consists of CITEREF plus the defined text
  • Auto anchor— the anchor is automatically built by concatenating (running together) template fields such as the author last names and the year (e.g. SmithJones1999)
  • Custom anchor— the anchor is created from text defined in a field
  • Reference- anchor— the anchor consists of Reference- plus the defined text

Anchor types can be combined. For example, a template could create a CITEREF auto anchor.

In-text reference templates that create links to anchorsEdit

These templates always create a link of the form #CITEREF plus the author last names (up to four) plus the year.

setting |Ref= will create a custom link.

When a custom link is needed, the first author field can be replaced by the desired text.

Citation templates that create anchorsEdit

These templates always create a CITEREF auto anchor; setting |ref= will create a custom plain anchor.
These citation templates create a plain custom anchor when |ref= is set or a CITEREF custom anchor when |harvid= is set.
These citation templates create a plain custom anchor when |ref= is set or a Reference- custom anchor when |id= is set.
These citation templates create a plain custom anchor when |ref= is set.
These citation templates do not support anchors.

Date and year fieldsEdit

Most of the templates will attempt to extract the year from the date field. If the date consists of anything other than a full date then the year extraction will fail. Most templates include a month field that can be used in conjunction with the year field.

Custom anchorsEdit

Custom anchors must be used when the template does not support auto anchors or when there is no author. The name of the website or organization can be used in place of the author name. Custom anchors can be crafted manually or with {{SfnRef}} / {{harvid}}.

Link and anchor namesEdit

Manually created names should start with CITEREF. If you choose to not do this, then the first character must begin with a letter A-Z or a-z. All names are case sensitive. HTML ids have other name rules, but the MediaWiki software automatically encodes spaces to underlines and Unicode characters to their equivalent hexadecimal characters.

Manual links to citation anchorsEdit

To avoid the sometimes difficult to remember syntax for links to CITEREF anchors, {{citeref}} can be used to create internal wikilinks with either small superscript-style labels (like this[n]) or plain free-text labels to such anchors. It can be used inside of other citations.

Duplicate in-text linksEdit

Multiple instances of the same in-text link may be used to link to one citation in the reference list, and the in-text links can use the same name.

Duplicate anchorsEdit

The anchor name for each citation must be unique. Multiple instances of the same anchor will create ambiguous links and will cause invalid HTML output of the page. There is no automatic error checking. The W3C Validation Service can be used to check for duplicate HTML ids.

Where the same author has multiple publications within the same year, the citation template will create a duplicate anchor. The standard solution is to add a lower case alpha character to the year.

Templates without anchorsEdit

{{Wikicite}} can be used to add an anchor for any of the templates that do not support anchors. The |ref= field is used to create the anchor and the |reference= field is set to the citation template. The |ref= field should be enclosed in quotes and can be defined with {{SfnRef}}.