Drupal is a registered trademark of Dries Buytaert
drupal 10.6.8 Update released for Drupal core (10.6.8)! drupal 11.3.9 Update released for Drupal core (11.3.9)! drupal 11.3.8 Update released for Drupal core (11.3.8)! drupal 11.3.7 Update released for Drupal core (11.3.7)! drupal 11.2.11 Update released for Drupal core (11.2.11)! drupal 10.6.7 Update released for Drupal core (10.6.7)! drupal 10.5.9 Update released for Drupal core (10.5.9)! cms 2.1.1 Update released for Drupal core (2.1.1)! drupal 11.3.6 Update released for Drupal core (11.3.6)! drupal 10.6.6 Update released for Drupal core (10.6.6)! cms 2.1.0 Update released for Drupal core (2.1.0)! linkit 7.0.14 Minor update available for module linkit (7.0.14). migrate_tools 6.1.4 Minor update available for module migrate_tools (6.1.4). diff 2.0.0 Major update available for module diff (2.0.0). masquerade 8.x-2.2 Minor update available for module masquerade (8.x-2.2). video_embed_field 3.1.0 Minor update available for module video_embed_field (3.1.0). bootstrap 8.x-3.40 Minor update available for theme bootstrap (8.x-3.40). menu_link_attributes 8.x-1.7 Minor update available for module menu_link_attributes (8.x-1.7). colorbox_inline 2.1.1 Minor update available for module colorbox_inline (2.1.1). node_view_permissions 8.x-1.7 Minor update available for module node_view_permissions (8.x-1.7).

body_roles_classes

327 sites No security coverage
View on drupal.org

The Body Roles Classes module adds CSS classes to the HTML element based on the roles of the currently logged-in user.
This helps developers and themers easily target users by role when applying styles or custom behaviors.

Features

  • Adds role-based CSS classes to the element
  • Configurable class prefix (e.g. role-editor, role-administrator)
  • Option to exclude specific roles from being added as classes
  • Adds user-authenticated and user-anonymous classes
  • Cache-safe implementation using Drupal cache context (user.roles)

Example

If a user has the following roles:

  • authenticated
  • editor

The output will be:

  <body class="role-authenticated role-editor">

If the "administrator" role is excluded, it will not be added as a class.

Configuration

After enabling the module, go to:
/admin/config/user-interface/body-roles-classes

You can:

  • Enable or disable the module
  • Set a class prefix
  • Select roles to exclude from output

Installation

  1. Download and place the module in your DRUPAL_ROOT/modules/contrib directory.
  2. Go to Admin > Extend and enable the module.
  3. Configure the module at Admin > Configuration > User Interface > Body Roles Classes.

Use Cases

  • Role-based theming
  • Custom styling for administrators, editors, or other roles
  • Frontend personalization based on user roles

Notes

  • Use the exclude roles option to prevent exposing sensitive roles (e.g. administrator) in the frontend.
  • The module uses proper cache contexts to ensure correct output for each user.

Activity

Total releases
2
First release
May 2026
Latest release
4 days ago
Release cadence
0 days
Stability
50% stable

Releases

Version Type Release date
2.0.x-dev Dev May 9, 2026
2.0.0 Stable May 9, 2026