diff --git a/Tests/LibWeb/Text/expected/css/dir-pseudo-on-form-associated-element.txt b/Tests/LibWeb/Text/expected/css/dir-pseudo-on-form-associated-element.txt
new file mode 100644
index 00000000000..94405c7239d
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/css/dir-pseudo-on-form-associated-element.txt
@@ -0,0 +1,30 @@
+Testing input element with type=text
+Input matches :dir(ltr): true
+Input matches :dir(rtl): false
+Input matches :dir(ltr): true
+Input matches :dir(rtl): false
+Input matches :dir(ltr): false
+Input matches :dir(rtl): true
+Input matches :dir(ltr): true
+Input matches :dir(rtl): false
+Input matches :dir(ltr): false
+Input matches :dir(rtl): true
+Input matches :dir(ltr): true
+Input matches :dir(rtl): false
+Input matches :dir(ltr): true
+Input matches :dir(rtl): false
+Testing textarea element
+Input matches :dir(ltr): true
+Input matches :dir(rtl): false
+Input matches :dir(ltr): true
+Input matches :dir(rtl): false
+Input matches :dir(ltr): false
+Input matches :dir(rtl): true
+Input matches :dir(ltr): true
+Input matches :dir(rtl): false
+Input matches :dir(ltr): false
+Input matches :dir(rtl): true
+Input matches :dir(ltr): true
+Input matches :dir(rtl): false
+Input matches :dir(ltr): true
+Input matches :dir(rtl): false
diff --git a/Tests/LibWeb/Text/expected/css/dir-pseudo-on-input-element.txt b/Tests/LibWeb/Text/expected/css/dir-pseudo-on-input-element.txt
deleted file mode 100644
index b7b6c5025a5..00000000000
--- a/Tests/LibWeb/Text/expected/css/dir-pseudo-on-input-element.txt
+++ /dev/null
@@ -1,14 +0,0 @@
-Input matches :dir(ltr): true
-Input matches :dir(rtl): false
-Input matches :dir(ltr): true
-Input matches :dir(rtl): false
-Input matches :dir(ltr): false
-Input matches :dir(rtl): true
-Input matches :dir(ltr): true
-Input matches :dir(rtl): false
-Input matches :dir(ltr): false
-Input matches :dir(rtl): true
-Input matches :dir(ltr): true
-Input matches :dir(rtl): false
-Input matches :dir(ltr): true
-Input matches :dir(rtl): false
diff --git a/Tests/LibWeb/Text/input/css/dir-pseudo-on-form-associated-element.html b/Tests/LibWeb/Text/input/css/dir-pseudo-on-form-associated-element.html
new file mode 100644
index 00000000000..c0b5eb43006
--- /dev/null
+++ b/Tests/LibWeb/Text/input/css/dir-pseudo-on-form-associated-element.html
@@ -0,0 +1,53 @@
+
+
+
+
diff --git a/Tests/LibWeb/Text/input/css/dir-pseudo-on-input-element.html b/Tests/LibWeb/Text/input/css/dir-pseudo-on-input-element.html
deleted file mode 100644
index 1c628038a5b..00000000000
--- a/Tests/LibWeb/Text/input/css/dir-pseudo-on-input-element.html
+++ /dev/null
@@ -1,44 +0,0 @@
-
-
-
-
diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp
index 6174f6d57eb..becd9a47658 100644
--- a/Userland/Libraries/LibWeb/DOM/Element.cpp
+++ b/Userland/Libraries/LibWeb/DOM/Element.cpp
@@ -2373,7 +2373,9 @@ Optional Element::auto_directionality() const
// 1. If element is an auto-directionality form-associated element:
if (is_auto_directionality_form_associated_element()) {
- auto const& value = static_cast(*this).value();
+ auto const* form_associated_element = dynamic_cast(this);
+ VERIFY(form_associated_element);
+ auto const& value = form_associated_element->value();
// 1. If element's value contains a character of bidirectional character type AL or R,
// and there is no character of bidirectional character type L anywhere before it in the element's value, then return 'rtl'.