Help:HTML in wikitext

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search

Template:Short description Template:Pp-semi-indef

Script error: No such module "redirect hatnote".Script error: No such module "For".Template:Locutions pages header Template:Wikipedia how to

Template:Wiki markup Script error: No such module "Sidebar".

The MediaWiki software, which drives Wikipedia, allows the use of a subset of HTML 5 elements, or tags and their attributes, for presentation formatting.Template:R However, most HTML functionality can be replicated using equivalent wiki markup or templates. These alternatives are generally preferred within articles because they are often simpler for most editors to use and less intrusive in the editing interface. Wikipedia's Manual of Style recommends when and where these alternatives should be used. (See Help:Wikitext for wikitext equivalents to HTML tags not otherwise discussed below.)

HTML can also be useful outside articles, such as for formatting within templates. For assistance with using Cascading Style Sheets on Wikipedia, see Help:Cascading Style Sheets.

Some tags that resemble HTML are actually MediaWiki parser and extension tags, and so are actually wiki markup. HTML included in pages can be validated for HTML5 compliance by using validation. Note that some elements and attributes supported by MediaWiki and browsers have been deprecated by HTML5 and should no longer be used.Template:TOC limit

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 MediaWikiTemplate:R:

  • 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:Template:R

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

Other tags such as Template:Tag support specific attributes – these are listed in the appropriate section.

Template:Markup

The MediaWiki Template: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

Template:See The Template:Tag through Template:Tag tags are headings for the sections with which they are associated. Template:Tag is used for the article title. Headings are styled through CSS and added to the page's table of contents.

Template:Markup

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

Template:Markup

Templates: Template:Tlx for use in documentation

p

Template:Tag tag places content into a separate paragraph.

Template:Markup

Wikimarkup: Separate paragraphs by a single blank line.

Template:Markup

Template:Tag is especially useful in lists, for list items with multiple paragraphs:

Template:Markup

Note that the closing tag Template:Tag is not strictly necessary for MediaWiki installations that output HTML 5 (such as Wikipedia).

br

Template:See Template:Tag inserts a line break. See H:BR for the other 4 versions that the MediaWiki software converts to Template:Tag in the HTML that browsers read.

Template:Markup

Templates:

hr

Template:See Template:Tag or Template:Tag represents a paragraph-level thematic break and presents as a horizontal rule.

Template:Markup

Wikimarkup: use ---- Template:Markup

Templates: Template:Tlx

Comments

Template:See Template:Tag formats the enclosed text as a hidden comment.

Template:Markup

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:

Template:Markup

Formatting

abbr

Template:Tag creates a tooltip to define an abbreviation or acronym that is displayed on mouse-over.

Template:Markup

Templates: Template:Tlx

b

Template:See Template:Tag formats text stylistically offset from other text (bold) without conveying extra importance.

Template:Markup

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

Template:Markup

bdi

Template:Tag isolates the content from the surrounding text-direction settings.

Template:Markup

Support: Firefox, Chrome

bdo

Template:Tag specifies the text direction.

Attributes and values:

  • dir – Specifies the text direction.
    • ltr
    • rtl

Template:Markup

blockquote

Template:See Template:Tag presents text in an offset block.

Template:Markup

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

cite

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

Template:Markup

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

code

