Skip to content

Render an option's label attribute when not using base appearance - #12936

Merged
zcorpan merged 1 commit into
mainfrom
option-label-rendering
Sep 14, 2026
Merged

zcorpan merged 1 commit into
mainfrom
option-label-rendering

Conversation

@annevk

@annevk annevk commented Sep 14, 2026

Copy link
Copy Markdown
Member

Render an option's label attribute when not using base appearance

Defining customizable <select> in 172cccf replaced "displaying the
element's label" with "displaying the result of collect option text
given the option and true", which never consults the label content
attribute and strips and collapses whitespace. As written,
<option label="foo">bar</option> displays "bar", and an option whose
label attribute is a single space displays nothing.

Blink, Gecko, and WebKit instead display the label attribute's value
as-is when it is not the empty string, and the option's text otherwise.
That is what option-label-whitespace.html and
option-label-whitespace-2.html in
html/rendering/replaced-elements/the-option-element/ test.

The rendering section could not simply reference the option's label
because it needs img alt text included. So the label is now an algorithm
that takes the same includeAltText boolean as collect option text,
mirroring "get an optgroup element's label": the label IDL attribute
getter passes false and rendering passes true.

Base appearance is unaffected; the option contents slot and option label
element already work this way.

While there, add a missing "the" to the sentences introducing the label
and value attributes.

Fixes #10955.


The prose this restores was lost in #10548 and stayed lost through #12201; base appearance, defined by those same PRs, already gets it right.

(See WHATWG Working Mode: Changes for more details.)


/form-elements.html ( diff )
/rendering.html ( diff )

Defining customizable `<select>` in 172cccf replaced "displaying the
element's label" with "displaying the result of collect option text
given the option and true", which never consults the label content
attribute and strips and collapses whitespace. As written,
`<option label="foo">bar</option>` displays "bar", and an option whose
label attribute is a single space displays nothing.

Blink, Gecko, and WebKit instead display the label attribute's value
as-is when it is not the empty string, and the option's text otherwise.
That is what option-label-whitespace.html and
option-label-whitespace-2.html in
html/rendering/replaced-elements/the-option-element/ test.

The rendering section could not simply reference the option's label
because it needs img alt text included. So the label is now an algorithm
that takes the same includeAltText boolean as collect option text,
mirroring "get an optgroup element's label": the label IDL attribute
getter passes false and rendering passes true.

Base appearance is unaffected; the option contents slot and option label
element already work this way.

While there, add a missing "the" to the sentences introducing the label
and value attributes.

Fixes #10955.
@annevk
annevk force-pushed the option-label-rendering branch from 4c469ee to 8db1b4a Compare September 14, 2026 09:48

@keithamus keithamus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@zcorpan
zcorpan merged commit 2b62707 into main Sep 14, 2026
2 checks passed
@zcorpan
zcorpan deleted the option-label-rendering branch September 14, 2026 11:34
@annevk annevk added the topic: select The <select> element label Sep 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic: select The <select> element

Development

Successfully merging this pull request may close these issues.

Rendering option with empty label attribute or whitespace

3 participants