diff --git a/lib/class-wp-theme-json-gutenberg.php b/lib/class-wp-theme-json-gutenberg.php index 7dd2c94bf30889..3eadb007f3d36c 100644 --- a/lib/class-wp-theme-json-gutenberg.php +++ b/lib/class-wp-theme-json-gutenberg.php @@ -724,7 +724,11 @@ private function get_block_classes( $style_nodes ) { } if ( self::ROOT_BLOCK_SELECTOR === $selector ) { - $block_rules .= 'body { margin: 0; }'; + // If the root body node has margin set in its spacing property + // then avoid setting a default margin. + if ( ! isset( $node['spacing']['margin'] ) ) { + $block_rules .= 'body { margin: 0; }'; + } $block_rules .= '.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }'; $block_rules .= '.wp-site-blocks > .alignright { float: right; margin-left: 2em; }'; $block_rules .= '.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }';