# `<math>`

> The `<math>` HTML element is the top-level element of MathML used to display mathematical formulas.

## How do I write math formulas in HTML with MathML?

The top-level element of MathML that embeds mathematical notation directly in HTML. Formulas are rendered natively by the browser, stay accessible to screen readers and scale with text without using images or third-party libraries.

- Topic: Scripting & Embedded Languages
- Type: tag
- Browser support: Chrome 109+, Chrome Android 109+, Edge 109+, Firefox 4+, Firefox Android 4+, Safari 5.1+, Safari iOS 5+

## Example

Wrong:

```html
<math>
  x^2 + 1
</math>
```

Right:

```html
<math>
  <msup><mi>x</mi><mn>2</mn></msup>
  <mo>+</mo>
  <mn>1</mn>
</math>
```

MathML elements mark the base, exponent and operator, so the formula renders and reads correctly.

## Common mistakes

- Writing the formula as plain text inside `<math>` without `<mi>`, `<mn>` and `<mo>`.

## Key points

- Formulas are written in MathML, not as images of text.
- Standalone formulas use `display='block'`, inline ones use the default.
- Variables use `<mi>`, numbers use `<mn>` and operators use `<mo>`.

## Interview questions

### Do I need a library to show MathML?

No. Browsers in the support table render MathML natively. Libraries are only needed to convert other formats.

### How do I write a fraction in MathML?

Use `<mfrac>` with two children: the numerator first, then the denominator.

## Related cards

- [math](https://wonderium.dev/a11y/math.md)
- [`<svg>`](https://wonderium.dev/html/svg.md)
- [`<sup>`](https://wonderium.dev/html/sup.md)
- [`<sub>`](https://wonderium.dev/html/sub.md)

---

- Level: [HTML](https://wonderium.dev/html.md)
- HTML version: https://wonderium.dev/html/math
- Last updated: 2026-11-25
