Skip to content

Additional CSS styles are not generated on the frontend for any block that handles its own rendering of inner blocks (for example: Navigation block) #82171

Closed

Description

@mrleemon

Description

I have added a Navigation block with several Navigation Link blocks inside a block template in a hybrid theme.
(Update: I tested this using the Twenty Twenty-Five block theme and ran into the exact same issue.)

I used the Additional CSS box introduced in WordPress 7.0 to customize the spacing of these blocks:

A margin-top: 0 rule for the Navigation block.
A padding: 0 rule for the Navigation Link blocks.

The changes are correctly reflected in the editor/backend. However, on the frontend, only the CSS for the Navigation block is generated and applied.

For example, the following CSS is present in the frontend:

:root :where(.wp-custom-css-68dd97ef) {
    margin-top: 0;
}

However, there is no corresponding generated CSS for the Navigation Link blocks, so the padding customization is not applied on the frontend.

Step-by-step reproduction instructions

  1. Use a hybrid theme.
  2. Add a Navigation block to a block template.
  3. Add one or more Navigation Link blocks inside the Navigation block.
  4. Use the Additional CSS box to add custom spacing to the blocks.
  5. Set margin-top: 0 on the Navigation block and padding: 0 on the Navigation Link blocks.
  6. View the template in the editor and verify that both customizations are reflected.
  7. View the same template on the frontend.
  8. Inspect the generated CSS.

Screenshots, screen recording, code snippet

No response

Environment info

WordPress: 7.1
No Gutenberg plugin
Custom hybrid theme

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
    [Type] BugAn existing feature does not function as intended
    on Aug 28, 2026
  2. mrleemon commented on Aug 28, 2026

    @mrleemon
    ContributorAuthor

    Apparently, the css key is present in the wp_posts entry referenced by the ref of the Navigation block:

    <!-- wp:navigation-link {"label":"Privacy Policy","type":"page","id":3951,"url":"https://example.com/privacy-policy/","kind":"post-type","metadata":{"bindings":{"url":{"source":"core/post-data","args":{"field":"link"}}}},"style":{"css":"padding: 0;"}} /-->
    
    <!-- wp:navigation-link {"label":"Terms & Conditions","type":"page","id":5218,"url":"https://example.com/terms-conditions/","kind":"post-type","metadata":{"bindings":{"url":{"source":"core/post-data","args":{"field":"link"}}}},"style":{"css":"padding: 0;"}} /-->
    
  3. mrleemon commented on Aug 29, 2026

    @mrleemon
    ContributorAuthor

    I'm seeing this behavior in block themes as well, specifically tested in Twenty Twenty-Five.

  4. PawelB02 commented on Aug 29, 2026

    @PawelB02

    Reproduction Report

    I was able to reproduce this issue.

    Environment

    • WordPress: 7.1
    • Gutenberg: 23.8.0
    • Browser: Google Chrome
    • OS: Windows 11
    • Theme: Twenty Twenty-Four

    Steps

    1. Added a Navigation block with a Navigation Link block.
    2. Added margin-top: 0; in the Additional CSS field for the Navigation block.
    3. Added padding: 0; in the Additional CSS field for the Navigation Link block.
    4. Saved the changes and checked the page on the frontend.
    5. Inspected the Navigation Link using Chrome DevTools.

    Result

    The Navigation block receives a generated wp-custom-css-* class, but the Navigation Link does not.

    The padding: 0; rule added through the Additional CSS field for the Navigation Link is not generated on the frontend.

    I have attached a screenshot from Chrome DevTools showing the result.

    Image
  5. ramonjd commented on Aug 31, 2026

    @ramonjd
    Member

    i wonder if this isn't a navigation link issue at all, but something to do with blocks that use "ref", which render inner blocks differently.

    they never hit render_block_data in the inner block loop

  6. mrleemon commented on Aug 31, 2026

    @mrleemon
    ContributorAuthor

    @ramonjd Yes, that seems to be the case.

  7. Jiwoon-Kim commented on Aug 31, 2026

    @Jiwoon-Kim
    Contributor

    I hit a separate failure in the same ref-backed Navigation rendering path:

    #82216

    That PR fixes Page List emitting a nested <ul> when rendered inside Navigation. It does not address the missing Additional CSS here, but it may be another useful example of the inner blocks being rendered through a different path from ordinary block rendering.


    #82208

    A concrete example of the current ref-backed rendering boundary surfaced in #82171:

    #82171

    Navigation Links saved in the referenced wp_navigation post do not pass through the ordinary inner-block rendering path, so their Additional CSS is not generated on the frontend. #82216 exposed another independent symptom in the same area: Page List needed special wrapper handling to avoid invalid list markup.

    Neither issue proves that a structured Navigation Resource would solve the bug by itself. A renderer would still need to preserve the normal block lifecycle where that contract matters. They do show that storing menu data as a block document currently makes renderer-specific behaviour part of the data model’s practical contract.

  8. mrleemon commented on Sep 6, 2026

    @mrleemon
    ContributorAuthor

    When trying to overcome this bug by defining a navigation link block style variation via a style .json file with top, bottom, left, and right padding values set to 0, the is-style-* class is correctly added to the block wrapper, but the actual CSS rules/styles themselves are never generated or applied on the frontend. I don't know if this is related.

  9. ramonjd commented on Sep 7, 2026

    @ramonjd
    Member

    I'd lean on @scruffian or @getdave's opinion here on where (and whether) there's a fix

  10. changed the title [-]Additional CSS styles are not generated for Navigation Link blocks[/-] [+]Additional CSS styles are not generated for Navigation Link blocks on the frontend[/+] on Sep 7, 2026
  11. scruffian commented on Sep 8, 2026

    @scruffian
    Contributor

    I agree with the assessment here - the problem is not in the navigation block specifically, its in any block that handles its own rendering of inner blocks. I created a draft PR to fix it here: Custom CSS: Generate styles for blocks rendered by their parent block

  12. changed the title [-]Additional CSS styles are not generated for Navigation Link blocks on the frontend[/-] [+]Additional CSS styles are not generated on the frontend for any block that handles its own rendering of inner blocks (for example: Navigation Link block)[/+] on Oct 14, 2026
  13. changed the title [-]Additional CSS styles are not generated on the frontend for any block that handles its own rendering of inner blocks (for example: Navigation Link block)[/-] [+]Additional CSS styles are not generated on the frontend for any block that handles its own rendering of inner blocks (for example: Navigation block)[/+] on Oct 14, 2026
  14. mrleemon commented on Oct 15, 2026

    @mrleemon
    ContributorAuthor

    Could someone please take a look at this bug, please? How can we help move this forward?

    Since padding and margin support for Navigation Links apparently will not be included in WordPress 7.2, this fix is currently one of the few practical ways to add custom spacing to individual blocks (aside from using a custom CSS class).

    @ramonjd @scruffian

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

Metadata

Metadata

Assignees

Labels

[Status] In ProgressTracking issues with work in progress[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