diff --git a/Tests/LibWeb/Text/expected/DOM/Element-toggleAttribute-xml-doc-html-ns.txt b/Tests/LibWeb/Text/expected/DOM/Element-toggleAttribute-xml-doc-html-ns.txt
new file mode 100644
index 00000000000..d4dca65c8c3
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/DOM/Element-toggleAttribute-xml-doc-html-ns.txt
@@ -0,0 +1,3 @@
+Text
+Text
+Text
diff --git a/Tests/LibWeb/Text/input/DOM/Element-toggleAttribute-xml-doc-html-ns.html b/Tests/LibWeb/Text/input/DOM/Element-toggleAttribute-xml-doc-html-ns.html
new file mode 100644
index 00000000000..6f5980bf8dc
--- /dev/null
+++ b/Tests/LibWeb/Text/input/DOM/Element-toggleAttribute-xml-doc-html-ns.html
@@ -0,0 +1,16 @@
+
+
diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp
index 407f49acc8a..6af6fd6417a 100644
--- a/Userland/Libraries/LibWeb/DOM/Element.cpp
+++ b/Userland/Libraries/LibWeb/DOM/Element.cpp
@@ -342,8 +342,7 @@ WebIDL::ExceptionOr Element::toggle_attribute(FlyString const& name, Optio
return WebIDL::InvalidCharacterError::create(realm(), "Attribute name must not be empty"_fly_string);
// 2. If this is in the HTML namespace and its node document is an HTML document, then set qualifiedName to qualifiedName in ASCII lowercase.
- // FIXME: Handle the second condition, assume it is an HTML document for now.
- bool insert_as_lowercase = namespace_uri() == Namespace::HTML;
+ bool insert_as_lowercase = namespace_uri() == Namespace::HTML && document().document_type() == Document::Type::HTML;
// 3. Let attribute be the first attribute in this’s attribute list whose qualified name is qualifiedName, and null otherwise.
auto* attribute = m_attributes->get_attribute(name);