diff --git a/Tests/LibWeb/Layout/expected/image-display-block-margin-auto.txt b/Tests/LibWeb/Layout/expected/image-display-block-margin-auto.txt
new file mode 100644
index 0000000000..354b964149
--- /dev/null
+++ b/Tests/LibWeb/Layout/expected/image-display-block-margin-auto.txt
@@ -0,0 +1,4 @@
+Viewport <#document> at (0,0) content-size 800x600 children: not-inline
+ BlockContainer at (0,0) content-size 800x116 children: not-inline
+ BlockContainer
at (8,8) content-size 400x100 children: not-inline
+ ImageBox
at (158,8) content-size 100x100 children: not-inline
diff --git a/Tests/LibWeb/Layout/input/image-display-block-margin-auto.html b/Tests/LibWeb/Layout/input/image-display-block-margin-auto.html
new file mode 100644
index 0000000000..65c4cff2e5
--- /dev/null
+++ b/Tests/LibWeb/Layout/input/image-display-block-margin-auto.html
@@ -0,0 +1,11 @@
+
\ No newline at end of file
diff --git a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp
index fdd5df089e..af4d568d8e 100644
--- a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp
+++ b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp
@@ -210,6 +210,11 @@ void BlockFormattingContext::compute_width(Box const& box, AvailableSpace const&
};
auto input_width = [&] {
+ if (is(box)) {
+ // NOTE: Replaced elements had their width calculated independently above.
+ // We use that width as the input here to ensure that margins get resolved.
+ return CSS::Length::make_px(box_state.content_width());
+ }
if (is(box))
return CSS::Length::make_px(compute_width_for_table_wrapper(box, available_space));
if (should_treat_width_as_auto(box, available_space))