Drupal is a registered trademark of Dries Buytaert
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)! 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)!

Role Classes

is a lightweight Drupal module that automatically adds a CSS class to the <body> tag based on the current user's highest-privilege role. This allows site builders and theme developers to style pages differently per role using pure CSS — no JavaScript, no template overrides, no custom theme hooks required.

How It Works

Every Drupal role has a weight that reflects its privilege level. When a user visits any page, Role Classes reads their roles, identifies the one with the highest weight, looks up the CSS class you have configured for that role, and adds it to the tag automatically.
A user who holds multiple roles — for example, both authenticated and editor — receives only the class for the highest-weight role. This keeps the markup clean and predictable.

Example

Given this configuration:

An administrator visiting the site gets:
<body class="role-admin">
An editor who is also authenticated gets only:
<body class="role-editor">

Features

Highest-weight role wins — only one class is ever added to , reflecting the user's most privileged role.
Fully configurable — assign any valid CSS class name to any role from a simple admin form at Admin → Configuration → System → Role Classes.
Input validation — class names are validated against the CSS identifier specification and sanitized before being written to the DOM.
Performant — all logic runs inside a dedicated service with a per-request cache. Config is read and role entities are loaded at most once per page load, and only for roles that actually have a class configured.
Properly integrated — ships with a config schema, default configuration, and install/uninstall hooks so it behaves correctly on fresh installs, existing sites, and drush config:import workflows.
Developer friendly — all business logic lives in RoleClassesManager, a fully dependency-injected service that is straightforward to mock and unit test. The .module file is a thin delegator with no static calls except the unavoidable service container lookup inside the procedural hook.
Drupal 9, 10, and 11 compatible.

Installation

Via Composer (recommended):

composer require drupal/role_classes
drush en role_classes

Manual:

Download the module and place it in web/modules/contrib/role_classes/, then enable it at Admin → Extend.

Configuration
Navigate to Admin → Configuration → System → Role Classes (/admin/config/system/role-classes).
Enter a CSS class name next to each role. Leave a field blank to skip that role entirely. Role weights are shown alongside each field so you can follow the privilege hierarchy at a glance. Clear caches after saving.

Requirements

Drupal 9, 10, or 11
PHP 8.1 or higher

Activity

Total releases
1
First release
May 2026
Latest release
14 hours ago
Release cadence
Stability
100% stable

Releases

Version Type Release date
1.0.6 Stable May 30, 2026