This project is not covered by Drupal’s security advisory policy.
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
- Download and place the module in your
DRUPAL_ROOT/modules/contribdirectory. - Go to Admin > Extend and enable the module.
- 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.
Supporting organizations:
Development and bug fixing
Project information
322 sites report using this module
- Created by dkmishra on , updated
This project is not covered by the security advisory policy.
Use at your own risk! It may have publicly disclosed vulnerabilities.
Releases
2.0.1
released 15 June 2026
Works with Drupal: ^10 || ^11 || ^12
Drupal 12 compatibility.
Install:
Development version: 2.0.x-dev updated 15 Jun 2026 at 03:14 UTC
8.x-1.5
released 25 May 2026
Works with Drupal: ^8 || ^9 || ^10 || ^11
Install:
Development version: 8.x-1.x-dev updated 29 Jun 2026 at 10:19 UTC

