Page MenuHomePhabricator

Math block with display="block" apparently displays inline on mobile
Open, Needs TriagePublicBUG REPORT

Assigned To
None
Authored By
HairyDude
Feb 8 2026, 11:23 PM
Referenced Files
F71781221: Screenshot 2026-02-10 at 01.06.10.png
Feb 10 2026, 12:08 AM
F71781202: Screenshot 2026-02-09 at 3.58.47 PM.png
Feb 9 2026, 11:59 PM
F71779341: Screenshot 2026-02-09 at 21.43.01.png
Feb 9 2026, 8:46 PM
Restricted File
Feb 9 2026, 6:13 PM
F71759388: Screenshot from 2026-02-08 23-06-43.png
Feb 8 2026, 11:23 PM

Description

The math tag with the attribute display="block" displays with CSS display set to block, and on desktop it is indented. Recently, on English Wikipedia it no longer indents and sometimes even displays on the same line as the preceding content (despite still being display:block, according to my inspector). Both behaviours are wrong. (It appears the formula displays in a span; possibly this is a change from before this issue arose when it displayed in a div, but I don't know if that's the case.)

Test case: https://en.wikipedia.org/wiki/User:Hairy_Dude/mathblock

This screenshot was taken with desktop Firefox by using the mobile preview button in the inspector, which reflects how it displays in mobile Firefox. The first example has no line break between the {{lorem}} and the opening <math> tag. The second has one line break. The first example displays on the same line as the paragraph before it (inside the same <p> element); the second has no indent. If you add a second line break (a blank line), there is a spurious <br> - under no other circumstances that I know of will a blank line in wikitext cause a <br> rather than just a paragraph break. A third line break (two blank lines) produces an empty paragraph instead, as expected.

Screenshot from 2026-02-08 23-06-43.png (868×1 px, 177 KB)

Event Timeline

Jdlrobson-WMF subscribed.

This also occurs on desktop at lower resolutions.
The .mwe-math-element-block element is a SPAN so is inline by default.

{F71776963}

Physikerwelt subscribed.

Per https://phabricator.wikimedia.org/T182041 it needs to be a span and it renders correctly on desktop. So I don’t know if anything can be done from within Math extension code, except for removing images entirely.

Screenshot 2026-02-09 at 21.43.01.png (2×1 px, 452 KB)

Screenshot on mobile in desktop mode.

Per https://phabricator.wikimedia.org/T182041 it needs to be a span and it renders correctly on desktop.

Your screenshot shows the DESKTOP site on a mobile device. I am testing in a resized browser window viewing it at 720px to get the desired effect and I have the tools menu closed on the right (which appears to be open in your example suggesting). Note on a mobile device, Vector 2022 forces itself into a desktop rendering mode.

So I don’t know if anything can be done from within Math extension code, except for removing images entirely.

The markup is identical on mobile to desktop. MobileFrontend doesn't touch the CSS or HTML.

@Jdlrobson-WMF thank you for the clarification.
In the CSS there is display: inline-block, which seems to come from I0780e6c4bc5a6da636d194ea22a9edf34b98ce1b

In the CSS there is display: inline-block, which seems to come from I0780e6c4bc5a6da636d194ea22a9edf34b98ce1b

span.mwe-math-element.mwe-math-element-block seems to be defaulting as inline and mwe-math-mathml-display the child is block. For the overflow to work the block needs to be on mwe-math-element

Perhaps this needs to change to

span.mwe-math-element.mwe-math-element-block {
    display: block;
}

@Jdlrobson-WMF do you mean

@import 'mediawiki.skin.defaults.less';

/* [[phab:T201233]] */
@media ( max-width: @max-width-breakpoint-tablet ) {
	.mwe-math-element-block,
	dd .mwe-math-element-inline {
		overflow-x: auto;
		vertical-align: middle;
		max-width: 100%;
	}
}
/* [[phab:T416809]] */
@media ( max-width: @max-width-breakpoint-tablet ) {
	dd .mwe-math-element-inline {
		display: inline-block;
	}
}

That should only touch the display attribute, of inline elements.

No, I mean:

@import 'mediawiki.skin.defaults.less';

/* [[phab:T201233]] */
@media ( max-width: @max-width-breakpoint-tablet ) {
	.mwe-math-element-block,
	dd .mwe-math-element-inline {
		overflow-x: auto;
		vertical-align: middle;
		max-width: 100%;
	}
}
/* [[phab:T416809]] */
@media ( max-width: @max-width-breakpoint-tablet ) {
	dd .mwe-math-element-inline {
		display: inline-block;
	}
	.mwe-math-element-block {
		display: block;
	}
}

Your code wouldn't work for the fallback display (mwe-math-fallback-image-display) as span.mwe-math-element-block would confusingly render as an inline element.

Note, if we could move the img tag to a child of mwe-math-mathml-display or have a common parent element, then we could move the rules to that element if it's important to keep .mwe-math-element inline.

I tested that quite a bit and still don't understand when we would need

	.mwe-math-element-block {
		display: block;
	}

MathML sets the attribute display explicitly in the HTML output and fallback images set it via css.

Change #1238057 had a related patch set uploaded (by Physikerwelt; author: Physikerwelt):

[mediawiki/extensions/Math@master] Don't overwrite the display attribute of block rendering

https://gerrit.wikimedia.org/r/1238057

Hopefully i clarified on Gerrit but you need to add this test case https://en.wikipedia.beta.wmcloud.org/wiki/T416809 and ensure you are not introducing horizontal scrolling to the whole page like so:

Screenshot 2026-02-09 at 3.58.47 PM.png (337×371 px, 24 KB)

Ok, I think I get the idea. However, what I currently see (without any change) are no scroll bars in MathML

Screenshot 2026-02-10 at 01.06.10.png (672×572 px, 82 KB)

(screenshot with safari in responsive design mode, as I could not convince FF to make the window small enough:-)

note that mathml renders to SVG and native (the default in beta) renders to MathML. I know it's a bit confusing.

Yeh the rule is intended to cover all different renderings. It would be a lot less confusing once MathML is default :-) Thanks for your patience with me :)

Change #1238057 merged by jenkins-bot:

[mediawiki/extensions/Math@master] Don't overwrite the display attribute of block rendering

https://gerrit.wikimedia.org/r/1238057

I note that the linked change log mentions math formatted as

:<math>e^{i\pi}+1=0</math>

This is an abuse of description list markup that generates invalid HTML (dd without preceding dt). I eliminate it whenever I see it on Wikipedia but I have been told in the past to just use display=block rather than wrap in {{block indent}}. Is this advice now changing?

@HairyDude thank you for chaning from :<math to <math display=block that's what I would recommend.

The change, however, does try to make the layout for :<math not worth, as we assume that there are still :<math instances around. The community started discussions at T111712 T268922 but it seems very hard to achieve consensus.

For me the fact that <math>\somTex</math> is rendered as {\displaystyle \someTex} generates all kinds of problems and I would very much like to get away, without to annoy the editors.