Skip to content
Tutorials Center
My learning

Topics

HTML Reference ยท Embedded Content

MathML elements

Reference for every MathML Core element: tokens, mrow, fractions, roots, scripts, limits and tables, with their key attributes and live formula examples.

Inside a <math> element you build a formula from small MathML elements. Token elements hold the actual characters: identifiers, numbers, operators and text. Layout elements arrange their children: a fraction puts one child over another, a superscript raises its second child, a table lines children up in rows and columns. Browsers implement MathML Core, the part of MathML listed on this page.

HTML
<math>
  <msup><mi>x</mi><mn>2</mn></msup>
  <mo>+</mo>
  <mfrac><mn>1</mn><mi>y</mi></mfrac>
</math>

Try it

Tokens: mi, mn, mo, mtext and mspace

In the second line, the left formula marks + and = with <mo>, so the browser looks them up in its operator dictionary and adds the right space around them. Marked as <mi>, the same characters are crammed together and drawn in italics.

Token elements

Element Contains Description
<mi> Text An identifier: a variable, a function name or a constant (x, sin, ฯ€). A single character is shown in italics; longer text is upright.
<mn> Text A number (3, 0.25, 1,000). Shown upright.
<mo> Text An operator, a fence or a separator (+, =, (, โˆ‘, ,). Spacing, stretching and size come from the operator dictionary and the attributes below.
<mtext> Text Ordinary text inside a formula, such as "if" or "otherwise". Spaces at its start and end are trimmed, so use <mspace> for gaps.
<ms> Text A string literal, as in programming-language expressions.
<mspace> Nothing Blank space of a given width, height and depth.

Layout elements

Element Children Description
<mrow> Any number Groups children into one horizontal row. Use it whenever a layout element needs several items in one of its slots.
<mfrac> 2: numerator, denominator A fraction.
<msqrt> Any number (an implied row) A square root.
<mroot> 2: base, index A root with an index: <mroot><mi>x</mi><mn>3</mn></mroot> is the cube root of x.
<msub> 2: base, subscript A subscript.
<msup> 2: base, superscript A superscript.
<msubsup> 3: base, subscript, superscript Both at once, aligned on top of each other.
<munder> 2: base, underscript Something directly below the base, such as a limit.
<mover> 2: base, overscript Something directly above, such as an accent or an arrow.
<munderover> 3: base, underscript, overscript Both: the limits of a sum or integral.
<mmultiscripts> Base, then sub/sup pairs, then <mprescripts/> and more pairs Scripts before and after the base, as in isotope or tensor notation. Use an empty <mrow></mrow> for a missing script.
<mtable> <mtr> rows A table, used for matrices, systems of equations and aligned steps.
<mtr> <mtd> cells A table row.
<mtd> Any number (an implied row) A table cell.
<mstyle> Any number Like <mrow>; exists to carry style attributes such as displaystyle.
<mpadded> Any number Adjusts the space around its content (width, height, depth, lspace, voffset).
<mphantom> Any number Takes up the space of its content but draws nothing; useful for alignment.
<merror> Any number Shows content as an error message (used by converters).
<semantics> A presentation child, then <annotation> or <annotation-xml> children Attaches other representations (such as the LaTeX source) to a formula. Only the first child is displayed.
<maction> Any number Legacy interactive element; MathML Core displays only its first child.

When a layout element expects a fixed number of children, each child is one slot. To put a + b in a numerator, wrap it in <mrow>; without the wrapper the fraction has too many children and won't render as intended.

Fractions and roots

linethickness="0" removes the fraction bar, which is how a binomial coefficient is written. The parentheses around it are <mo> fences inside one <mrow>, so they stretch to the height of the fraction.

Attributes

Attributes for all MathML elements

Attribute Values Description
displaystyle true, false Display style draws large operators bigger and puts limits above and below. <math display="block"> turns it on.
scriptlevel Integer, +n, -n Sets or changes the script level, which controls how much smaller scripts get.
mathcolor, mathbackground CSS color Text and background color (prefer CSS color and background).
mathsize CSS length Font size (prefer CSS font-size).
dir ltr, rtl Layout direction, for right-to-left mathematics.
class, id, style, tabindex, autofocus, nonce, data-*, on* The same as the HTML global attributes.

Element-specific attributes

Element Attribute Values Description
<mi> mathvariant normal Makes a single-character identifier upright. MathML Core supports only this value; use Unicode math letters (๐”ธ, ๐ฑ) for other styles.
<mo> form prefix, infix, postfix Which dictionary entry to use; normally guessed from the position in the row.
stretchy true, false Whether the operator stretches to the size of its row (parentheses, brackets, bars) or of its base (arrows over/under things).
symmetric true, false Whether a stretched operator grows equally above and below the math axis.
minsize, maxsize Length or percentage Limits for stretching.
lspace, rspace Length Space before and after the operator, replacing the dictionary values. lspace="0" tightens it.
largeop true, false Draw the operator larger in display style (โˆ‘, โˆซ, โˆ are large by default).
movablelimits true, false Whether limits in <munder>/<mover> move to script positions when not in display style.
fence, separator true, false Mark the operator as a fence or a separator. Mostly informational.
<mfrac> linethickness Length, percentage or 0 Thickness of the fraction bar. 0 hides it.
<mover>, <munderover> accent true, false Treats the overscript as an accent, drawn closer to the base and at full size.
<munder>, <munderover> accentunder true, false The same for the underscript.
<mspace> width, height, depth Length The size of the blank space.
<mpadded> width, height, depth, lspace, voffset Length or percentage The new box size, the space added on the left, and a vertical shift.
<mtd> columnspan, rowspan Positive integer Cell spanning, as in HTML tables.
<annotation>, <annotation-xml> encoding MIME type or name The format of the annotation, such as application/x-tex.
Scripts, limits and accents

The sum sign has movablelimits set in the operator dictionary. In a block formula the limits sit above and below it; inside a sentence they move to the side, like a subscript and superscript, so the line spacing isn't disturbed. The uranium symbol uses <mprescripts/> to put the atomic and mass numbers before the base, with empty <mrow> elements for the missing post-scripts.

Matrices and cases with mtable

The brackets and the curly brace stretch to the height of the table because each is an <mo> in the same <mrow> as the table. A brace with nothing on its right side is fine: the closing fence is simply left out. Cell alignment and padding come from CSS.

Usage notes

  • Wrap slots in <mrow>. Most rendering surprises come from a layout element with the wrong number of children.
  • Mark operators with <mo>. The browser only applies operator spacing and stretching to characters inside <mo>.
  • Use real characters. Write โˆ’ (U+2212), ร—, ยท, โ‰ค, โ†’ and โˆ‘ instead of ASCII look-alikes; the operator dictionary knows how to space them. See character entities.
  • Legacy elements and attributes. <mfenced>, <menclose>, <mlabeledtr> and table attributes such as columnalign and rowlines come from older MathML versions and are not part of MathML Core. Support is inconsistent, so use <mo> fences and CSS instead.
  • Keep the source. <semantics> with <annotation encoding="application/x-tex"> keeps the original LaTeX next to the formula; it isn't displayed but can be copied by tools.
  • Accessibility. Screen readers that support MathML read the structure ("fraction, a plus b, over 2"). For key formulas, also explain them in words in the surrounding text.

Technical summary

Permitted parents Any MathML element, starting from a <math> root
Tag omission End tags required; empty elements such as <mspace> and <mprescripts> can be self-closing (<mprescripts/>)
Implicit ARIA role None for the children; the <math> root has the role math
DOM interface MathMLElement for every element
Default display block math, meaning each element is laid out by its parent formula (<mtable> is inline-table, <mtr> is table-row, <mtd> is table-cell)

Browser support

The MathML Core elements on this page are supported in all current browsers (Baseline since 2023). Older browsers show the characters as plain inline text without layout.