Drupal is a registered trademark of Dries Buytaert
Release: reCAPTCHA 8.x-3.5 Minor update available for module recaptcha (8.x-3.5). Release: Search API Solr 4.3.14 Minor update available for module search_api_solr (4.3.14). Release: ECA: Event - Condition - Action 2.1.22 Minor update available for module eca (2.1.22). Release: WebProfiler 11.2.1 Minor update available for module webprofiler (11.2.1). Usage Milestone: Entity Browser Module entity_browser crossed 100,000 active installs. Release: Editoria11y SI (SiteImprove) 3.0.0 Major update available for module editoria11y_si (3.0.0). Release: Diagnosis 1.0.3 Minor update available for theme diagnosis (1.0.3). Release: DiBa Integration 1.3.3 Minor update available for module diba_integration (1.3.3). Release: AlternativeCommerce NovaPoshta API 1.1.10 Minor update available for module basket_novaposhta (1.1.10). Module Revived: Commerce Currency Resolver 2.0.2 Module commerce_currency_resolver updated after 10 months of inactivity (2.0.2).

Roles Classes

321 sites No security coverage
View on drupal.org

This module adds CSS classes to the HTML body tag based on the roles assigned to the currently logged-in user. It allows for easy styling and custom behavior targeting of users by role, with options to configure class prefixes and exclude specific roles. The module also adds classes for authenticated and anonymous users.

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

Tracked releases
4
Tracked since
May 2026
Latest release
1 month ago
Releases (12 mo)
4 ▲ from 0
Maintenance
Active

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