I am trying to have all my taxonomy terms to look different from each other.

Is there a way for me add specific CSS classes to differing taxonomy terms?


4 Answers 4


Already the page-taxonomy-term-TERM_ID is present on the body tag.

To add more classes you can use hook_preprocess_html() and add the $vars['classes_array'] to add the css classes you want for the terms.


Are you talking about taxonomy pages? If so you can target each one of them with the default body class "page-taxonomy-term-X" where X is the taxonomy id.

If you want a different class, I suggest you to use the context module


you can add new filed


then use this filed with custom template

using normal theme suggestions and overwrites or

Note this code related to another issue [How to render node using custom view mode]

 * Implements hook_entity_info_alter().
  add new view info [name , label]
function {ModuleName}_entity_info_alter(&$entity_info) {
  $entity_info['node']['view modes']['{ViewName}'] = array(
    'label' => t('{ViewName Label}'),
    'custom settings' => TRUE,

 * Implements hook_theme_registry_alter().
  register templates path so drupal could find this view name template 
  and you could add this template inside your module
function {ModuleName}_theme_registry_alter(&$theme_registry) {
    // Defined path to the current module.
  $module_path = drupal_get_path('module', '{ModuleName}');
  // Find all .tpl.php files in this module's folder recursively.
  $template_file_objects = drupal_find_theme_templates($theme_registry, '.tpl.php', $module_path);
  // Iterate through all found template file objects.
  foreach ($template_file_objects as $key => $template_file_object) {
      // If the template has not already been overridden by a theme.
      if (!isset($theme_registry[$key]['theme path']) || !preg_match('#/themes/#', $theme_registry[$key]['theme path'])) {
          // Alter the theme path and template elements.
          $theme_registry[$key]['theme path'] = $module_path;
          $theme_registry[$key] = array_merge($theme_registry[$key], $template_file_object);
          $theme_registry[$key]['type'] = 'module';

 * Implements hook_preprocess_node().
  use our custom view as theme suggestions while rendering this a node who use this view mode
function {ModuleName}_preprocess_node(&$variables) {
  if($variables['view_mode'] == '{ViewName}') {
    $variables['theme_hook_suggestions'][] = 'node__' . $variables['type'] . '__{ViewName}';

If you want add class to term in everywhere I suggest customize taxonomy template with taxonomy-term.tpl.php. This will allow you to customize the output of your term page.

also if you want to add class to it in views result use Field Formatter CSS Class module is what you're looking for.

Adds a formatter for text/list/taxonomy fields to render as CSS classes on nodes.

The Field formatter CSS class module allows you to set any text/list/option/taxonomy field to render as CSS class on the node. This enables the node author to select predefined CSS styling per node.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.