diff --git a/Libraries/LibWeb/HTML/Location.cpp b/Libraries/LibWeb/HTML/Location.cpp
index d561cb3a6ee..788f1eb8a20 100644
--- a/Libraries/LibWeb/HTML/Location.cpp
+++ b/Libraries/LibWeb/HTML/Location.cpp
@@ -413,7 +413,10 @@ WebIDL::ExceptionOr Location::set_hash(String const& value)
(void)URL::Parser::basic_parse(input, {}, ©_url, URL::Parser::State::Fragment);
// 7. If copyURL's fragment is this's url's fragment, then return.
- if (copy_url.fragment() == this->url().fragment())
+ // NOTE: Ignore null values when comparing fragments. This behavior is not explicitly mentioned in the specs, potential bug?
+ auto copy_url_fragment = copy_url.fragment().has_value() ? copy_url.fragment() : String {};
+ auto this_url_fragment = this->url().fragment().has_value() ? this->url().fragment() : String {};
+ if (copy_url_fragment == this_url_fragment)
return {};
// 8. Location-object navigate this to copyURL.
diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/browsers/browsing-the-web/history-traversal/hash-empty-string.txt b/Tests/LibWeb/Text/expected/wpt-import/html/browsers/browsing-the-web/history-traversal/hash-empty-string.txt
new file mode 100644
index 00000000000..77f26e17bcc
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/html/browsers/browsing-the-web/history-traversal/hash-empty-string.txt
@@ -0,0 +1,8 @@
+Harness status: OK
+
+Found 3 tests
+
+3 Pass
+Pass URL has no hash
+Pass changing the hash from an empty string to an empty string does not trigger a popstate event
+Pass changing the hash from an empty string to an empty string does not trigger a hashchange event
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/input/wpt-import/html/browsers/browsing-the-web/history-traversal/hash-empty-string.html b/Tests/LibWeb/Text/input/wpt-import/html/browsers/browsing-the-web/history-traversal/hash-empty-string.html
new file mode 100644
index 00000000000..4670740cf6f
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/html/browsers/browsing-the-web/history-traversal/hash-empty-string.html
@@ -0,0 +1,31 @@
+
+
+
+
+
+
+
+