MyInternships.in

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 takes numerator then denominator
Example
<mfrac>
  <mn>1</mn>   <!-- numerator -->
  <mn>2</mn>   <!-- denominator -->
</mfrac>

Attributes

AttributeDescription
linethicknessThickness of the fraction bar, e.g. 0, 1px, 2px, or medium/thick.
bevelledtrue renders a diagonal (bevelled) fraction like a/b.
numalignHorizontal alignment of the numerator (left, center, right).
denomalignHorizontal alignment of the denominator.

Example

A simple fraction
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.

A binomial coefficient with no bar
Example
<!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.

Related HTML Topics

Keep learning with these closely related tutorials.

Ready to use your HTML skills?

Find web development internships and fresher jobs across India.

Browse Web Dev Internships