diff --git a/Libraries/LibWeb/HTML/HTMLMediaElement.cpp b/Libraries/LibWeb/HTML/HTMLMediaElement.cpp
index 22770da6f40..e10d6f8be93 100644
--- a/Libraries/LibWeb/HTML/HTMLMediaElement.cpp
+++ b/Libraries/LibWeb/HTML/HTMLMediaElement.cpp
@@ -107,8 +107,6 @@ void HTMLMediaElement::attribute_changed(FlyString const& name, Optional
load_element().release_value_but_fixme_should_propagate_errors();
} else if (name == HTML::AttributeNames::crossorigin) {
m_crossorigin = cors_setting_attribute_from_keyword(value);
- } else if (name == HTML::AttributeNames::muted) {
- set_muted(true);
}
}
diff --git a/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp b/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp
index 51c8d22fed6..858c58ea02f 100644
--- a/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp
+++ b/Libraries/LibWeb/HTML/Parser/HTMLParser.cpp
@@ -832,6 +832,17 @@ GC::Ref HTMLParser::create_element_for(HTMLToken const& token, Opt
return IterationDecision::Continue;
});
+ // AD-HOC: The muted attribute on media elements is only set if the muted content attribute is present when the element is first created.
+ if (element->is_html_media_element() && namespace_ == Namespace::HTML) {
+ // https://html.spec.whatwg.org/multipage/media.html#user-interface:attr-media-muted
+ // When a media element is created, if the element has a muted content attribute specified, then the muted IDL
+ // attribute should be set to true; otherwise, the user agents may set the value to the user's preferred value.
+ if (element->has_attribute(HTML::AttributeNames::muted)) {
+ auto& media_element = as(*element);
+ media_element.set_muted(true);
+ }
+ }
+
// 11. If willExecuteScript is true:
if (will_execute_script) {
// 1. Let queue be the result of popping from document's relevant agent's custom element reactions stack. (This will be the same element queue as was pushed above.)
diff --git a/Tests/LibWeb/Text/expected/HTML/HTMLMediaElement-muted-content-attribute.txt b/Tests/LibWeb/Text/expected/HTML/HTMLMediaElement-muted-content-attribute.txt
new file mode 100644
index 00000000000..00507b3a2b4
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/HTML/HTMLMediaElement-muted-content-attribute.txt
@@ -0,0 +1,5 @@
+Initial muted state when muted content attribute is present: true
+Changing the muted attribute after object creation changes the muted state: false
+Re-inserting the video element into the document changes the muted state: false
+Re-inserting non-default muted video element into the document changes the muted state: false
+Muted state of a script-created video element after adding the muted content attribute false
diff --git a/Tests/LibWeb/Text/input/HTML/HTMLMediaElement-muted-content-attribute.html b/Tests/LibWeb/Text/input/HTML/HTMLMediaElement-muted-content-attribute.html
new file mode 100644
index 00000000000..edcc36bb594
--- /dev/null
+++ b/Tests/LibWeb/Text/input/HTML/HTMLMediaElement-muted-content-attribute.html
@@ -0,0 +1,28 @@
+
+
+
+
+