HTML5 MathML
HTML5 MathML <mn> Tag
The <mn> element represents a numeric literal - an integer, decimal or any run of digits treated as a single number. Numbers are rendered upright, distinct from italic identifiers.
Definition and Usage
Wrap each number in its own <mn> so the browser spaces and styles it correctly. Decimal points, digit groups and even numbers in other bases can appear inside <mn>. Keep operators like the minus sign in <mo>, not <mn>.
Syntax
Example
<mn>42</mn>
<mn>3.14159</mn>Attributes
| Attribute | Description |
|---|---|
| mathvariant | Style such as normal, bold or double-struck. |
| mathsize | Font size of the number. |
| mathcolor | Text colour of the number. |
| mathbackground | Background colour behind the number. |
Example
Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>MathML mn</title>
</head>
<body>
<math display="block">
<mrow>
<mi>π</mi>
<mo>≈</mo>
<mn>3.14159</mn>
</mrow>
</math>
</body>
</html>💡
Use a separate <mo> for a leading minus sign - <mo>-</mo><mn>5</mn> - so it is treated as an operator, not part of the number.
Key Takeaways
- <mn> holds a numeric literal and renders it upright.
- Each number gets its own <mn>; operators stay in <mo>.
- mathvariant and mathsize adjust the appearance.
