Skip to content

[Pattern Block Overwrides] - Inline style attribute is stripped from rich text #70352

Open

Description

@webexpr-dhenriet

Description

There is a major inconsistency in how inline style attributes are handled within synchronized patterns that have overrides enabled.
The rich text "Highlight" tool in the block editor creates a <mark> tag with an inline style attribute (e.g., style="background-color:..."). However, when a user overrides the content of a block containing this markup within a synced pattern, the style attribute is stripped out upon saving, while the class attribute is preserved.

The core inconsistency is :

  • why does the editor provide a tool that generates inline styles if the pattern override system is designed to strip them ?
  • the behavior should be consistent: either never add inline styles, or always preserve them ?

Step-by-step reproduction instructions

  1. Create a new synchronized pattern.
  2. Insert a Heading block. In the heading's text, use the "Highlight" tool to color a portion of the text. To create colored text without a background, one common method is to set the highlight background to transparent, which results in a <mark> tag with an inline style
  3. Ensure that overrides are enabled for the Heading block within the pattern.
  4. Save the synchronized pattern.
  5. Insert this pattern into a new page or post.
  6. Modify the text content of the heading. For example, change "Title with color" to "A new title with color".
  7. Save the page and inspect the code of the overridden heading block.

<!-- wp:group {"metadata":{"name":"Custom title section"},"style":{"spacing":{"padding":{"bottom":"var:preset|spacing|50"}}},"layout":{"type":"constrained"}} -->
<div class="wp-block-group" style="padding-bottom:var(--wp--preset--spacing--50)">
<!-- wp:heading {"metadata":{"name":"Title","bindings":{"__default":{"source":"core/pattern-overrides"}}}} -->
<h2 class="wp-block-heading">
Title
<mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-orange-700-color">with color</mark>
</h2>
<!-- /wp:heading -->
</div>
<!-- /wp:group -->

Actual behavior
The style="background-color:rgba(0, 0, 0, 0)" attribute is stripped from the mark tag, while the class attribute is correctly preserved. The resulting code is :

<h2 class="wp-block-heading">Title <mark class="has-inline-color has-orange-700-color">with color</mark></h2>

Expected behavior
The mark tag within the overridden heading should preserve both its class and its inline style attribute. The code should look like this :

<h2 class="wp-block-heading">Title <mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-orange-700-color">with color</mark></h2>

Screenshots, screen recording, code snippet

Color menu

Image

Pattern

Image

Pattern in a page (back office)

Image


Pattern in page front end

Image

Environment info

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

  • Yes

Please confirm which theme type you used for testing.

  • Block
  • Classic
  • Hybrid (e.g. classic with theme.json)
  • Not sure

Activity

  1. added
    [Feature] Synced PatternsRelated to synced patterns (formerly reusable blocks)
    [Feature] PatternsA collection of blocks that can be synced (previously reusable blocks) or unsynced
    on Jun 9, 2025
  2. talldan commented on Jun 9, 2025

    @talldan
    Contributor

    why does the editor provide a tool that generates inline styles if the pattern override system is designed to strip them ?
    the behavior should be consistent: either never add inline styles, or always preserve them ?

    Thanks for reporting this, it's not designed to do this, unfortunately it's a bug. It should preserve the content. It's a really unusual bug, since the color is preserved.

  3. patil-vipul commented on Jun 9, 2025

    @patil-vipul

    @webexpr-dhenriet The issue can be replicated in the latest version of Gutenberg (21.0.0-rc.1).
    Image

    Frontend:
    Image

    Will update here with a patch.

  4. webexpr-dhenriet commented on Jun 9, 2025

    @webexpr-dhenriet
    Author

    @talldan @patil-vipul thanks for the feedback ;)

  5. dhananjaykuber commented on Nov 12, 2026

    @dhananjaykuber
    Contributor

    I tested this on trunk and it looks fixed by #84213. The style was removed when the override was rendered, because WP_Block::replace_html() passes the override through wp_kses_post(), and safecss_filter_attr() dropped any value using rgba(). #84213 lets CSS color functions through kses, and with it the override renders as expected. Removing that filter brings the bug back. The Core change is tracked in Trac #66387 for WordPress 7.3, so I think this can be closed once that lands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Block] PatternAffects the Patterns Block[Feature] PatternsA collection of blocks that can be synced (previously reusable blocks) or unsynced[Feature] Synced PatternsRelated to synced patterns (formerly reusable blocks)[Type] BugAn existing feature does not function as intended

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions