Problem/Motivation
The Drupal admin toolbar currently updates the body and html padding dynamically via JS to prevent its content from being overlapped:
$('body')[0].style.paddingTop = `${this.model.get('height')}px`;
$('html')[0].style.scrollPaddingTop = `${this.model.get('height')}px`;
This works but has limitations:
• Hardcoded JS values are not easily reusable in CSS for other components.
• Themes cannot reference the toolbar height in their styles.
Proposed resolution
Store the toolbar height in a CSS variable instead of applying the padding directly. For example:
document.documentElement.style.setProperty('--toolbar-height', `${this.model.get('height')}px`);
Update CSS to use the variable:
body.toolbar-tray-open {
padding-top: var(--toolbar-height);
}
html {
scroll-padding-top: var(--toolbar-height);
}
Benefits
- Provides a reusable value for other components (e.g., sticky headers, modals).
- Makes responsive adjustments easier without modifying JS.
- Separates measurement (JS) from styling (CSS), improving maintainability.
- Future-proof: any toolbar height changes automatically propagate to layouts using the variable.
Comments
Comment #2
quietone commentedHi, in Drupal core changes are made on on 11.x (our main development branch) first, and are then back ported as needed according to the Core change policies. Thanks.
Comment #4
quietone commentedThe Toolbar Module was approved for removal in #3476882: [Policy] Move Toolbar module to contrib.
This is Postponed. The status is set according to two policies. The Remove a core extension and move it to a contributed project and the Extensions approved for removal policies.
The deprecation work is in #3484850: [meta] Tasks to deprecate Toolbar module and the removal work in #3488828: [meta] Tasks to remove Toolbar module.
Toolbar will be moved to a contributed project before Drupal 12.0.0 is released.
Comment #5
quietone commentedToolbar has moved to contrib