diff --git a/Tests/LibWeb/Text/expected/css/CSSStyleSheet-removeRule.txt b/Tests/LibWeb/Text/expected/css/CSSStyleSheet-removeRule.txt
new file mode 100644
index 0000000000..2a83cb2bf5
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/css/CSSStyleSheet-removeRule.txt
@@ -0,0 +1,12 @@
+Exception thrown when removeRule() called on empty sheet: IndexSizeError
+Rule count after adding 3 rules: 3
+Rule text: .test { padding: 10px; }
+Rule text: .test { margin: 5px; }
+Rule text: .test { font-size: 14px; }
+Rule count after calling removeRule with no arguments: 2
+Rule text: .test { margin: 5px; }
+Rule text: .test { font-size: 14px; }
+Rule count after calling removeRule with explicit index: 1
+Rule text: .test { margin: 5px; }
+Exception thrown when given a negative index: IndexSizeError
+Exception thrown when index out of range: IndexSizeError
diff --git a/Tests/LibWeb/Text/input/css/CSSStyleSheet-removeRule.html b/Tests/LibWeb/Text/input/css/CSSStyleSheet-removeRule.html
new file mode 100644
index 0000000000..83dbea49a4
--- /dev/null
+++ b/Tests/LibWeb/Text/input/css/CSSStyleSheet-removeRule.html
@@ -0,0 +1,41 @@
+
+
+
diff --git a/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.cpp b/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.cpp
index 2f4a5eaff7..0a49ab9bbc 100644
--- a/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.cpp
+++ b/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.cpp
@@ -286,10 +286,10 @@ WebIDL::ExceptionOr CSSStyleSheet::add_rule(Optional selec
}
// https://www.w3.org/TR/cssom/#dom-cssstylesheet-removerule
-WebIDL::ExceptionOr CSSStyleSheet::remove_rule(unsigned index)
+WebIDL::ExceptionOr CSSStyleSheet::remove_rule(Optional index)
{
// The removeRule(index) method must run the same steps as deleteRule().
- return delete_rule(index);
+ return delete_rule(index.value_or(0));
}
void CSSStyleSheet::for_each_effective_style_rule(Function const& callback) const
diff --git a/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.h b/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.h
index 0621f9a535..9f02ff8da5 100644
--- a/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.h
+++ b/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.h
@@ -51,7 +51,7 @@ public:
WebIDL::ExceptionOr insert_rule(StringView rule, unsigned index);
WebIDL::ExceptionOr add_rule(Optional selector, Optional style, Optional index);
- WebIDL::ExceptionOr remove_rule(unsigned index);
+ WebIDL::ExceptionOr remove_rule(Optional index);
WebIDL::ExceptionOr delete_rule(unsigned index);
JS::NonnullGCPtr replace(String text);
diff --git a/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.idl b/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.idl
index 8dcce0584f..c7f223b7b9 100644
--- a/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.idl
+++ b/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.idl
@@ -19,7 +19,7 @@ interface CSSStyleSheet : StyleSheet {
// https://drafts.csswg.org/cssom/#legacy-css-style-sheet-members
[SameObject, ImplementedAs=css_rules] readonly attribute CSSRuleList rules;
long addRule(optional DOMString selector = "undefined", optional DOMString style = "undefined", optional unsigned long index);
- undefined removeRule(unsigned long index);
+ undefined removeRule(optional unsigned long index);
};
dictionary CSSStyleSheetInit {