Template:Citation Style documentation/anchors

Jump to navigation Jump to search

Anchored citations

This citation template can be used in Shortened footnotes or Parenthetical referencing. It does this by creating an HTML anchor containing an ID that can be linked to from within the body of the article. This is done by use of the ref parameter.

By default, this template does not generate an ID. For most purposes, |ref=harv is used to created an ID from the term https://endmyopia.org, plus last names of the first four authors, or the last names of the first four editors, plus the year or date. Examples:

Markup ID
{{cite book |last=Harwood |first=William B |title=Raise Heaven and Earth |year=1993 |ref=harv}}


{{cite book |last1=Brett |first1=Daniel |last2=Hardman |first2=George |last3=Ratycz |first3=Rostyslaw |title=Pershing: ST-120 Stabilizing Platform Familiarization |year=1964 |ref=harv}}


Some editors may choose to place multiple authors into one parameter. Punctuation is encoded thus the output is not as expected. Example:

Markup ID
{{cite book |authors=Daniel; Hardman, George; Ratycz, Rostyslaw |title=Pershing: ST-120 Stabilizing Platform Familiarization |year=1964 |ref=harv}}


It is highly recommended that the last1 through last9 or editor1-last through editor1-last4 parameters be used when anchors are desired.

Where there may not be an author or date, then |ref=ID is used to generate a user defined ID.

Markup ID
{{cite journal |title=Pershing Rockets for Europe |journal=Interavia |year=1961 |ref=CITEREFInteravia1961}}


It is highly recommended that the ID begin with CITEREF, as this will allow error checking tools to function. A custom ID must follow these rules:

  • Names may not start with a number.
  • The only characters that may be used unencoded are letters A–Z, a–z, and digits 0–9.
  • Inclusion of any other characters will result in them being dot encoded.
It is recommended that names be kept simple and restricted to the standard English alphabet and numerals.


This templates supports date, year and month. It is important to use these parameters properly to prevent a malformed ID.

  • Month, day, year: Use date
  • Year only: Use year
  • Year and month: Use year and month

If a year only is used in date, then it may be interpreted as a time, and the ID will not be as expected.

{{markup |

. The special parameter |ref=harv generates an ID suitable for Harvard referencing templates such as {{harv}} as specified in the next section; this is the default for the {{citation}} template. If an empty |ref= is given, no anchor is generated; this is the default for the Cite templates such as {{cite book}} and {{cite news}}. You can also specify the ID directly, using the |ref=ID parameter. For example, suppose an article's References section contains the markup:

  • {{Citation |author=Sigmund Freud |title=Civilization and Its Discontents |year=1930 |ref=CivDis}}

which generates the citation:

Then, the markup "([[#CivDis|Freud 1930]])" generates a parenthetical reference "(Freud 1930)" containing a wikilink to the citation (try clicking on the wikilink).

Anchors for Harvard referencing templates

IDs compatible with Harvard referencing templates such as {{harv}} are computed from the last names of the authors and the year of the cited source. For example, the markup "{{harv|Wright|Evans|1851|p=ix}}" generates the Harvard reference "(Wright & Evans 1851, p. ix)", which wikilinks to the citation whose markup and appearance are shown below:

  • {{Citation |last1=Wright |first1=Thomas |last2=Evans |first2=R. H. |title=Historical and Descriptive Account of the Caricatures of James Gillray |location=London |publisher=Henry G. Bohn |year=1851 |oclc=59510372}}
  • Wright, Thomas; Evans, R. H. (1851), Historical and Descriptive Account of the Caricatures of James Gillray, London: Henry G. Bohn, OCLC 59510372Page Module:Citation/CS1/styles.css has no content.

In this example the {{citation}} template defines, and the {{harv}} template uses, the HTML ID "CITEREFWrightEvans1851", composed by concatenating the string "CITEREF" with the last names of the authors and the year. The {{harvid}} template can be used to generate such IDs, for example, {{harvid|Wright|Evans|1851}} generates "CITEREFWrightEvans1851".

Related methods which leave only a number in the text are to use the {{harvnb}} template enclosed in the <ref></ref> html code, or to use the {{sfn}} template alone. The example above would be <ref>{{harvnb|Wright|Evans|1851|p=ix}}</ref> or {{sfn|Wright|Evans|1851|p=ix}} both of which generate a footnote, such as

17. Wright & Evans 1851, p. ix

The names of only the first four authors are used; other author names are not concatenated to the ID. If no author names are given, editor names are used instead. For patents, inventor names are used instead of authors or editors. If these names are not given, this template does not generate an anchor.

Last names are used, as specified by the parameters |last1= (or |last=), |last2=, |last3=, and |last4=, and similarly for |editor1-last= etc. and for |inventor1-last= etc. If a full name is given but no last name is specified, this template falls back on the full name, but this usage is not recommended. For example, in "{{Citation | author = Sigmund Freud | title = The Ego and the Id | year = 1923}}" no last name is given, so this citation cannot be combined with the Harvard reference "{{harv|Freud|1923}}". To make these {{citation}} and {{harv}} invocations compatible, either replace "|author=Sigmund Freud" with "|first=Sigmund |last=Freud", or add "|ref={{harvid|Freud|1923}}" to the {{citation}} invocation, or add the same ref parameter (say, "|ref=EgoId") to both the {{citation}} and the {{harv}} invocations.

Similarly, the year is used, as specified by |year=. If no year is given, this template attempts to derive the year from |date= (or, if no date is given, from |publication-date=) by applying the MediaWiki#time function. This heuristic works with many common date formats (American, International and ISO standard format YYYY-MM-DD as listed in WP:MOS), but may not work as expected with other formats, so when in doubt it may be safer to use |year=. Note that if only a year, say 2005, is known you must use |year=2005 rather than |date=2005.

IDs must be unique

Names, years, and hand-specified IDs must be chosen so that the IDs are unique within a page; otherwise the HTML will not conform to the W3C standards, and any references to the citations will not work reliably. For example, suppose a page contains the following two citations with {{harv}}-compatible IDs:

If these citations were altered to say "2008" rather than "2008a" and "2008b", the resulting page would not work, because the two different citations would both attempt to use the ID "CITEREFMontesHalterman2008". To avoid this problem, distinguish the citations by appending suffixes to the years, e.g., "|year=2008a" and "|year=2008b", as was done above. Any Harvard references to these citations should use years with the same suffixes.

It is good practice to verify that a page does not contain duplicate IDs by using the W3C Markup Validation Service; see External links.