Commonly-used macros
This page lists many of the general-purpose macros created for use on MDN. For additional how-to information on using these macros, see Using macros.
See Other macros for information on macros that are infrequently used, are used only in special contexts, or are deprecated.
Linking
MDN provides a number of link macros for easing the creation of links to reference pages, glossary entries, and other topics.
Link macros are recommended over normal Markdown links because they are succinct and translation-friendly. For example, a glossary or reference link created using a macro does not need to be translated: in other locales it will automatically link to the correct version of the file.
Glossary links
The Glossary
macro creates a link to a specified term’s entry in the MDN glossary.
This macro accepts one required parameter and one optional parameter:
- The term’s name (such as “HTML”):
\
{{Glossary(“HTML”)}}
yields{{Glossary("HTML")}}
- Optional: The text to display in the article instead of the term name:
\
{{Glossary(“CSS”, “Cascading Style Sheets”)}}
yields{{Glossary("CSS", "Cascading Style Sheets")}}
Linking to pages in references
There are macros for locale-independent linking to pages in specific reference areas of MDN: JavaScript, CSS, HTML elements, SVG, etc.
The macros are easy to use. Minimally all you need to do is specify the name of the item to link to in the first argument. Most macros will also take a second argument allowing you to change the display text (documentation can be found at the links in the left-most column below).
Macro | Links to page under | Example |
---|---|---|
CSSxRef | CSS Reference (/Web/CSS/Reference) |
\`{{CSSxRef("cursor")}}` results in `{{CSSxRef("cursor")}}` .
|
DOMxRef | DOM Reference (/Web/API) |
\`{{DOMxRef("Document")}}` or \`{{DOMxRef("document")}}` results in `{{DOMxRef("Document")}}` ,\`{{DOMxRef("document.getElementsByName()")}}` result in `{{DOMxRef("document.getElementsByName()")}}` \`{{DOMxRef("Node")}}` result in `{{DOMxRef("Node")}}` .You can change the display text using a second parameter: \`{{DOMxRef("document.getElementsByName()","getElementsByName()")}}` results in `{{DOMxRef("document.getElementsByName()","getElementsByName()")}}` .
|
HTMLElement | HTML Elements reference (/Web/HTML/Element) |
\`{{HTMLElement("select")}}` results in `{{HTMLElement("select")}}`
|
JSxRef | JavaScript reference (/Web/JavaScript/Reference). |
\`{{JSxRef("Promise")}}` results in `{{JSxRef("Promise")}}`
|
SVGAttr | SVG attribute reference (/Web/SVG/Attribute). |
\`{{SVGAttr("d")}}` results in `{{SVGAttr("d")}}`
|
SVGElement | SVG Element reference (/Web/SVG/Element). |
\`{{SVGElement("view")}}` results in `{{SVGElement("view")}}`
|
HTTPHeader
|
HTTP headers (/Web/HTTP/Headers). |
\`{{HTTPHeader("ACCEPT")}}` results in `{{HTTPHeader("ACCEPT")}}`
|
HTTPMethod | HTTP request methods (/Web/HTTP/Methods). |
\`{{HTTPMethod("HEAD")}}` results in `{{HTTPMethod("HEAD")}}`
|
HTTPStatus | HTTP response status codes (/Web/HTTP/Status) |
\`{{HTTPStatus("404")}}` results in `{{HTTPStatus("404")}}`
|
Navigation aids for multi-page guides
Previous
, Next
, and PreviousNext
provide navigation controls for articles which are part of sequences.
For the single-way templates, the only parameter needed is the wiki location of the previous or next article in the sequence.
For PreviousNext
, the two parameters needed are the wiki locations of the appropriate articles.
The first parameter is for the previous article, and the second is for the next article.
Code samples
Live samples
EmbedLiveSample
lets you embed the output of a code sample on a page, as described in Live samples.LiveSampleLink
creates a link to a page containing the output of a code sample on a page, as described in Live samples.EmbedGHLiveSample
allows to embed live samples from GitHub pages. You can get more information at GitHub live samples.
General-purpose formatting
Inline indicators for API documentation
Optional_Inline
and ReadOnlyInline
are used in API documentation, usually when describing the list of properties of an object or parameters of a function.
Usage: \
{{Optional_Inline}}
or \
{{ReadOnlyInline}}
.
Example:
isCustomObject
{{ReadOnlyInline}}
- : Indicates, if
true
, that the object is a custom one.
- : Indicates, if
parameterX
{{optional_inline}}
- : Blah blah blah…
Status and compatibility indicators
Inline indicators with no additional parameters
Non-standard
Non-standard_Inline
inserts an in-line mark indicating the API has not been standardized and is not on a standards track.
Syntax
\
{{Non-standard_Inline}}
Examples
- Icon:
{{Non-standard_Inline}}
Experimental
Experimental_Inline
inserts an in-line mark indicating the API is not widely implemented and may change in the future.
For more information on the definition experimental, see the Experimental, deprecated, and obsolete documentation.
Syntax
\
{{Experimental_Inline}}
Examples
- Icon:
{{Experimental_Inline}}
Inline indicators that support specifying the technology
Deprecated
Deprecated_Inline
inserts an in-line deprecated mark ({{Deprecated_Inline}}
) to discourage the use of an API that is officially deprecated (or has been removed).
For more information on the definition deprecated, see the Experimental, deprecated, and obsolete documentation.
Syntax
\
{{Deprecated_Inline}}
Examples
- Icon:
{{Deprecated_Inline}}
Page or section header indicators
These templates have the same semantics as their inline counterparts described above. The templates should be placed directly underneath the main page title (or breadcrumb navigation if available) in the reference page. They can also be used to mark up a section on a page.
Non-standard_Header
:\
{{Non-standard_Header}}
{{Non-standard_Header}}
SeeCompatTable
used on pages that document experimental features. Example:\
{{SeeCompatTable}}
{{SeeCompatTable}}
Deprecated_Header
:\
{{Deprecated_Header}}
{{Deprecated_Header}}
SecureContext_Header
. Should be used on main pages like interface pages, API overview pages, and API entry points (e.g.navigator.xyz
) but usually not on subpages like method and property pages. Example:\
{{SecureContext_Header}}
{{SecureContext_Header}}
Indicating that a feature is available in web workers
The AvailableInWorkers
macro inserts a localized note box indicating that a feature is available in a worker context.
You can also pass some arguments to indicate that a feature works in specified worker context.
Syntax
\`{{AvailableInWorkers}}`
\`{{AvailableInWorkers("window_and_worker_except_service")}}`
Examples
{{AvailableInWorkers}}
{{AvailableInWorkers("window_and_worker_except_service")}}
Browser compatibility and specification macros
The following macros are included on all reference pages, but are also supported by all page types:
-
\
{{Compat}}
/\
{{Compat(<feature>)}}
/\
{{Compat(<feature>, <depth>)}}
- : Generates a compatibility table for the feature passed as the parameter. If no parameter is included, it defaults to the features defined by
browser-compat
in the frontmatter. An optional depth parameter sets how deep sub features should be added to the table. The depth, if omitted, defaults to 1, meaning only the first level of sub feature data from BCD will be included.
- : Generates a compatibility table for the feature passed as the parameter. If no parameter is included, it defaults to the features defined by
-
\
{{Specifications}}
/\
{{Specifications(<feature>)}}
- : Includes the specification for the feature specified in the parameter. If no parameter is passed, the specification listed is defined by the value for
spec-urls
in the frontmatter, if present, or from the specification listed in browser compatibility data defined bybrowser-compat
in the frontmatter. The specification is rendered as an external link.
- : Includes the specification for the feature specified in the parameter. If no parameter is passed, the specification listed is defined by the value for