Drupal is a registered trademark of Dries Buytaert
drupal 10.6.12 Update released for Drupal core (10.6.12)! drupal 11.3.13 Update released for Drupal core (11.3.13)! drupal 10.6.11 Update released for Drupal core (10.6.11)! drupal 11.3.12 Update released for Drupal core (11.3.12)! drupal 11.2.14 Update released for Drupal core (11.2.14)! drupal 10.5.12 Update released for Drupal core (10.5.12)! cms 2.1.3 Update released for Drupal core (2.1.3)! drupal 10.5.11 Update released for Drupal core (10.5.11)! drupal 11.3.11 Update released for Drupal core (11.3.11)! drupal 11.2.13 Update released for Drupal core (11.2.13)! drupal 10.6.10 Update released for Drupal core (10.6.10)! cms 2.1.2 Update released for Drupal core (2.1.2)! drupal 11.1.10 Update released for Drupal core (11.1.10)! drupal 10.5.10 Update released for Drupal core (10.5.10)! drupal 10.4.10 Update released for Drupal core (10.4.10)! drupal 11.2.12 Update released for Drupal core (11.2.12)! drupal 11.3.10 Update released for Drupal core (11.3.10)! drupal 10.6.9 Update released for Drupal core (10.6.9)! drupal 10.6.8 Update released for Drupal core (10.6.8)! drupal 11.3.9 Update released for Drupal core (11.3.9)!

body_roles_classes

335 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
4
First release
May 2026
Latest release
1 week ago
Release cadence
12 days
Stability
75% stable

Release Timeline

Releases

Version Type Release date
2.0.1 Stable Jun 15, 2026
8.x-1.5 Stable May 25, 2026
2.0.x-dev Dev May 9, 2026
2.0.0 Stable May 9, 2026