<!DOCTYPE html><html><head><metacharset="utf-8"/><title>MathML display attribute</title><linkrel="help"href="https://w3c.github.io/mathml-core/#css-styling"><linkrel="help"href="https://w3c.github.io/mathml-core/#the-top-level-math-element"><linkrel="help"href="https://w3c.github.io/mathml-core/#dom-and-javascript"><metaname="assert"content="Verify that the display attribute on the math element is supported and impacts centering and line breaking with surrounding content."><scriptsrc="/resources/testharness.js"></script><scriptsrc="/resources/testharnessreport.js"></script><scriptsrc="/mathml/support/feature-detection.js"></script><scriptsrc="/mathml/support/attribute-values.js"></script><script>functiongetBox(aId){returndocument.getElementById(aId).getBoundingClientRect();}window.addEventListener("DOMContentLoaded",function(){for(transforminAttributeValueTransforms){TransformAttributeValues(transform,["display"]);varcontent=getBox("content");varbefore_block=getBox("before_block");varmspace_block=getBox("mspace_block");varafter_block=getBox("after_block");test(function(){assert_true(MathMLFeatureDetection.has_mspace());assert_approx_equals(before_block.left,content.left,1,"content before must be left aligned");assert_approx_equals((mspace_block.left+mspace_block.right)/2,(content.left+content.right)/2,1,"math must be centered.");assert_approx_equals(after_block.left,content.left,1,"content after must be left aligned");assert_less_than_equal(before_block.bottom,mspace_block.top,"new line before math");assert_less_than_equal(mspace_block.bottom,after_block.top,"new line after math");},`Test display math ${transform}`);varbefore_inline=getBox("before_inline");varmspace_inline=getBox("mspace_inline");varafter_inline=getBox("after_inline");test(function(){assert_true(MathMLFeatureDetection.has_mspace());assert_approx_equals((before_inline.top+before_inline.bottom)/2,(mspace_inline.top+mspace_inline.bottom)/2,1,"content before must be horizontally aligned with math");assert_approx_equals((after_inline.top+after_inline.bottom)/2,(mspace_inline.top+mspace_inline.bottom)/2,1,"content after must be horizontally aligned with math");assert_less_than_equal(before_inline.right,mspace_inline.left,"content before must be on the left of math");assert_less_than_equal(mspace_inline.right,after_inline.left,"content after must be on the right of math");},`Test inline math ${transform}`);varbefore_block_and_specified_width=getBox("before_block_and_specified_width");varmspace_width=getBox("mspace_width");varafter_block_and_specified_width=getBox("after_block_and_specified_width");test(function(){assert_true(MathMLFeatureDetection.has_mspace());letmath=getBox("math_with_specified_width");assert_approx_equals(before_block_and_specified_width.left,math.left,1,"content before must be left aligned");assert_approx_equals(math.width,100,1,"math uses specified width.");assert_approx_equals((mspace_width.left+mspace_width.right)/2,(math.left+math.right)/2,1,"math must be centered.");assert_approx_equals(after_block_and_specified_width.left,math.left,1,"content after must be left aligned");assert_less_than_equal(before_block_and_specified_width.bottom,mspace_width.top,"new line before math");assert_less_than_equal(mspace_width.bottom,after_block_and_specified_width.top,"new line after math");},`Test width on display=block math ${transform}`);}test(function(){assert_true(MathMLFeatureDetection.has_mspace());document.getElementById("mspace_dynamic_block").parentNode.setAttribute("display","block");varbefore_block=getBox("before_dynamic_block");varmspace_block=getBox("mspace_dynamic_block");varafter_block=getBox("after_dynamic_block");assert_true(MathMLFeatureDetection.has_mspace());assert_approx_equals(before_block.left,content.left,1,"content before must be left aligned");assert_approx_equals((mspace_block.left+mspace_block.right)/2,(content.left+content.right)/2,1,"math must be centered.");assert_approx_equals(after_block.left,content.left,1,"content after must be left aligned");assert_less_than_equal(before_block.bottom,mspace_block.top,"new line before math");assert_less_than_equal(mspace_block.bottom,after_block.top,"new line after math");},"Test dynamically setting display=block");test(function(){assert_true(MathMLFeatureDetection.has_mspace());document.getElementById("mspace_dynamic_inline").parentNode.removeAttribute("display");varbefore_inline=getBox("before_dynamic_inline");varmspace_inline=getBox("mspace_dynamic_inline");varafter_inline=getBox("after_dynamic_inline");assert_true(MathMLFeatureDetection.has_mspace());assert_approx_equals((before_inline.top+before_inline.bottom)/2,(mspace_inline.top+mspace_inline.bottom)/2,1,"content before must be horizontally aligned with math");assert_approx_equals((after_inline.top+after_inline.bottom)/2,(mspace_inline.top+mspace_inline.bottom)/2,1,"content after must be horizontally aligned with math");assert_less_than_equal(before_inline.right,mspace_inline.left,"content before must be on the left of math");assert_less_than_equal(mspace_inline.right,after_inline.left,"content after must be on the right of math");},"Test dynamically setting display=inline");done();});</script><style>#content{width:600px;background:#ccc;}span.square{display:inline-block;width:50px;height:50px;background:black;}mspace{background:blue;}</style></head><body><divid="log"></div><divid="content"><spanid="before_block"class="square"></span><mathdisplay="block"><mspaceid="mspace_block"width="50px"height="50px"/></math><spanid="after_block"class="square"></span><br/><spanid="before_inline"class="square"></span><mathdisplay="inline"><mspaceid="mspace_inline"width="50px"height="50px"/></math><spanid="after_inline"class="square"></span><br/><spanid="before_block_and_specified_width"class="square"></span><mathdisplay="block"id="math_with_specified_width"style="background: pink; width:100px"><mspaceid="mspace_width"width="50px"height="50px"/></math><spanid="after_block_and_specified_width"class="square"></span><br/><div><spanid="before_dynamic_block"class="square"></span><math><mspaceid="mspace_dynamic_block"width="50px"height="50px"/></math><spanid="after_dynamic_block"class="square"></span></div><div><spanid="before_dynamic_inline"class="square"></span><mathdisplay="block"><mspaceid="mspace_dynamic_inline"width="50px"height="50px"/></math><spanid="after_dynamic_inline"class="square"></span></div></div></body></html>