diff --git a/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp
index 53df9e647e3..1f67d45bdab 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp
+++ b/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp
@@ -1171,4 +1171,17 @@ void HTMLImageElement::set_decoding(String decoding)
m_decoding_hint = ImageDecodingHint::Auto;
}
+bool HTMLImageElement::allows_auto_sizes() const
+{
+ // An img element allows auto-sizes if:
+ // - its loading attribute is in the Lazy state, and
+ // - its sizes attribute's value is "auto" (ASCII case-insensitive), or starts with "auto," (ASCII case-insensitive).
+ if (lazy_loading_attribute() != LazyLoading::Lazy)
+ return false;
+ auto sizes = attribute(HTML::AttributeNames::sizes);
+ return sizes.has_value()
+ && (sizes->equals_ignoring_ascii_case("auto"sv)
+ || sizes->starts_with_bytes("auto,"sv, AK::CaseSensitivity::CaseInsensitive));
+}
+
}
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLImageElement.h b/Userland/Libraries/LibWeb/HTML/HTMLImageElement.h
index 6258cc09078..4db80ae8f78 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLImageElement.h
+++ b/Userland/Libraries/LibWeb/HTML/HTMLImageElement.h
@@ -94,6 +94,9 @@ public:
// https://html.spec.whatwg.org/multipage/images.html#upgrade-the-pending-request-to-the-current-request
void upgrade_pending_request_to_current_request();
+ // https://html.spec.whatwg.org/multipage/embedded-content.html#allows-auto-sizes
+ bool allows_auto_sizes() const;
+
// ^Layout::ImageProvider
virtual bool is_image_available() const override;
virtual Optional intrinsic_width() const override;