HTML Reference Β· Embedded Content
The <math> element
Reference for the <math> element: writing MathML formulas inside HTML, the display attribute, common child elements, accessibility notes and technical details.
The <math> element is the root of a MathML formula. Everything inside it is MathML, a markup language for mathematics, so the browser lays out fractions, roots, exponents and matrices with real typesetting rules instead of images. The formula stays text: it scales with zoom, can be copied, and is read by screen readers.
You write <math> straight into HTML; the parser switches to the MathML namespace automatically, so no xmlns is needed.
<p>The area of a circle is <math><mi>A</mi><mo>=</mo><mi>Ο</mi><msup><mi>r</mi><mn>2</mn></msup></math>.</p>
Try it
<mi> marks identifiers (variables), <mn> numbers and <mo> operators. <mrow> groups items, and layout elements such as <mfrac>, <msqrt> and <msup> take a fixed number of children.
Attributes
| Attribute | Values | Description |
|---|---|---|
display |
inline (default), block |
block renders the formula on its own centered line in display style (larger operators, limits above and below). inline keeps it in the flow of the text. |
displaystyle |
true, false |
Overrides whether the content uses display style, independently of display. |
scriptlevel |
Integer, or +n/-n |
Sets or adjusts the script level, which controls the font size used for scripts. |
mathcolor |
CSS color | Text color. Prefer CSS color. |
mathbackground |
CSS color | Background color. Prefer CSS background. |
mathsize |
CSS length | Font size. Prefer CSS font-size. |
dir |
ltr, rtl |
The direction of the formula's layout. |
<math> also takes the attributes that every MathML element shares, including class, id, style, tabindex, autofocus, nonce, data-* and the event handler attributes. Older MathML attributes such as alttext, altimg and mode are not part of MathML Core, the version browsers implement.
Usage notes
- Common children.
<mi>,<mn>,<mo>,<mtext>(tokens);<mrow>(grouping);<mfrac>,<msqrt>,<mroot>(fractions and roots);<msub>,<msup>,<msubsup>,<munder>,<mover>,<munderover>(scripts and limits);<mtable>,<mtr>,<mtd>(matrices);<mspace>,<mpadded>,<mphantom>(spacing). - Inline vs. block. Use
display="block"for formulas that stand alone between paragraphs, and leave it out for formulas inside a sentence. - Use real characters. Write
β(U+2212 minus),Γ,β€andΟas characters or entities rather than a hyphen or the letter "x". - Accessibility. The implicit role is
math, and screen readers with MathML support read the structure ("x equals fractionβ¦"). Support varies, so for an important formula consider a short explanation in the surrounding text. - Authoring. Writing MathML by hand is verbose. Many sites write LaTeX and convert it to MathML at build time, so the page ships plain MathML with no client-side library.
- Styling. MathML elements accept CSS.
math { font-family: math; }uses the system's math font, which gives the best layout.
Technical summary
| Content categories | Flow content, phrasing content, embedded content, palpable content |
| Permitted content | MathML presentation markup, as defined by MathML Core |
| Tag omission | None; both the start and end tags are required |
| Permitted parents | Any element that accepts phrasing content |
| Implicit ARIA role | math |
| DOM interface | MathMLElement |
| Default display | inline math; block math with display="block" |
Browser support
MathML Core is supported in all current browsers (Baseline since 2023, when Chromium added it). Very old browsers show the formula's characters as plain text in a row.