Help:HTML in wikitext

This is an old revision of this page, as edited by Aftar Amin Akash (talk | contribs) at 17:09, 22 October 2016 (Elements). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

The MediaWiki software, which drives Wikipedia, allows the use of a subset of HTML5 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 preferred within articles, as they are simpler for most editors, and less intrusive in the editing window. But 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.

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. The MediaWiki software automatically adds the xml:lang attribute whenever lang is defined, but xml:lang will no longer be passed when included as a separate attribute.
  • 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> or <br /> inserts a line break. Both versions of the break are supported by HTML5. </br> is invalid.

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> 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

==== blockquot

Obsolete/deprecated elements

These elements are now obsolete and deprecated in HTML5, but still supported by browsers.[3] These tags either have an alternate tag or a template that replaces their function with CSS. See Wikipedia:HTML5 for more details on obsolete HTML parts and their replacements.

big

<big>...</big> (obsolete) formats text in a larger font size.

Templates: {{big}} uses CSS.

center

<center>...</center> (obsolete) is used to center text elements.

Templates: {{center}} uses CSS.

font

<font>...</font> (obsolete) is used to set the font size, font face and color of text.

Templates: {{font}} uses CSS.

rb

<rb>...</rb> (obsolete) Used to mark base text in a ruby annotation

strike

<strike>...</strike> (obsolete) formats strike-through characters; use <s> instead.

tt

<tt>...</tt> (obsolete) formats text in a fixed-width font. Use <code>, <kbd> or <samp> instead.

Templates: {{mono}} uses CSS.

Unsupported elements

These elements are not supported, but have equivalent wiki markup. Attempting to use any element not whitelisted by Sanitizer.php will result in the markup showing as plain text.

a

<a> is used to create links. Use the [[ ]] wikimarkup for internal links and [ ] for external links.

input

<input> is used to create forms. The <inputbox> extension tag is used to create a text box with a button.

HTML Tidy

HTML Tidy is enabled for the English Wikipedia. Tidy parses the MediaWiki output and cleans it up to ensure that valid HTML is rendered. For example, <br>, </br>, <br/>, <br.> will all render as <br />. Tidy is not enabled for MediaWiki interface pages. Tidy is not perfect, and has been known to introduce errors.

Exceptions

In some pages in the MediaWiki namespace, typically the short messages like button labels, HTML is not parsed, and tags will be exposed.

User and sitewide CSS and JavaScript pages are interpreted as if inside a <pre> block. See Help:User style.

Validation

The MediaWiki software attempts to fix HTML errors, but it does not catch all of them. Where HTML is used, it is helpful to verify it with the W3C Markup Validation Service.

Parser and extension tags

For a machine-generated list, see Special:Version#mw-version-parser-extensiontags. It may include tags not documented here.

Parser tags
<gallery>, <includeonly>, <noinclude>, <nowiki>, <onlyinclude>, <pre>
Extension tags
<categorytree>, <charinsert>, <chem> (alias <ce>), <graph>, <hiero>, <imagemap>, <indicator>, <inputbox>, <mapframe>, <maplink>, <math>, <math chem>, <poem>, <ref>, <references>, <score>, <section>, <syntaxhighlight> (alias <source>), <templatedata>, <templatestyles>, <timeline>

See also

References

  1. ^ a b Allowable elements and attributes are defined in the Sanitizer.php module.
  2. ^ "The microdata model". HTML Living Standard.
  3. ^ "HTML5: A vocabulary and associated APIs for HTML and XHTML: Obsolete Features". W3C. 31 July 2014.