diff --git a/Tests/LibWeb/Text/expected/ShadowDOM/css-variable-inheritance-across-shadow-boundary.txt b/Tests/LibWeb/Text/expected/ShadowDOM/css-variable-inheritance-across-shadow-boundary.txt
new file mode 100644
index 00000000000..36a76231ff8
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/ShadowDOM/css-variable-inheritance-across-shadow-boundary.txt
@@ -0,0 +1 @@
+ green rgb(0, 128, 0)
diff --git a/Tests/LibWeb/Text/input/ShadowDOM/css-variable-inheritance-across-shadow-boundary.html b/Tests/LibWeb/Text/input/ShadowDOM/css-variable-inheritance-across-shadow-boundary.html
new file mode 100644
index 00000000000..236dbb4f6de
--- /dev/null
+++ b/Tests/LibWeb/Text/input/ShadowDOM/css-variable-inheritance-across-shadow-boundary.html
@@ -0,0 +1,20 @@
+
+
+
+
+green
+
+
+
+
diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
index 4215e474059..f5cd9af60fa 100644
--- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
+++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp
@@ -7651,7 +7651,7 @@ static RefPtr get_custom_property(DOM::Element const& element,
return it->value.value;
}
- for (auto const* current_element = &element; current_element; current_element = current_element->parent_element()) {
+ for (auto const* current_element = &element; current_element; current_element = current_element->parent_or_shadow_host_element()) {
if (auto it = current_element->custom_properties({}).find(custom_property_name); it != current_element->custom_properties({}).end())
return it->value.value;
}