) [8,8 16x32]
+ PaintableWithLines (BlockContainer) [0,0 800x33]
+ PaintableWithLines (BlockContainer) [8,8 1x17]
+ PaintableWithLines (BlockContainer
) [8,8 1x17]
+ ImagePaintable (ImageBox
![]()
) [8,21 0x0]
diff --git a/Tests/LibWeb/Layout/expected/svg/svg-as-image-invalid.txt b/Tests/LibWeb/Layout/expected/svg/svg-as-image-invalid.txt
index ec52dc6183..55946ffd77 100644
--- a/Tests/LibWeb/Layout/expected/svg/svg-as-image-invalid.txt
+++ b/Tests/LibWeb/Layout/expected/svg/svg-as-image-invalid.txt
@@ -1,9 +1,9 @@
Viewport <#document> at (0,0) content-size 800x600 children: not-inline
- BlockContainer at (0,0) content-size 800x48 [BFC] children: not-inline
- BlockContainer at (8,8) content-size 784x32 children: not-inline
- ImageBox
![]()
at (8,8) content-size 16x32 children: not-inline
+ BlockContainer at (0,0) content-size 800x16 [BFC] children: not-inline
+ BlockContainer at (8,8) content-size 784x0 children: not-inline
+ ImageBox
![]()
at (8,8) content-size 0x0 children: not-inline
ViewportPaintable (Viewport<#document>) [0,0 800x600]
- PaintableWithLines (BlockContainer) [0,0 800x48]
- PaintableWithLines (BlockContainer) [8,8 784x32]
- ImagePaintable (ImageBox
![]()
) [8,8 16x32]
+ PaintableWithLines (BlockContainer) [0,0 800x16]
+ PaintableWithLines (BlockContainer) [8,8 784x0]
+ ImagePaintable (ImageBox
![]()
) [8,8 0x0]
diff --git a/Tests/LibWeb/Layout/input/empty-image-should-be-zero-sized.html b/Tests/LibWeb/Layout/input/empty-image-should-be-zero-sized.html
new file mode 100644
index 0000000000..52ad811ece
--- /dev/null
+++ b/Tests/LibWeb/Layout/input/empty-image-should-be-zero-sized.html
@@ -0,0 +1 @@
+
![]()
\ No newline at end of file
diff --git a/Userland/Libraries/LibWeb/Layout/ImageBox.cpp b/Userland/Libraries/LibWeb/Layout/ImageBox.cpp
index c009cc541f..b28d12b2fc 100644
--- a/Userland/Libraries/LibWeb/Layout/ImageBox.cpp
+++ b/Userland/Libraries/LibWeb/Layout/ImageBox.cpp
@@ -36,16 +36,21 @@ void ImageBox::prepare_for_replaced_layout()
if (renders_as_alt_text()) {
auto const& element = verify_cast
(dom_node());
- auto& font = Platform::FontPlugin::the().default_font();
auto alt = element.get_attribute_value(HTML::AttributeNames::alt);
- CSSPixels alt_text_width = 0;
- if (!m_cached_alt_text_width.has_value())
- m_cached_alt_text_width = CSSPixels::nearest_value_for(font.width(alt));
- alt_text_width = m_cached_alt_text_width.value();
+ if (alt.is_empty()) {
+ set_natural_width(0);
+ set_natural_height(0);
+ } else {
+ auto const& font = Platform::FontPlugin::the().default_font();
+ CSSPixels alt_text_width = 0;
+ if (!m_cached_alt_text_width.has_value())
+ m_cached_alt_text_width = CSSPixels::nearest_value_for(font.width(alt));
+ alt_text_width = m_cached_alt_text_width.value();
- set_natural_width(alt_text_width + 16);
- set_natural_height(CSSPixels::nearest_value_for(font.pixel_size()) + 16);
+ set_natural_width(alt_text_width + 16);
+ set_natural_height(CSSPixels::nearest_value_for(font.pixel_size()) + 16);
+ }
}
if (!has_natural_width() && !has_natural_height()) {