CSS math-style Property

The CSS math-style property controls whether mathematical expressions use normal or compact layout styling.

It is primarily used with MathML to adjust the presentation of fractions, operators, and other mathematical structures. The property accepts normal and compact, allowing mathematical notation to adapt to the available space without changing its underlying meaning.

math-style Syntax

The math-style property accepts one keyword that selects the mathematical layout style.

Basic Syntax

selector {
  math-style: normal;
}

Compact Mathematical Style

math {
  math-style: compact;
}

Target a Specific Expression

.compact-math {
  math-style: compact;
}

CSS-Wide Keywords

math {
  math-style: initial;
}
math {
  math-style: inherit;
}
math {
  math-style: unset;
}
math {
  math-style: revert;
}
math {
  math-style: revert-layer;
}

The initial value is normal. The property is inherited, allowing descendants to use the same mathematical style unless another declaration overrides it.

Property Values

Value Description
normal Uses normal mathematical layout, allowing display-style formatting for structures such as fractions and large operators. This is the initial value.
compact Uses a more compact mathematical layout, particularly for fractions and operators that support different presentation styles.
initial Resets the property to normal.
inherit Uses the computed value from the parent element.
unset Acts like inherit because the property is inherited.
revert Reverts the property according to cascade origin rules.
revert-layer Reverts the property according to cascade layer rules.

Property Characteristics

Characteristic Value
Initial value normal
Inherited Yes
Applies to All elements
Computed value As specified
Animation type Discrete
Accepted values normal, compact, and CSS-wide keywords
Primary use Mathematical layout, particularly MathML

How It Works

Mathematical notation often requires different layouts depending on where an expression appears. A fraction displayed on its own can use more vertical space than the same fraction embedded within a line of text.

The math-style property allows the browser to select the appropriate mathematical layout style.

Normal Mathematical Layout

math {
  math-style: normal;
}

The browser uses normal mathematical formatting, which can include taller fractions and larger operators.

Compact Mathematical Layout

math {
  math-style: compact;
}

The browser uses compact mathematical formatting where supported by the mathematical structure. This can reduce the vertical space required by fractions and certain operators.

Mathematical Structure

The property changes presentation, not the mathematical meaning or the underlying MathML markup.

Inherited Styling

math {
  math-style: compact;
}
math .display-expression {
  math-style: normal;
}

Descendants normally inherit the compact value, but the targeted expression uses normal styling.

Important Consideration

Not every MathML element has a visibly different normal and compact appearance. The effect depends on the mathematical structure, browser, and available font metrics.

normal Value

The normal value selects normal mathematical layout. It is the initial value of the property.

Basic Example

math {
  math-style: normal;
}

MathML Fraction

<math xmlns="http://www.w3.org/1998/Math/MathML" style="math-style: normal;">
  <mfrac>
    <mn>1</mn>
    <mn>2</mn>
  </mfrac>
</math>

The fraction uses normal mathematical layout, allowing the numerator and denominator to be arranged with the spacing and sizing appropriate to that style.

Reset Compact Styling

.math-container {
  math-style: compact;
}
.math-container .normal-expression {
  math-style: normal;
}

When to Use normal

Use normal for standalone mathematical expressions or when an expression should use standard display-style formatting instead of compact formatting.

An explicit declaration is generally unnecessary unless another rule or inherited style has selected compact.

compact Value

The compact value selects a space-saving mathematical layout, particularly useful for expressions embedded in text or nested inside other mathematical structures.

Basic Example

math {
  math-style: compact;
}

Compact Fraction

<math xmlns="http://www.w3.org/1998/Math/MathML" style="math-style: compact;">
  <mfrac>
    <mi>a</mi>
    <mi>b</mi>
  </mfrac>
</math>

The browser uses compact fraction formatting, which can reduce the height of the expression.

Inline Mathematical Content

p math {
  math-style: compact;
}

This rule requests compact styling for mathematical expressions inside paragraphs.

Nested Mathematical Expressions

math .nested-expression {
  math-style: compact;
}

Compact styling can help nested mathematical content fit within the surrounding expression.

When to Use compact

Use compact when mathematical notation needs to occupy less vertical space without changing the expression's meaning.

Important Consideration

The compact value does not simply reduce the entire expression using a fixed scale factor. It changes mathematical layout rules for structures that support compact formatting.

Fractions and Mathematical Layout

Fractions provide one of the clearest examples of how math-style affects mathematical presentation.

Normal Fraction

<math xmlns="http://www.w3.org/1998/Math/MathML" style="math-style: normal;">
  <mfrac>
    <mi>a</mi>
    <mi>b</mi>
  </mfrac>
</math>

Compact Fraction

<math xmlns="http://www.w3.org/1998/Math/MathML" style="math-style: compact;">
  <mfrac>
    <mi>a</mi>
    <mi>b</mi>
  </mfrac>
</math>

