HTML5 MathML
HTML5 MathML <mfrac> Tag
The <mfrac> element renders a fraction. It takes exactly two children: the first is the numerator and the second is the denominator, drawn one above the other with a horizontal bar between them.
Definition and Usage
Place two sub-expressions inside <mfrac>. Wrap multi-part numerators or denominators in <mrow> so they group correctly. The linethickness attribute controls the fraction bar and can be set to 0 to hide it (useful for binomial coefficients).
Syntax
<mfrac>
<mn>1</mn> <!-- numerator -->
<mn>2</mn> <!-- denominator -->
</mfrac>Attributes
| Attribute | Description |
|---|---|
| linethickness | Thickness of the fraction bar, e.g. 0, 1px, 2px, or medium/thick. |
| bevelled | true renders a diagonal (bevelled) fraction like a/b. |
| numalign | Horizontal alignment of the numerator (left, center, right). |
| denomalign | Horizontal alignment of the denominator. |
Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>MathML mfrac</title>
</head>
<body>
<math display="block">
<mrow>
<mi>x</mi><mo>=</mo>
<mfrac>
<mrow><mn>3</mn><mo>+</mo><mi>a</mi></mrow>
<mrow><mn>2</mn><mi>b</mi></mrow>
</mfrac>
</mrow>
</math>
</body>
</html>More Examples
Setting linethickness to 0 hides the bar - the standard way to write a binomial coefficient.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Binomial coefficient</title>
</head>
<body>
<math display="block">
<mrow>
<mo>(</mo>
<mfrac linethickness="0">
<mi>n</mi>
<mi>k</mi>
</mfrac>
<mo>)</mo>
</mrow>
</math>
</body>
</html>Nest <mfrac> inside another <mfrac> to build continued fractions. Always group multi-token parts in <mrow>.
Key Takeaways
- <mfrac> needs exactly two children: numerator then denominator.
- linethickness="0" hides the bar for binomial coefficients.
- Use <mrow> to group compound numerators and denominators.
