diff --git a/Libraries/LibWeb/HTML/HTMLOptionElement.cpp b/Libraries/LibWeb/HTML/HTMLOptionElement.cpp
index 18374cd6c9d..0f40cf43704 100644
--- a/Libraries/LibWeb/HTML/HTMLOptionElement.cpp
+++ b/Libraries/LibWeb/HTML/HTMLOptionElement.cpp
@@ -99,6 +99,23 @@ static void concatenate_descendants_text_content(DOM::Node const* node, StringBu
});
}
+// https://html.spec.whatwg.org/multipage/form-elements.html#dom-option-label
+String HTMLOptionElement::label() const
+{
+ // The label IDL attribute, on getting, if there is a label content attribute,
+ // must return that attribute's value; otherwise, it must return the element's label.
+ if (auto label = attribute(HTML::AttributeNames::label); label.has_value())
+ return label.release_value();
+
+ return text();
+}
+
+// https://html.spec.whatwg.org/multipage/form-elements.html#dom-option-label
+void HTMLOptionElement::set_label(String const& label)
+{
+ MUST(set_attribute(HTML::AttributeNames::label, label));
+}
+
// https://html.spec.whatwg.org/multipage/form-elements.html#dom-option-text
String HTMLOptionElement::text() const
{
diff --git a/Libraries/LibWeb/HTML/HTMLOptionElement.h b/Libraries/LibWeb/HTML/HTMLOptionElement.h
index 2f176acf308..d87a1c0684e 100644
--- a/Libraries/LibWeb/HTML/HTMLOptionElement.h
+++ b/Libraries/LibWeb/HTML/HTMLOptionElement.h
@@ -29,6 +29,9 @@ public:
String text() const;
void set_text(String const&);
+ [[nodiscard]] String label() const;
+ void set_label(String const&);
+
int index() const;
bool disabled() const;
diff --git a/Libraries/LibWeb/HTML/HTMLOptionElement.idl b/Libraries/LibWeb/HTML/HTMLOptionElement.idl
index 6078be0d249..de6ee059da9 100644
--- a/Libraries/LibWeb/HTML/HTMLOptionElement.idl
+++ b/Libraries/LibWeb/HTML/HTMLOptionElement.idl
@@ -7,7 +7,7 @@ interface HTMLOptionElement : HTMLElement {
[CEReactions, Reflect] attribute boolean disabled;
readonly attribute HTMLFormElement? form;
- [CEReactions, Reflect] attribute DOMString label;
+ [CEReactions] attribute DOMString label;
[CEReactions, Reflect=selected] attribute boolean defaultSelected;
attribute boolean selected;
[CEReactions] attribute DOMString value;
diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-option-element/option-label.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-option-element/option-label.txt
index 80daf1d0395..353e67219d5 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-option-element/option-label.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-option-element/option-label.txt
@@ -6,18 +6,18 @@ Rerun
Found 12 tests
-7 Pass
-5 Fail
+9 Pass
+3 Fail
Details
Result Test Name MessagePass No children, no label
Pass No children, empty label
Pass No children, label
Fail No children, namespaced label
-Fail Single child, no label
+Pass Single child, no label
Pass Single child, empty label
Pass Single child, label
Fail Single child, namespaced label
-Fail Two children, no label
+Pass Two children, no label
Pass Two children, empty label
Pass Two children, label
Fail Two children, namespaced label
\ No newline at end of file