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

majmunbog created an issue. See original summary.

quietone’s picture

Version: 11.2.x-dev » 11.x-dev

Hi, 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.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

quietone’s picture

Status: Active » Postponed

The 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.

quietone’s picture

Project: Drupal core » Toolbar
Version: main » 1.x-dev
Component: toolbar.module » Code
Status: Postponed » Active

Toolbar has moved to contrib