Repository navigation
Are form controls replaced elements? #12876
Description
From web-platform-tests/interop#1124 (cc @Loirooriol)
See previously: #1024.
CSS 2 says:
CSS 2 does not define which properties apply to form controls and frames, or how CSS can be used to style them. User agents may apply CSS properties to these elements. Authors are recommended to treat such support as experimental. A future level of CSS may specify this further.
CSS 2, defining "replaced element", says:
An element whose content is outside the scope of the CSS formatting model, such as an image, embedded document, or applet.
CSS Display says:
An element whose content is outside the scope of the CSS formatting model, such as an image or embedded document.
CSS Display, defining display: contents, says:
This value computes to display: none on replaced elements and other elements whose rendering is not entirely controlled by CSS; see Appendix B: Effects of display: contents on Unusual Elements for details.
CSS Sizing says:
In addition to the replaced elements listed in HTML§14.4 [HTML], the following HTML elements are also considered to be replaced elements for the purpose of the percentage-sized replaced element rule above, and can have their min-content contribution compressed when their width/height or max-width/max-height is expressed with a cyclic percentage size: [
<input>,<select>,<textarea>,<progress>,<meter>,<marquee>]
CSS UI says:
The term widget in this specification denotes replaced elements that can have native appearance, meaning that they are rendered like analogous native widgets or controls of the host operating system or platform, or with a look and feel not otherwise expressible in CSS.
HTML says:
The following elements can have a native appearance for the purpose of the CSS 'appearance' property.
So:
- CSS 2 explicitly leaves form controls undefined, and "replaced element" definition would presumably include them (because they're not defined by the CSS model),
- CSS Display has a similar definition of "replaced element", but also talks about form controls distinct to replaced elements,
- CSS Sizing implies that a number of HTML elements are to be considered replaced elements (implying they're not in general),
- CSS UI makes it clear that widgets are replaced elements,
- HTML defines them as widgets (per the CSS UI definition).
So on the whole to me it seems like the intention is that they are replaced elements, but we don't make this super obvious?
Activity
Loirooriol commentedon Oct 2, 2025
If they are replaced elements, why does
object-position: 100pxhave no effect on them?object-positionapplies to replaced elements.If they are replaced elements (presumably with no natural sizes), then why do they not stretch when assigned a preferred aspect ratio with
aspect-ratio?If they are replaced elements, why do they stretch by default when they are grid items?
emilio commentedon Oct 2, 2025
On the flip side, if they're not replaced elements, why do their children not render? :)
[-]Are form controlled replaced elements?[/-][+]Are form controls replaced elements?[/+]bfgeek commentedon Oct 3, 2025
They aren't replaced elements from the perspective of layout engines anymore. Form controls once behaved more similar to replaced elements, however (at the request of FF I believe) engines moved the rules for form-controls closer to non-replaced (which IMO was a good thing).
Likely we need a definite term for these things, we've previously used "semi-replaced" which IMO is too confusing, likely just "form control" or "widget" is fine.
Loirooriol commentedon Dec 2, 2025
Having a closed UA shadow DOM explains this.
emilio commentedon Dec 4, 2025
Something like a checkbox doesn't have quite a well defined place to put its children in, fwiw... But ok, I guess.
Loirooriol commentedon Dec 4, 2025
To be clear I'm not against saying that widgets shouldn't have a ::before or ::after. It's just that I don't think that the restriction on replaced elements is also covering widgets.
emilio commentedon Dec 4, 2025
So what's the state of this right now? On a test page like this:
It seems:
::before/::afterfor<button>/<input type=submit>and<input type=checkbox/radio>whenappearance: none(when they just followdisplay).::before/::afterfor everything above plus:date/month/datetime-local/color/file/marquee/<progress>The choices above don't make a lot of sense to me:
textinputs don't allow generated content but date inputs do?I think I'd be ok with saying that we allow generated content on:
<select>(so<input type=color/button/submit>).But not on:
<input type=image>/<svg>/<iframe>: those are "real replaced" things.<br>: very special / not well defined layout model.<progress>/<meter>/ range inputs / (at least when not inappearance: base/base-selectmode): the internal layout details of those are not spec'd / can't be relied on.Would people agree with such proposal?
emilio commentedon Dec 4, 2025
Ah, thanks. Sorry, just read this after posting the wall of text above.
Ok, so can we agree on:
I believe that makes all engines converge (Firefox needs to implement the generated content in a few places, and WebKit / Blink removing it from others), but I think the result is probably more sensible than the current state of things, which feels mostly random.
zcorpan commentedon Dec 18, 2025
Certainly not all widgets are fully replaced elements. e.g. for
vertical-align: baseline,<input type=text>,<input type=button>andbuttonhave baseline alignment like inline-blocks (with text), whereas replaced elements sit on top of the baseline.Demo: https://software.hixie.ch/utilities/js/live-dom-viewer/saved/14404
dholbert commentedon Oct 22, 2026
https://issues.chromium.org/issues/365052666 is one relevant spot where this has come up before, FWIW.
Also #6789 is a spot where this came up in terms of defining the layout of these elements.