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.
Project information
320 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
Adds role-based CSS classes to the body tag, allowing developers to style pages differently based on the current user's role.
Development version: 2.0.x-dev updated 25 May 2026 at 11:55 UTC
Development version: 8.x-1.x-dev updated 25 May 2026 at 11:23 UTC

