Problem/Motivation
Depending the front-end themes CSS, you can run into situations where styles bleed into the Navigation components. This type of issue is not new, other admin components that need to be rendered on the front-end theme have also gone through similar issues. Some related reading on that topic:
- #2195695: Admin UIs on the front-end are difficult to theme
- #3291797: Refactor Drupal 10 settings tray / off-canvas to use modern CSS
- #3230518: Figure out how we want to incorporate web components in Drupal 10
It appears Navigation may be particularly vulnerable, b/c, although it does use an all: revert style declaration for all children, that rule is of very low specificity and is easily accidentally overridden by theme CSS.
Steps to reproduce
- Install Drupal using
demo_umamiinstall profile - Enable the
navigationmodule. - Login as admin
- Add a style rule like the following to your front-end theme. For instance, if we add this to
core/profiles/demo_umami/themes/umami/css/base.css:
button:hover, input[type="submit"]:hover { background-color: red; }
- View any front-end page
- Hover over the expand / collapse button in the Navigation
Expected result
The background-color of the expand/collapse button should be unchanged on hover.
Actual result
The background-color of the expand / collapse button is red. The theme CSS is bleeding through:

Proposed resolution
Review how the off-canvas dialog architects its CSS and mimic to prevent CSS bleeding through from the front-end theme. See #3291797: Refactor Drupal 10 settings tray / off-canvas to use modern CSS.
Remaining tasks
Review off-canvas dialog
Review other relevant admin components that need protection on the front-end
Consider web components to isolate styles
User interface changes
TBD
| Comment | File | Size | Author |
|---|---|---|---|
| #57 | extra-specificity-hack.png | 253.55 KB | scott_euser |
| #28 | with-patch.png | 9.57 KB | scott_euser |
| #28 | without-patch.png | 11.42 KB | scott_euser |
| #13 | Capture d’écran du 2025-06-20 13-27-28.png | 24.63 KB | grimreaper |
| #4 | mukurtu_navigation_css_bleed.png | 1.44 MB | m4olivei |
Issue fork drupal-3511280
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
m4oliveiComment #3
m4oliveiComment #4
m4oliveiWe saw this in the wild on the Mukurtu distribution. It's an open source Drupal install profile (which you can set up quite easily!):
Comment #7
finnsky commentedI added quick implementation of
https://web.dev/articles/declarative-shadow-dom
Almost current Drupal browserslist https://caniuse.com/declarative-shadow-dom
Works as a charm. Toolbar button fixed ;)
Comment #8
mherchelCSS layers won't work because all declared layers will be less specific than styles with no declared layer (which is the rest of Drupal).
Web components would be ideal, because encapsulation is one of the main benefits. Not sure of @finnsky’s MR is enough though, as far as I can tell it just protects the button. It should also protect everything else there (list styles etc). From the Slack thread at https://drupal.slack.com/archives/C7AB68LJV/p1741201924377989, @m4olivei found issues with BigPipe and declarative shadow DOM not being compatible.
The additional specificity of the ID selector (like we did in offcanvas) is a great solution that would be relatively easy to apply if we can't get the web component method working.
Comment #9
plopescWe experienced something similar while integrating Navigation in one of our sites.
There was a global rule to apply specific styles to all the buttons across the whole site that cause conflicts with Navigation.
As reference, this is the diff that made the trick in that project:
Comment #10
m4oliveiComment #11
quietone commentedChanging tags per Issue tags field and Issue tags -- special tags
Comment #13
grimreaperHi,
I have added a
font-family: inheritComing from https://drupal.slack.com/archives/C7AB68LJV/p1750418950750889
Comment #14
mherchelHad a long discussion about how to proceed with this at https://drupal.slack.com/archives/C7AB68LJV/p1751487654599299
Involved were navigation maintainers @nod_ and @finnsky (among others).
Per @nod_, we're going to move forward with the reset similar to how the offcanvas does it. We should also look at the fence created by https://git.drupalcode.org/project/drupal/-/blob/11.x/core/modules/ckedi... and see if this is something we need or could use.
Comment #17
mherchelNew MR created with a "regular" CSS reset.
The "Donut" selector that @nod_ mentioned in Slack isn't necessary.
Because
[data-drupal-admin-styles]exists multiple times on each page, we can't use a regular#idselector reset like we do we the off-canvas. Fortunately, there's a "quirk" with the CSS:is()pseudo-class (example CodePen), where its weight is equal to the highest weight selector in the list.So, if we write
:is(#extra-specificity, [data-drupal-admin-styles]), the selector will match[data-drupal-admin-styles], but have the specificity of the ID#extra-specificity. This is how we're proceeding.This should be ready to go!
Comment #18
mherchelFYI, test is red because evidently the performance test counts the number of CSS bytes (which is obviously increasing with this MR).
This will need to be changed at https://git.drupalcode.org/project/drupal/-/blob/11.x/core/modules/navig..., although I don't want to do it just yet, as reviews might necessitate further changes.
Comment #19
finnsky commentedLet's leave this task for a quick fix, and continue experimenting with web components here
https://www.drupal.org/project/drupal/issues/3534298
Comment #20
finnsky commented@mherchel
I found bugs in Tugboat:
1. on small screens: https://gyazo.com/d5ff663b2f211157fd129d687be2dd51
2. seems link toolbar-button has extra padding, at least size is different.
Comment #21
mherchelGood catch!
Comment #22
mherchelBugs fixed (🤞)
Comment #23
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #24
mherchelConflicts fixed!
Comment #25
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #26
mherchelI'm not going to keep re-rolling this everytime some CSS changes. Let's get a review in before fixing the tests and recompiling the CSS.
Comment #27
mherchelComment #28
scott_euser commentedThe CSS is a bit beyond me, but in terms of testing this, here is before & after with Environment Indicator + Devel enabled for example. Thank you for your work on this!
Before (bleeding in as issue summary describes):

After (looks great):

Comment #29
nod_Haven't tested the UI but I'm ok with the clever solution. Maybe we can name it
#extra-specificity-hack? to make sure we're not saying it's a supported pattern, and as a callback to old school CSS hacks :DComment #30
mherchelI like it! Makes it a bit more clearer to the dev that this is very non-standard.
Pushed!
Comment #31
berdirDoes this also fix #3501662: navigation top bar edit button has strange active (?) colors?
Comment #32
finnsky commented@berdir
yes. currently it is only one option that we have
Umami has global `a:hover` style.
What about MR I don't really like `hack` word.
`#extra-specificity-trick` probably will sounds better? :)
Comment #33
mherchelYa'll figure that out in Slack, and we can change the selector name at the end.
Does everything else look good?
Comment #34
smustgrave commentedSorry to be that guy but MR needs manual rebase.
Comment #35
mherchelNo worries.
Before I do a rebase, can I get a review on the methodology, etc, from the maintainers/committers (See #26)?
This will touch so many files, I'll be rebasing forever as it just sits here (it's already been waiting forever).
Comment #36
nicxvan commentedFirst thought, instead of calling it a hack, can we call it override?
Comment #37
smustgrave commentedGot hit by this on a client project. Seems only outstanding issue is the name extra-specificity-hack, do like the idea of override. So after that change just needs a rebase and believe its good to go?
Comment #38
smustgrave commentedMaybe a CR if anyone has written their own components?
Comment #39
nod_Comment #40
mherchelSounds good. I'll likely be able to work on it this weekend. Thanks :)
Comment #42
mherchelCurrent MR is all FUBAR. Going to create a new one.
Comment #45
lauriiiOn Slack, @catch pointed out that this could be a blocker for #3557578: Mark Navigation as a stable module. I personally think it's fine for us to mark the module stable and commit this whenever it's ready. That said, this is a pretty nasty DX bug so it would be good to get this fixed sooner rather than later.
Comment #46
mherchelThis is ready for review! I did extensive testing, and it should be good to go!
Lets get this reviewed, and committed asap. It touches every single CSS, so it's easy to get out of date (and I've already re-done it 3x now!)
Comment #47
smustgrave commentedTested this out following the steps from the summary
Added
To a file in umami and am seeing the red hover on the button.
Applying the MR the CSS no longer applies.
Tested this on a random side project I work on where links were changing size and it was fixed there too.
LGTM
Comment #48
mherchelYay! Lets get this in before it gets stale!
Comment #49
godotislateComment #53
nod_Committed and pushed ae8ac5ed60c to 11.x and 82a36af1315 to 11.3.x. Thanks!
Comment #57
scott_euser commentedI noticed this is breaking the Gin Top bar in Gin 5.x when in the admin theme. Should gin then go extra-extra-specificity to override this? Or would this be a follow-up in Core?
Comment #58
mherchelYeah, Gin will need to add specificity. I wonder if we should have a CR
Comment #59
scott_euser commentedOkay thanks, I created this issue in Gin: #3560487: Gin Top Bar styling is fully gone in 11.3.x
Yes I suppose it could affect other themes or modules, so perhaps a general announcement about it could be helpful
Comment #61
norman.lolInstead of
#extra-specificity-hackin core we should just introduce a real ID.Comment #62
nicxvan commentedI said basically the same thing in 36, but it was never addressed
Comment #63
penyaskitoSee you in #3569668: Broken styles for contextual links for blocks when editing navigation layout 🤓