大网数据广告活动
Web 标准与前端开发

`math-depth` CSS property

· 52CE 我爱测

The **`math-depth`** property describes a notion of _depth_ for each element of a mathematical formula, with respect to the top-level container of that formula. This is used to scale the computed value of the font-size of elements when `font-size: math` is applied.

The math-depth property describes a notion of depth for each element of a mathematical formula, with respect to the top-level container of that formula. This is used to scale the computed value of the font-size of elements when font-size: math is applied.

[!NOTE] font-size: math is the default for <math> elements in the MathML Core User Agent stylesheet, so it's not necessary to specify it explicitly.

Syntax

/* Keyword value */
math-depth: auto-add;

/* Relative values */
math-depth: add(2);
math-depth: add(-2);

/* Absolute value */
math-depth: 4;

/* Global values */
math-depth: inherit;
math-depth: initial;
math-depth: revert;
math-depth: revert-layer;
math-depth: unset;

Values

  • auto-add
    • : Set to the inherited math-depth plus 1 when inherited math-style is compact.
  • add(&lt;integer&gt;)
    • : Set to the inherited math-depth plus the specified integer.
  • <integer>
    • : Set to the specified integer.

Formal definition

Formal syntax

Examples

Specifying a math depth

The following example shows the effect of changing the math-depth property on the font size of subformulas. The numbers in each subformula indicate the math-depth and scale factor applied.

The first <mtext> element is used as a reference to other subformulas and has no specific styles applied. The second and third subformulas have math-depth set to auto-add and show the effect of scaling depending on the math-style.

The last two subformulas show the effect of setting math-depth to a specific value.

HTML

<p>
  <math>
    <mtext>0</mtext>

    
    <mrow style="math-style: normal">
      <mrow style="math-depth: auto-add">
        <mtext>0</mtext>
      </mrow>
    </mrow>

    
    <mrow style="math-depth: auto-add">
      <mtext>1</mtext>
    </mrow>

    <mrow style="math-depth: add(2)">
      <mtext>2</mtext>
      <mrow style="math-depth: add(-1)">
        <mtext>1</mtext>
      </mrow>
      <mrow style="math-depth: 0">
        <mtext>0</mtext>
      </mrow>
    </mrow>
  </math>
</p>
p {
  font-size: 3rem;
  margin: 1rem 0;
}

Result

Specifying_a_math_depth

Specifications

Browser compatibility

See also

  • font-size
  • math-style

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。