Icon block: Block supports attributes for wrapper, not SVG inside it
What problem does this address?
The core/icon block currently applies block supports attributes like background, border, spacing, and color styles directly to the <svg>element instead of the .wp-block-icon wrapper.
For example, inline-styles padding: 1rem and border-radius: 999px are applied to the SVG itself, which can cause the icon/background to bleed outside the intended rounded shape and makes spacing behave unexpectedly.
Example of current markup:
<div class="wp-block-icon">
<svg
class="has-background has-brand-yellow-background-color"
style="background-color: var(--wp--preset--color--black); color: var(--wp--preset--color--white); padding: 1rem; border-radius: 999px;">
...
</svg>
</div>
What is your proposed solution?
Apply the block dimensions and box-model related styles to the .wp-block-icon wrapper instead of the SVG.
The wrapper should handle:
- width / height
- background / color
- padding / margins
- borders / radius
For example something like this:
<div class="wp-block-icon has-background has-black-background-color has-text-color has-white-color" style="padding: 1rem; border-radius: 999px;" >
<svg> ... </svg>
</div>
The SVG should fit inside the wrapper dimensions while preserving its aspect ratio.
This would make the Icon block behave more like a normal styled container and allow rounded, padded icons to work correctly without custom CSS.
Thanks for the report. However, there is a reason why block support was applied to the SVG rather than the block wrapper. See #75553 for more details.
Applying width directly to the block itself makes it very difficult to select. Additionally, it's centered by default and can't easily be left-aligned. So, I applied all block support except margins to the SVG element.
If we apply block support to the block wrapper, we need to reconsider how to solve this problem.