MyInternships.in

HTML5 MathML

HTML5 MathML mathbackground Attribute

The mathbackground attribute sets the background colour behind a MathML element and its content. It accepts any CSS colour value and is handy for highlighting part of a formula.


Definition and Usage

Apply mathbackground to most MathML elements - from the whole <math> root down to a single <mi> - to paint a colour behind them. Values may be named colours (yellow), hex (#ffff00), rgb() or transparent.

Syntax

Setting a background colour
Example
<mn mathbackground="yellow">5</mn>

Example

This highlights a term by giving it a coloured background.

Highlighting a term
Example
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>MathML mathbackground</title>
</head>
<body>
  <math display="block">
    <mrow>
      <mi>a</mi><mo>+</mo>
      <mn mathbackground="#fff2ac">2</mn>
      <mo>+</mo><mi>b</mi>
    </mrow>
  </math>
</body>
</html>
💡

In MathML Core you can also use the CSS background property, which behaves consistently with the rest of the page's styling.

Key Takeaways

  • mathbackground sets the background colour of an element.
  • It accepts named, hex, rgb() and transparent values.
  • The CSS background property is a modern alternative.

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