Home / Learn HTML / HTML MathML: Maths Formulas

HTML MathML: Maths Formulas

Write fractions, powers, roots and matrices as real HTML. No images and no extra library.

In shortWrap a formula in and build it from small tags like and .

Theory in plain words

A fractionmi ami bmfracmath
A fraction

What it is

MathML writes mathematical formulas as real HTML-like elements.

Why we use it

Formulas stay sharp, can be read by screen readers and copied as text.

How it works

Elements such as mfrac, msup and msqrt describe the formula and the browser draws it.

Where it is used

  • Science and school sites
  • Documentation with formulas

What is MathML?

MathML is a set of HTML tags for maths. The browser draws the formula, so it stays sharp, can be selected and is read by screen readers. All modern browsers support it.

A first formulaTry it Yourself

mi is an identifier (a letter), mo is an operator, mn is a number.

TagMeaning
<math>Wraps the formula. Use display="block" for a big centred formula.
<mi>A variable or name, for example x
<mn>A number
<mo>An operator: + - = ( )
<mrow>Groups parts together
<mfrac>Fraction: top, then bottom
<msup> <msub>Power and subscript
<msqrt> <mroot>Square root and n-th root
<munderover>Limits, for example a sum
<mtable>Table or matrix

Fractions, powers and roots

Fraction and powerTry it Yourself

mfrac takes exactly two children: top and bottom.

The quadratic formulaTry it Yourself

mrow groups the top and the bottom so the fraction reads correctly.

Sums and matrices

A sumTry it Yourself
A matrixTry it Yourself

mtr is a row and mtd is a cell, like a table.

Tip:Style it with CSS: math { font-size: 1.4em; color: #0b6e4f; }. For an image or screen-reader fallback add aria-label on the math tag when the formula is complex.
Careful:Writing long formulas by hand is slow. Many tools can convert LaTeX to MathML. Paste the result into your page.

Quick quiz

1. Which tag draws a fraction in MathML?

2. What does the mi tag hold?

3. Which tag groups parts of a formula together?

Common questions

Which tag draws a fraction in MathML?

<mfrac>. mfrac takes two children: the top and the bottom.

What does the mi tag hold?

An identifier such as x. mn is a number and mo is an operator.

Which tag groups parts of a formula together?

<mrow>. mrow groups children so they act as one unit.

My notes
Ask a question about this lesson