Help:HTML in wikitext

Page semi-protected
From Wikipedia, the free encyclopedia

The MediaWiki software, which drives Wikipedia, allows the use of a subset of HTML 5 elements, or tags and their attributes, for presentation formatting.[1] But most HTML can be included by using equivalent wiki markup or templates; these are generally preferred within articles, as they are sometimes simpler for most editors and less intrusive in the editing window; but Wikipedia's Manual of Style recommends their use in certain cases. (See Help:Wikitext for wiki equivalents to HTML tags not otherwise discussed below.) And HTML is useful outside of articles, for example for formatting within templates. For help with Cascading Style Sheet use within Wikipedia see Help:Cascading Style Sheets.

Some tags look like HTML, but are actually MediaWiki parser and extension tags, and so are really wiki markup. HTML in pages can be checked for HTML5 compliance by using validation. Some elements and attributes are supported by MediaWiki and browsers, but have been deprecated by HTML5, and therefore should no longer be used.

Tutorials

This help page gives only an overview of allowed markup. For further assistance and detailed specifications:

Attributes

HTML attributes provide additional information about an element and are always specified in the start tag. They are formatted as a name/value pair like name="value".

Global attributes apply to all tags. Attributes not listed here are not allowed by MediaWiki[1]:

  • class: one or more classifications to which the element belongs. See Wikipedia:Catalogue of CSS classes.
  • dir: text direction— "ltr" (left-to-right), "rtl" (right-to-left) or "auto".
  • id: unique identifier for the element.
  • lang: primary language for the contents of the element per BCP 47.
  • style: applies CSS styling to the contents of the element.
  • title: advisory information associated with the element.

HTML5 microdata attributes apply to all tags:[2]

  • Any attribute beginning with data-
  • itemid
  • itemprop
  • itemref
  • itemscope
  • itemtype

Other tags such as <table> support specific attributes – these are listed in the appropriate section.

Markup Renders as
This is <span style="color:red;">red</span> text.

This is red text.

The MediaWiki Sanitizer.php does some cleanup on attributes. A best practice is to use the proper syntax.

  • Discards attributes not on a whitelist for the given element.
  • Turns broken or invalid entities into plaintext.
  • Double-quotes all attribute values.
  • Attributes without values are given the name as value.
  • Double attributes are discarded.
  • Unsafe style attributes are discarded.
  • Prepends space if there are attributes.

Elements

These HTML elements are supported by the MediaWiki software. This section gives a brief overview of the HTML element, an example, relevant wikimarkup and templates.

Basic

h1, h2, h3, h4, h5, h6

The <h1>...</h1> through <h6>...</h6> tags are headings for the sections with which they are associated. <h1> is used for the article title. Headings are styled through CSS and added to the page's table of contents.

Markup Renders as
<h1>Heading 1</h1>
<h2>Heading 2</h2>
<h3>Heading 3</h3>
<h4>Heading 4</h4>
<h5>Heading 5</h5>
<h6>Heading 6</h6>
Heading 1
Heading 2
Heading 3
Heading 4
Heading 5
Heading 6

Wikimarkup: surround the text with the appropriate number of equal signs. Headers formatted with wikimarkup add an [edit] link.

Markup Renders as
= Heading 1 =
== Heading 2 ==
=== Heading 3 ===
==== Heading 4 ====
===== Heading 5 =====
====== Heading 6 ======
Heading 1
Heading 2
Heading 3
Heading 4
Heading 5
Heading 6


Templates: {{fake heading}} for use in documentation

p

<p>...</p> tag places content into a separate paragraph.

Markup Renders as
<p>HyperText Markup Language</p><p>HyperText Markup Language</p>

HyperText Markup Language

HyperText Markup Language

Wikimarkup: Separate paragraphs by a single blank line.

Markup Renders as
HyperText Markup Language

HyperText Markup Language

HyperText Markup Language

HyperText Markup Language

<p>...</p> is especially useful in lists, for list items with multiple paragraphs:

Markup Renders as
* <p>This is a paragraph.</p><p>This is another paragraph in the same item.</p>
* This is a different item.
  • This is a paragraph.

    This is another paragraph in the same item.

  • This is a different item.

Note that the closing tag </p> is not strictly necessary for MediaWiki installations that output HTML 5 (such as Wikipedia).

br

<br> inserts a line break. See H:BR for the other 4 versions that the MediaWiki software converts to <br /> in the HTML that browsers read.

Markup Renders as
HyperText<br>Markup Language