Template:Tag formats a section of computer code. Styled with CSS through Template:MediaWiki source as a black monospaced typeface with a grey background (#F8F9FA) and border (#EAECF0).

Template:Markup

Templates: Template:Tlx uses Template:Xtag. See the "See also" section at the template page for additional code-markup templates.

See Template:Section link and Template:Section link on this page for semantic markup of output and input, respectively.

data

Template:Tag formats a machine-readable version of contents.

Template:Markup

Attributes: value

del

Template:Tag formats deleted text.

Template:Markup

dfn

Template:Tag is used for indicating the defining instance of a term.

Template:Markup

Templates: Template:Tlx

em

Template:See Template:Tag represents a span of text with emphatic stress (i.e. semantic emphasis). In most browsers, it renders as italic.

Template:Markup

Templates: Template:Tlx

i

Template:See Template:Tag 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.

Template:Markup

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

ins

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

Template:Markup

kbd

Template:Tag indicates user input such as keyboard input or voice commands (but no Template:Kbd as with the template Template:Tlx).

Template:Markup

Templates:

mark

Template:Tag represents a run of text in one document marked or highlighted for reference purposes, due to its relevance in another context. Marked text is formatted with a yellow background by default.

Template:Markup

Support: Not supported by Internet Explorer 8 and below.

pre

Template:Tag element represents a block of preformatted text. In MediaWiki, Template:Xtag is actually a parser tag and not HTML, but the function is the same. It also prevents the parsing of templates.

Template:Markup

HTML entities

Template:Tag parses HTML entities. If you want to escape this, replace & with &, or use Template:Xtag instead.

Template:Markup

Templates:

q

Template:Tag is used to mark a short quotation. There has been very little implementation of this element in Wikipedia yet.

Template:Markup

MOS:QUOTATIONS says Wikipedia should instead use "", Template:Tl, or <blockquote>.

rp, rt, ruby

Template:See

Template:Tag marks spans of phrasing content with ruby annotations.

  • Template:Tag marks the ruby text component of a ruby annotation; the ruby text shows in a reduced size over top of the normal characters.
  • Template:Tag is used to provide parentheses around a ruby text component of a ruby annotation, to be shown by user agents that don't support ruby annotations.

Browsers that do not support ruby characters will show the ruby text in normal size, enclosed in parentheses and after the normal content.

Template:Markup

Templates:

s

Template:Tag is used to indicate inline content that is no longer accurate or relevant and that has been struck from the page. It is not appropriate when indicating document edits; to mark a span of text as having been removed from a document, use Template:Tag.

Template:Markup

Templates: Template:Tlx (for inline content), Template:Tlx (for block content)

samp

Template:Tag indicates sample output from a program or computing system. Examples include: output of a program, script, or Wikipedia template; status displays or audio announcements made by an app or device; file system directory listings and samples from them, such as paths and file names.

Template:Markup

Templates: Template:Tlx applies monospace styling, and gives the text in dark grey to distinguish from code (Template:Tag) and input (Template:Tag or Template:Tlx).

small

Template:See Template:Tag format small text.

Template:Markup

Templates:

strong

Template:Tag formats a span of text with strong importance or unusual emphasis; in most browsers it renders as boldface. This should generally not be used in Wikipedia articles, per WP:Neutral point of view policy. See MOS:BOLD on use of this element and other boldfacing. Most semantic emphasis, including in quoted material, should be rendered with the Template:Tag element.

Template:Markup

Templates: Template:Tlx

sub

Template:See Template:Tag formats a span of text as a subscript.

Template:Markup

Templates:Template:Hlist

sup

Template:See Template:Tag formats a span of text as a superscript.

Template:Markup

Templates:

  1. redirect Template:Smallsub text)

time

Template:Tag defines either a time (24 hour clock), or a date in the Gregorian calendar, optionally with a time and a time-zone offset.

Template:Markup

Attributes: datetime

Support: Not supported by Internet Explorer 8 and below.

u

Template:See Template:Tag 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 underlining; for example, a span of text in Chinese that is a proper name (a Chinese proper name mark), or span of text that is known to be misspelled.

Template:Tag was presentational element of HTML that was originally used to underline text; this usage was deprecated in HTML4 in favor of the CSS style {text-decoration: underline}.[1] In HTML5, the tag reappeared but its meaning was changed significantly: it now "represents a span of inline text which should be rendered in a way that indicates that it has a non-textual annotation".[1] This facility is intended for example to provide a red wavy line underline to flag spelling errors at input time but which are not to be embedded in any stored file (unlike an emphasis mark, which would be).

Template:Markup

Templates: Template:Tlx (which supplies the recommended CSS style)

var

Template:See Template:Tag formats text in italics to indicate a variable in a mathematical expression or programming context, or placeholder text that the reader is meant to mentally replace with some other literal value.

Template:Markup

Templates:

wbr

Template:See Template:Tag is a word break opportunity; that is, it specifies where it would be OK to add a line-break where a word is too long, or it is perceived that the browser will break a line at the wrong place.

Template:Markup

As the browser window is adjusted narrower, the second example wraps between Hyper and Text.

Lists

Template:See

Do not leave blank lines between items in a list unless there is a reason to do so, since this causes the MediaWiki software to interpret each item as beginning a new list.

dl, dt, dd

