On this page9 sections
  1. Learning Objectives
  2. 1. The Building Blocks
  3. 2. A First Formula
  4. 3. Fractions and Roots
  5. 4. Subscripts
  6. Common Beginner Mistakes
  7. Practice Questions
  8. Practice Answers
  9. Key Takeaways

Lecture 041: MathML

Category7: Interactive Elements, Graphics & Media
Lecture041 of 048
Estimated video length8 min
TargetHTML5 · any modern browser
LevelBeginner

Fractions, powers and square roots are hard to show with plain text. MathML is a markup language for maths that works right inside HTML, and screen readers can read it aloud properly.


Learning Objectives

  • Write maths with <math> and its main elements
  • Show numbers, variables, operators, powers, fractions and roots
  • Choose between inline and block (display) formulas

1. The Building Blocks

ElementMeaningExample
<mi>Identifier (a variable)x
<mn>Number2
<mo>Operator+ = ( )
<mrow>A group(keeps parts together)
<msup>Superscriptx²
<msub>Subscriptx₁
<mfrac>Fraction½
<msqrt>Square root√x

2. A First Formula

Example

html
<p>
  The area of a circle is
  <math>
    <mi>A</mi><mo>=</mo><mi>π</mi><msup><mi>r</mi><mn>2</mn></msup>
  </math>.
</p>

<msup> takes two children: the base (r) and the power (2).


3. Fractions and Roots

Example

html
<p>
  <math display="block">
    <mi>x</mi><mo>=</mo>
    <mfrac>
      <mrow><mo>−</mo><mi>b</mi><mo>±</mo>
        <msqrt><msup><mi>b</mi><mn>2</mn></msup><mo>−</mo><mn>4</mn><mi>a</mi><mi>c</mi></msqrt>
      </mrow>
      <mrow><mn>2</mn><mi>a</mi></mrow>
    </mfrac>
  </math>
</p>
  • <mfrac> takes a numerator, then a denominator.
  • display="block" centres the formula on its own line, like in a textbook.

4. Subscripts

Example

html
<p>Water is <math><msub><mi>H</mi><mn>2</mn></msub><mi>O</mi></math>, and the first term is <math><msub><mi>a</mi><mn>1</mn></msub></math>.</p>

For simple chemistry in text, <sub> (HTML Lecture 007) is often enough; MathML shines for real formulas.


Common Beginner Mistakes

1. Wrong number of children. <mfrac> and <msup> need exactly two children. Wrap groups in <mrow>.

2. Typing operators as plain text. Put +, = and brackets in <mo> so spacing is correct.

3. Images of formulas. They can't be read aloud, searched or zoomed. Use MathML.


Practice Questions

  1. Which element wraps all MathML?
  2. Which elements are for variables, numbers and operators?
  3. Write x² in MathML.
  4. Write the fraction 3 over 4.
  5. What does display="block" do?

Practice Answers

  1. <math>
  2. <mi>, <mn> and <mo>.
  3. <math><msup><mi>x</mi><mn>2</mn></msup></math>
  4. <math><mfrac><mn>3</mn><mn>4</mn></mfrac></math>
  5. It shows the formula on its own centred line instead of inside the text.

Key Takeaways

  • <math> holds maths; <mi>, <mn>, <mo> are variables, numbers, operators.
  • <msup>, <msub>, <mfrac>, <msqrt> build powers, subscripts, fractions and roots.
  • <mrow> groups parts; display="block" gives a textbook-style formula.
  • MathML is accessible, unlike images of formulas.