HyperText
Markup Language

Templates:

  • {{break}} adds multiple line breaks.
  • {{crlf2}} adds a true carriage return and line feed.
  • {{clear}} adds a break with styling to clear floating elements.
  • {{plainlist}} creates an unbulleted list.

hr

<hr> or <hr /> represents a paragraph-level thematic break and presents as a horizontal rule.

Markup Renders as
<hr />

Wikimarkup: use ----

Markup Renders as
----


Templates: {{hr}}

Comments

<!--...--> formats the enclosed text as a hidden comment.

Markup Renders as
HyperText<!--Markup Language-->

HyperText

Be careful with spacing around comments. Surrounding a comment with blank lines will result in a blank paragraph, perceived as an extra two blank lines:

Markup Renders as
Content line 1

<!-- Comment -->

Content line 2

Content line 1


Content line 2

Formatting

abbr

<abbr>...</abbr> creates a tooltip to define an abbreviation or acronym that is displayed on mouse-over.

Markup Renders as
<abbr title="HyperText Markup Language">HTML</abbr>

HTML

Templates: {{abbr}}

b

<b>...</b> formats text stylistically offset from other text (bold) without conveying extra importance.

Markup Renders as
<b>HyperText Markup Language</b>

HyperText Markup Language

Wikimarkup: Use ''' to open and close bold text.

Markup Renders as
'''HyperText Markup Language'''

HyperText Markup Language

bdi

<bdi>...</bdi> isolates the content from the surrounding text-direction settings.

Markup Renders as
اليمين إلى اليسارleft to right

اليمين إلى اليسارleft to right

اليمين إلى اليسار<bdi>left to right</bdi>

اليمين إلى اليسارleft to right

Support: Firefox, Chrome

bdo

<bdo>...</bdo> specifies the text direction.

Attributes and values:

  • dir – Specifies the text direction.
    • ltr
    • rtl
Markup Renders as
<bdo dir="rtl">HyperText Markup Language</bdo>

HyperText Markup Language

blockquote

<blockquote>...</blockquote> presents text in an offset block.

Markup Renders as
<blockquote>HyperText Markup Language</blockquote>

HyperText Markup Language

Templates: {{quote}}; supports pre-formatted attribution and source parameters. For other specialized quotation templates, see Category:Quotation templates.

cite

<cite>...</cite> contains the title of a work. This is a new definition in HTML5— in the previous XML implementation <cite> was used to contain a citation or a reference to other sources. No formatting is applied when this tag is used.

Markup Renders as
<cite>HyperText Markup Language</cite>

HyperText Markup Language

<cite>...</cite> is generally not used directly in Wikipedia articles, and is often misused; see Wikipedia:HTML 5#cite for replacement instructions.

code

<code>...</code> formats a section of computer code. Styled with CSS through mediawiki.skinning/elements.less as a black monospaced typeface with a grey background (#F8F9FA) and border (#EAECF0).

Markup Renders as[3]
use <code>this code</code>

use this code

Templates: {{code}} uses <syntaxhighlight>. See the "See also" section at the template page for additional code-markup templates.

See § samp and § kbd on this page for semantic markup of output and input, respectively.

data

<data>...</data> formats a machine-readable version of contents.

Markup Renders as
<data value="978-0764502149">HTML for Dummies</data>

HTML for Dummies

Attributes: value

del

<del>...</del> formats deleted text.

Markup Renders as
<del>HyperText Markup Language</del>

HyperText Markup Language

dfn

<dfn>...</dfn> is used for indicating the defining instance of a term.

Markup Renders as
<dfn>Definition</dfn>

Definition

Templates: {{dfn}}

em

<em>...</em> represents a span of text with emphatic stress (i.e. semantic emphasis). In most browsers, it renders as italic.

Markup Renders as
<em>HyperText Markup Language</em>

HyperText Markup Language

Templates: {{em}}

i

<i>...</i> represents a span of text offset from its surrounding content without conveying any extra emphasis or importance, and for which the conventional typographic presentation is italic text.

Markup Renders as
<i>HyperText Markup Language</i>

HyperText Markup Language

Wikimarkup: Use '' to open and close italic text.

Markup Renders as
''HyperText Markup Language''

HyperText Markup Language

ins

<ins>...</ins> indicates a range of text that has been added. Styled as underlined text. Used on talk pages to indicate refactored text; see WP:REDACT.

Markup Renders as
<ins>HyperText Markup Language</ins>