Both examples represent the same fraction. The compact version uses mathematical layout rules intended to reduce the vertical space occupied by the fraction.

Nested Fractions

<math xmlns="http://www.w3.org/1998/Math/MathML">
  <mfrac>
    <mn>1</mn>
    <mfrac>
      <mn>2</mn>
      <mn>3</mn>
    </mfrac>
  </mfrac>
</math>

Nested fractions require additional layout calculations. Browsers use mathematical styling and depth rules to determine how the inner and outer fractions should appear.

Apply Compact Styling to a Nested Fraction

math mfrac mfrac {
  math-style: compact;
}

This rule targets fractions nested directly inside another fraction and requests compact mathematical styling.

Important Consideration

MathML user-agent styles may already select compact formatting for nested expressions. Explicit CSS is most useful when overriding or customizing that behavior.

Mathematical Operators

Some mathematical operators have different forms or placement rules depending on the mathematical style.

Summation Expression

<math xmlns="http://www.w3.org/1998/Math/MathML">
  <munderover>
    <mo>&sum;</mo>
    <mi>i</mi>
    <mi>n</mi>
  </munderover>
</math>

The <munderover> element places limits below and above an operator when the mathematical layout rules call for that arrangement.

Normal Operator Styling

.normal-sum {
  math-style: normal;
}

Compact Operator Styling

.compact-sum {
  math-style: compact;
}

In compact mathematical style, certain movable limits can appear beside an operator rather than directly above and below it. Large operators may also use smaller forms.

Important Consideration

The result depends on the operator and its MathML attributes. Not all operators change appearance when math-style changes.

Relationship with math-depth

The math-depth property controls the nesting depth used for mathematical size calculations. It works alongside math-style when rendering nested expressions.

Set Mathematical Depth

math {
  math-depth: 0;
}

Increase Depth

math .nested {
  math-depth: add(1);
}

Combine Depth and Style

math .nested {
  math-depth: add(1);
  math-style: compact;
}

The first declaration increases the mathematical depth. The second selects compact mathematical formatting.

Automatic Depth Adjustment

math .nested {
  math-style: compact;
  math-depth: auto-add;
}

When math-style computes to compact, math-depth: auto-add increases the inherited mathematical depth by one.

Comparing the Properties

Property Purpose
math-style Controls normal or compact mathematical layout.
math-depth Controls mathematical depth used in sizing calculations.

Changing mathematical style does not automatically set a particular integer depth. The properties have separate computed values.

Relationship with math-shift

The math-shift property controls the vertical shift mode used for mathematical superscripts.

Normal Superscript Shift

math {
  math-shift: normal;
}

Compact Superscript Shift

math {
  math-shift: compact;
}

Combined Example

math .compact-expression {
  math-style: compact;
  math-shift: compact;
}

The first property selects compact mathematical layout. The second requests compact superscript positioning.

Comparing the Properties

Property Purpose
math-style Controls mathematical layout style.
math-shift Controls superscript vertical shift behavior.
math-depth Controls mathematical nesting depth.

Although math-style and math-shift both accept normal and compact, their effects are different.

Using math-style with MathML

MathML provides semantic markup for mathematical expressions. CSS can control their appearance without changing the mathematical structure.

Inline Mathematical Expression

<p>
  The result is
  <math xmlns="http://www.w3.org/1998/Math/MathML">
    <mfrac>
      <mn>1</mn>
      <mn>2</mn>
    </mfrac>
  </math>.
</p>

Style Inline Mathematics

p math {
  math-style: compact;
}

Compact styling can help inline fractions fit more naturally within surrounding text.

Block Mathematical Expression

<math display="block" xmlns="http://www.w3.org/1998/Math/MathML">
  <mfrac>
    <mi>a</mi>
    <mi>b</mi>
  </mfrac>
</math>

Style Block Mathematics

math[display="block"] {
  math-style: normal;
}

This rule selects normal mathematical styling for block-level MathML expressions.

Using a Class

<math class="compact-math" xmlns="http://www.w3.org/1998/Math/MathML">
  <mfrac>
    <mi>x</mi>
    <mn>3</mn>
  </mfrac>
</math>
.compact-math {
  math-style: compact;
}

Classes allow individual mathematical expressions to use different styles without affecting every MathML element on the page.

math-style Example

This example compares normal and compact mathematical styling using identical fractions and summation expressions.

HTML Example