Template:Tag, Template:Tag and Template:Tag are used to create a description list (formerly definition list) with terms and descriptions. Terms are displayed in bold and descriptions are indented. Each term must include one or more descriptions.

Template:Markup

Wikimarkup: Template:Tag is created using ; while automatically enclosed in Template:Tag. Template:Tag is created using : for each value. For a single or first value the : can be placed on the same line after ; where subsequent values must be placed on separate lines.

Template:Markup

Templates: Template:Tlx

ol, ul, li

Template:Tag represents an ordered list; Template:Tag represents an unordered list; Template:Tag represents a list item within either type of list.

Template:Markup

Wikimarkup: use * for items in an unordered list and # for ordered lists. Template:Markup

Templates: for a variety of specialized uses, see Category:List formatting and function templates.

Containers

div

Template:See Template:Tag is a generic container for flow content that displays as a block element.

Template:Markup

span

Template:See Template:Tag is a container for flow content that displays as an inline element.

Template:Markup

Tables

Template:See

table, td, tr

Template:Tag defines a table.

  • Template:Tag defines a table row.
  • Template:Tag defines a data cell with contents that may include text, links, images, lists, forms, other tables, etc.

Template:Markup

Attributes:

  • Template:Tag:
    Allowed but not recommended: border="" and border="1"
    Allowed but obsolete: border (with a non-empty value different from "1"), align, bgcolor, cellpadding, cellspacing, frame, rules, summary, width[2]
  • Template:Tag: colspan, headers, rowspan
    Allowed but obsolete: abbr, align, axis, bgcolor, scope, height, nowrap, valign, width[2]

th

Template:Tag defines a table header; styled as centered and bold.

Template:Markup

Attributes:

  • Template:Tag: colspan, headers, rowspan, scope
    Allowed but obsolete: abbr, align, axis, bgcolor, height, nowrap, valign, width[2]

caption

Template:Tag adds a caption to a table.

Template:Markup

Attributes:

thead, tfoot, tbody

Template:Tag, Template:Tag and Template:Tag are not supported, but are automatically generated when the page is rendered.

Obsolete/deprecated elements

Script error: No such module "Labelled list hatnote". These elements are now obsolete and either deprecated or removed in HTML5, although they are still supported by browsers.[2] Their use should be avoided on Wikipedia. These tags either have an alternate tag or a template that replaces their function with CSS; the tags are being replaced by editors on pages throughout Wikipedia (see Wikipedia:Linter for more details). See Template:Slink for more details on obsolete HTML parts and their replacements.

center

Script error: No such module "For". Template:Dc was used to center text elements.

Templates: Template:Tlx uses CSS.

font

Template:Dc was used to set the font size, font face and color of text.

Templates: Template:Tlx uses CSS.

rb

Template:Dc was used to mark base text in a ruby annotation.

For replacements, see: Help:HTML in wikitext#rp, rt, ruby

strike

Template:Dc formatted strike-through characters; use Template:Tag or Template:Tag instead, depending on the context.

tt

Template:Dc formatted text in a fixed-width font. Use Template:Tag, Template:Tag, Template:Tag, or Template:Tag instead, depending on the context.

Templates: Template:Tlx uses CSS.

Unsupported elements

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

a

Script error: No such module "labelled list hatnote". Template:Tag is used to create links. Use the [[ ]] wikimarkup for internal/intrawiki links and interwiki links, and [ ] for external links.

input

Script error: No such module "labelled list hatnote". Template:Tag is used to create forms. The Template:Xtag extension tag is used to create a text box with a button.

HTML Tidy

HTML Tidy is an outdated HTML4 libraryTemplate:Vague that is slated for removal. Tidy parses the MediaWiki output and cleans it up to increase the likelihood that valid HTML4 is rendered. For example, with Tidy enabled, Template:Tag, Template:Tag, Template:Tag, Template:Tag all rendered as Template:Tag. Tidy is not enabled for MediaWiki interface pages. Tidy was never 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 Template:Tag block. See Help:User style.

Validation

Script error: No such module "Labelled list hatnote". 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

Script error: No such module "Shortcut". {{#section:Template:Xtag/doc|xtag}}

See also

References

Template:Reflist

External links

Template:Wikipedia directories Template:Wikipedia editor navigation

  1. a b Script error: No such module "citation/CS1".
  2. a b c d e Cite error: Invalid <ref> tag; no text was provided for refs named w3c_obsolete