Drupal is a registered trademark of Dries Buytaert
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)! drupal 10.6.6 Update released for Drupal core (10.6.6)! cms 2.1.0 Update released for Drupal core (2.1.0)! bootstrap 8.x-3.40 Minor update available for theme bootstrap (8.x-3.40). menu_link_attributes 8.x-1.7 Minor update available for module menu_link_attributes (8.x-1.7). eca 3.1.1 Minor update available for module eca (3.1.1). layout_paragraphs 2.1.3 Minor update available for module layout_paragraphs (2.1.3). ai 1.3.3 Minor update available for module ai (1.3.3). ai 1.2.14 Minor update available for module ai (1.2.14). node_revision_delete 2.0.3 Minor update available for module node_revision_delete (2.0.3). moderated_content_bulk_publish 2.0.52 Minor update available for module moderated_content_bulk_publish (2.0.52). klaro 3.0.10 Minor update available for module klaro (3.0.10). klaro 3.0.9 Minor update available for module klaro (3.0.9). layout_paragraphs 2.1.2 Minor update available for module layout_paragraphs (2.1.2). geofield_map 11.1.8 Minor update available for module geofield_map (11.1.8).

node_id_class

30 sites Security covered
View on drupal.org

The Node ID Class module for Drupal enables site builders to assign custom CSS IDs and classes to the <body> element and individual node wrappers. These can include dynamic tokens such as {node_id}, {node_title}, {bundle}, and {node_author_uid}, allowing flexible theming, unique layouts, or custom frontend behavior.

Requirements

  • Drupal Version: This module requires Drupal 10 or higher.
  • Additional Modules: No additional contributed modules are required.

Installation

  • Download the Node ID Class module.
  • Install using Composer:

    composer require drupal/node_id_class
  • Or manually place the module in your modules/custom directory. See:

    Drupal module installation guide
  • Enable the module via the Extend page in the Drupal admin interface or using Drush:

    drush en node_id_class

Configuration

After enabling the module, a new Node ID Class fieldset will appear on each content type’s edit page (e.g., admin/structure/types/manage/article). Within this fieldset, you can configure the following:

  • CSS Body ID: Applied to the <body> element on full node pages. Supports tokens: {node_id}, {bundle}, {node_title}, {node_author_uid}. Example: body-id-{node_id}-{bundle}-{node_title}
  • CSS Body Class(es): Applied to the <body> element. Supports multiple classes separated by spaces. Example: body-class-{node_id}-{bundle}
  • CSS Node Class(es): Applied to the node wrapper in all view modes and listings (e.g., Views). Supports multiple classes separated by spaces. Example: node-class-{node_id}-{bundle}-{node_title}

Dynamic Tokens

  • {node_id} – Node ID
  • {node_title} – Node title (converted to a URL-friendly slug)
  • {bundle} – Content type machine name
  • {node_author_uid} – Node author’s user ID

Tokens are sanitized and escaped automatically to prevent invalid markup or XSS vulnerabilities.

Similar Projects

Troubleshooting & FAQ

  • Custom classes not appearing? Ensure the node is displayed in a full-page view mode and your theme prints $attributes and $content_attributes.
  • Body ID or classes not showing? Verify that the settings are saved for the correct content type.
  • Tokens are not replaced? Tokens only work when viewing a node page.
  • Why is HTML not allowed in the fields? HTML is stripped for security, preventing XSS attacks and invalid CSS.

Support

Please post bug reports, feature requests and support requests to the Node ID Class module issue queue. If you met any problems with this module - feel free to create an issue.

Activity

Total releases
4
First release
Feb 2025
Latest release
4 months ago
Release cadence
103 days
Stability
75% stable

Release Timeline

Releases

Version Type Release date
1.1.3 Stable Dec 9, 2025
1.1.2 Stable Dec 9, 2025
1.1.x-dev Dev Feb 2, 2025
1.1.1 Stable Feb 2, 2025