Template:Tag

☆ Save On Wikipedia ↗

<tag>...</tag>

Template documentation

A markup tag is an open angle bracket < and a close angle bracket > and the content within them, in a markup language such as XML, HTML, or wikitext (which supports some HTML). For example:

The <title> tag provides a title for the Web page.

This template provides a quick way to mention a markup-style tag in a preformatted way. It is mainly used in discussion/help pages. For example, enter {{tag|title}} to render <title>...</title>.

Syntax

{{tag|tagname [|type] [|content=text] [|attribs=attributes and values]}}

(square brackets = optional)

Nested tags

For nested tags, use the |content= parameter of the outer template to house the inner tag:

{{tag|div|content={{tag|span}}}} renders <div><span>...</span></div>

Limitations

In certain contexts, nestling the tags in this way breaks the code. In these cases you will have to supply inner tags as plain wiki markup (meaning that the only benefit of this template is not having to do so for the outermost tag). In this example we wrap the inner tags in <nowiki>...</nowiki> tags:

{{tag|div|content=<nowiki><span>...</span></nowiki>}}
renders <div><span>...</span></div>

Compare to not using this template at all, instead wrapping our nested tags in <code><nowiki>...</nowiki></code> tags:

<code><nowiki><div><span>...</span></div></nowiki></code>
renders <div><span>...</span></div>

It is up to each editor to decide whether using this template is worth it in these cases.

Parameters

|1=  (tagname above) (required)
The XML/HTML tag's name (e.g. code, ref). Use special value !-- for an HTML comment.
|2=  (type above)
To indicate which of the tag's types is/are presented:
p  (pair) (default)
A matching pair of open/start and close/end tags (e.g. <div>...</div>).
To suppress the ellipsis ("...") between the tags, add an empty |content= parameter. For example, {{tag|div|p|content=}} produces <div></div>.
o  (open)
An open/start tag (e.g. <span>).
c  (close)
A close/end tag (e.g. </span>).
e  (empty)  or  s  (single)  or  v  (void)
An empty element, formed with a single self-terminating tag (e.g. use {{tag|hr|s}} to render <hr />); in HTML5 these are now known as "void" elements, though "empty" is the more common term.
|content=
Text to place between, after, before or inside (depending on |type=) the tag(s). To suppress any text between the tags, supply an empty parameter: |content=. The default changes with the type. For |2=pair the default is the ellipsis ("..."). For |2=open and |2=close, the default is nothing, as if |content=. For |2=single the default is a single space.
|attribs= or |params=
Attributes and values to be included as part of an open/start tag. This parameter is ignored if |2=close
|wrap=yes
Disable nowrap for long samples, so allowing wraps (line breaks).
|link=yes
Link to the element's entry in the HTML element article. This is only for HTML elements; the page for the link is hard-coded.
|style=
Replace the default CSS style. Use special value |style=plain as a shortcut for border:none; background:transparent.

Examples

MarkupRenders as
{{tag|ref}}

<ref>...</ref>

{{tag|ref|content=}}

<ref></ref>

{{tag|ref|content=hello}}

<ref>hello</ref>

{{tag|span|content=foo}}

<span>foo</span>

{{tag|span|open}}

<span>

{{tag|span|open|content=hello}}

<span>hello

{{tag|span|close|content=hello}}

hello</span>

{{tag|span|pair|content=hello}}

<span>hello</span>

{{tag|ref|open|attribs=group="note"}}

<ref group="note">

{{tag|references|single}}

<references />

{{tag|br|single}}

<br />

{{tag|!--|content=comment}}

<!--comment-->

{{tag|math|attribs=chem}}

<math chem>...</math>

{{tag|a
 |attribs=href="https://en.wikipedia.org/"
 |content=English Wikipedia
 |wrap=yes}}

<a href="https://en.wikipedia.org/">English Wikipedia</a>

{{Tag|del|link=y}}

<del>...</del>

{{tag|div|style=background: cornsilk}}

<div>...</div>

{{Tag|div|style=plain}}

<div>...</div>

TemplateData

This is the TemplateData for this template used by TemplateWizard, VisualEditor and other tools. See a monthly parameter usage report for Template:Tag in articles based on its TemplateData.

TemplateData for Tag