<div class="math-style-demo">
  <div class="math-style-item">
    <p>math-style: normal</p>
    <math class="normal-math" xmlns="http://www.w3.org/1998/Math/MathML">
      <mfrac>
        <mrow><mi>a</mi><mo>+</mo><mi>b</mi></mrow>
        <mi>c</mi>
      </mfrac>
    </math>
  </div>
  <div class="math-style-item">
    <p>math-style: compact</p>
    <math class="compact-math" xmlns="http://www.w3.org/1998/Math/MathML">
      <mfrac>
        <mrow><mi>a</mi><mo>+</mo><mi>b</mi></mrow>
        <mi>c</mi>
      </mfrac>
    </math>
  </div>
  <div class="math-style-item">
    <p>Normal Summation</p>
    <math class="normal-math" xmlns="http://www.w3.org/1998/Math/MathML">
      <munderover>
        <mo>&sum;</mo>
        <mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow>
        <mi>n</mi>
      </munderover>
    </math>
  </div>
  <div class="math-style-item">
    <p>Compact Summation</p>
    <math class="compact-math" xmlns="http://www.w3.org/1998/Math/MathML">
      <munderover>
        <mo>&sum;</mo>
        <mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow>
        <mi>n</mi>
      </munderover>
    </math>
  </div>
</div>

CSS Example

.math-style-demo {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  padding: 20px;
  background-color: #f1f5f9;
}
.math-style-item {
  min-width: 0;
  min-height: 160px;
  padding: 20px;
  text-align: center;
  background-color: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
}
.math-style-item p {
  margin: 0 0 25px;
  font-weight: bold;
}
.math-style-item math {
  font-size: 30px;
}
.normal-math {
  math-style: normal;
}
.compact-math {
  math-style: compact;
}
@media (max-width: 575px) {
  .math-style-demo {
    grid-template-columns: 1fr;
  }
}
Browser Result

math-style: normal

a+b c

math-style: compact

a+b c

Normal Summation

∑ i=1 n

Compact Summation

∑ i=1 n

The normal fraction generally occupies more vertical space than the compact fraction. The summation examples demonstrate how mathematical style can affect operator sizing and limit placement.

Exact rendering depends on the browser and mathematical font. Some expressions may show smaller differences than others.

Inline Fraction Example

<p>
  The fraction
  <math class="inline-fraction" xmlns="http://www.w3.org/1998/Math/MathML">
    <mfrac>
      <mn>3</mn>
      <mn>4</mn>
    </mfrac>
  </math>
  is three quarters.
</p>
.inline-fraction {
  math-style: compact;
}

Compact mathematical styling can help the fraction fit more naturally within the surrounding paragraph.

Common Mistakes

Using an Invalid Value

math {
  math-style: small;
}

The small keyword is invalid. Use normal or compact.

Using Numeric Values

math {
  math-style: 2;
}

The property does not accept numeric values. Mathematical depth is controlled separately using math-depth.

Expecting compact to Set a Fixed Font Size

The compact value changes mathematical layout behavior. It does not directly assign a specific font-size.

Confusing math-style with math-depth

The math-style property selects normal or compact mathematical formatting. The math-depth property controls mathematical nesting depth.

Confusing math-style with math-shift

The math-shift property selects a superscript positioning mode. It does not replace the broader mathematical layout behavior of math-style.

Expecting Every Element to Change Appearance

Some MathML structures have little or no visible difference between normal and compact styles. Fractions and certain operators provide clearer examples.

Using math-style for Ordinary Text

p {
  math-style: compact;
}

Although the property applies to all elements and can be inherited, it is intended for mathematical typesetting. Use ordinary typography properties for styling paragraph text.

Ignoring Browser MathML Styles

Browsers already apply mathematical layout rules to MathML elements. Custom declarations can override those rules, so test the resulting expressions carefully.

Important Considerations

Keep the following points in mind when using math-style:

  • The property controls normal or compact mathematical layout.
  • Its initial value is normal.
  • The property is inherited.
  • It accepts normal and compact.
  • Compact styling can reduce the vertical space used by fractions and certain operators.
  • The property does not directly set the font size of an expression.
  • It does not change the semantic meaning of MathML markup.
  • It can affect operator sizing and the placement of movable limits.
  • It works with math-depth and math-shift.
  • The math-depth: auto-add value depends on the computed mathematical style.
  • Some MathML elements may show little visible difference between the two styles.
  • Browser default styles may already apply compact formatting to nested mathematical content.
  • Mathematical font metrics can influence the final appearance.
  • Use normal styling when full mathematical display formatting is preferred.
  • Use compact styling when mathematical notation needs to fit within limited vertical space.
  • Test MathML expressions in the browsers and fonts your website supports.

Browser Support

The CSS math-style property is Baseline 2023 - Newly available. It is supported in current versions of major browsers, including Chrome, Edge, Firefox, and Safari.

Older browser versions may not recognize the property or may have incomplete MathML support. The exact appearance of compact mathematical expressions can also depend on mathematical font metrics and browser rendering behavior.

For current compatibility information, visit Can I Use? and search for math-style.

When using the property, test actual MathML fractions, operators, and nested expressions rather than relying only on whether the browser recognizes the CSS declaration.

Specifications

The math-style property is defined in the MathML Core specification.

MathML Core: math-style

The specification defines normal and compact mathematical styles and their effects on mathematical layout, including fractions and operators.

For additional documentation and examples, consult MDN Web Docs.

MDN Web Docs: math-style