at (11,11) content-size 100x55.34375 children: not-inline
+ BlockContainer
at (72,12) content-size 50x53.34375 children: inline
+ line 0 width: 28.40625, height: 17.46875, bottom: 17.46875, baseline: 13.53125
+ frag 0 from TextNode start: 0, length: 4, rect: [72,12 28.40625x17.46875]
+ "well"
+ line 1 width: 36.84375, height: 17.9375, bottom: 35.40625, baseline: 13.53125
+ frag 0 from TextNode start: 5, length: 5, rect: [72,29 36.84375x17.46875]
+ "hello"
+ line 2 width: 55.359375, height: 18.40625, bottom: 53.34375, baseline: 13.53125
+ frag 0 from TextNode start: 11, length: 7, rect: [72,46 55.359375x17.46875]
+ "friends"
+ TextNode <#text>
diff --git a/Tests/LibWeb/Layout/input/block-and-inline/width-auto-margins-set-zero-if-containing-size-smaller.html b/Tests/LibWeb/Layout/input/block-and-inline/width-auto-margins-set-zero-if-containing-size-smaller.html
new file mode 100644
index 0000000000..dc07cb3f11
--- /dev/null
+++ b/Tests/LibWeb/Layout/input/block-and-inline/width-auto-margins-set-zero-if-containing-size-smaller.html
@@ -0,0 +1,6 @@
+
well hello friends
\ No newline at end of file
diff --git a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp
index b04bed99a0..c25ea661e5 100644
--- a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp
+++ b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp
@@ -181,7 +181,7 @@ void BlockFormattingContext::compute_width(Box const& box, AvailableSpace const&
if (!box.is_inline()) {
// 10.3.3 Block-level, non-replaced elements in normal flow
// If 'width' is not 'auto' and 'border-left-width' + 'padding-left' + 'width' + 'padding-right' + 'border-right-width' (plus any of 'margin-left' or 'margin-right' that are not 'auto') is larger than the width of the containing block, then any 'auto' values for 'margin-left' or 'margin-right' are, for the following rules, treated as zero.
- if (width.is_auto() && total_px > width_of_containing_block) {
+ if (!width.is_auto() && total_px > width_of_containing_block) {
if (margin_left.is_auto())
margin_left = zero_value;
if (margin_right.is_auto())