This template is for 'displaying' HTML/XML-style tags for elements with code markup. It can contain contents between the start and end tags, as well as attributes for the tag. (Note: To add markup tags, use the #tag magic word.)

Template parameters

This template prefers inline formatting of parameters.

ParameterDescriptionTypeStatus
Tag name1

Tag's name. Use !-- for an HTML comment.

Example
includeonly
Stringrequired
Type2

To indicate which of the tag's types is/are presented. For example, using "open" → <span>; "close" → </span>; "empty" → <br />. To suppress the ellipsis ("...") between the tags, add an empty "content" parameter → <span></span>

Suggested values
pair open close empty void single p o c e v s
Default
pair
Example
open
Stringsuggested
Disable nowrapwrap

Disable nowrap for long samples, so allowing wraps (line breaks or newlines).

Default
no
Auto value
yes
Booleanoptional
CSS stylestyle

Replace the default CSS style. Use "plain" for "border:none; background:transparent".

Example
background: cornsilk
Stringoptional
Link?link

Link to an HTML element's entry. This is only for HTML elements; the page for the link is hard-coded.

Suggested values
yes y
Unknownoptional
Attributes and valuesattribs params

Attributes and values to be included as part of an open/start tag

Example
class="plainlinks"
Stringsuggested
Contentcontent

Text to place between open/start and close/end tags.

Stringsuggested

Global use and documentation

For a global use of this template in other sister or Wikimedia projects, after copy-pasting in the destination project, remember to change the code:

[[HTML element#
+
[[wikipedia:en:HTML element#

For template documentation in the sister project, you can use Template:Wikipedia doc.

See also

Other formatting templates

Templates producing specialised formatting effects for given templates, modules or parameters
Code example Effect Notes
<syntaxhighlight lang="wikitext">
{{Hatnote
   | Some text
   | selfref = yes
   | category = no
   | lang = fr
}}
</syntaxhighlight>
{{Hatnote
    | Some text
    | selfref = yes
    | category = no
    | lang = fr
}}
Same as above
<syntaxhighlight lang="wikitext" inline>{{Hatnote|Some text|selfref=yes|category=no|lang=fr}}</syntaxhighlight> {{Hatnote|Some text|selfref=yes|category=no|lang=fr}} Same as above
{{tl2|Hatnote|lang=fr}} {{hatnote}}Supports linking to sister projects (e.g., fr:Hatnote)
{{demo|<nowiki>{{Hatnote|Some text}}</nowiki>}}
{{hatnote|Some text}}
Shows code and example
{{tln|Hatnote}} Template:HatnoteProduces a normal link to the template
{{elc|Template:Example}}
{{elc|Template:Example|Text|suffix}}
[[Template:Example]]
[[Template:Example|Text]]suffix
Shows how wikilink would be entered in wiki markup, with optional link text and suffix
{{ml|Example|hello}} {{#invoke:Example|hello}}Counterpart to {{tl}} for linking to Lua modules
{{mfl|Example|hello}} {{#invoke:Example|hello}}Similar to {{ml}}, but expects the function to be documented and creates a link to the corresponding section
{{mlx|Example|hello}} {{#invoke:Example|hello}}Counterpart to {{tlx}} for linking to Lua modules
{{ml-lua|Module:Example}} require('Module:Example')Link to Lua modules and built-in libraries, showing Lua code.
{{para|title|<var>book title</var>}} |title=book titleFormats template parameters for display, with or without values
{{para2|title|<var>book title</var>}} |title=book titleFormats template parameters for display similar to <syntaxhighlight lang="wikitext">...</syntaxhighlight>, with or without values
{{sclx|LASTING}} [[WP:LASTING]]Takes a shortcut suffix in project namespace and displays it with brackets and the WP: alias in a <code>...</code> tag.
{{tag|ref}}
{{xtag|templatedata}}
<ref>...</ref>
<templatedata>
Formats [X]HTML tags; can add content, choose opening, closing, or self-closing
{{dtl|Ping project}} {{d:Ping project}}Wikidata counterpart to {{tl}}
{{mwl|#if}}
{{mwl|#if|{{{1}}}|true|false}}
{{#if}}
{{#if:{{{1}}}|true|false}}
Magic word links
{{pf|if}}
{{pf|if|{{{1}}}|true|false}}
{{#if}}
{{#if:{{{1}}}|true|false}}
Parser function equivalent to {{tl}}