HTML Title
Enables limited HTML markup in node titles to support formatting like italics, superscript, subscript, and other inline elements.
html_title
Install
composer require 'drupal/html_title:8.x-1.6'
Overview
The HTML Title module addresses a limitation in Drupal's core where node titles are restricted to plain text and do not support any HTML markup. This becomes problematic when content requires formatted titles, such as book titles that need italicization, scientific notation requiring subscript or superscript characters, or trademark symbols.
This module allows a configurable set of HTML tags (such as <em>, <sub>, <sup>, <b>, <i>, <strong>, <cite>, <code>, <bdi>, <wbr>, <br>) to be used within node titles. It filters all other markup to prevent XSS vulnerabilities or problematic nesting (such as links within links).
The module integrates seamlessly with Drupal's page titles, breadcrumbs, Views, search results, and node edit forms, ensuring HTML formatting is rendered properly throughout the site while maintaining security.
Features
- Configurable whitelist of allowed HTML tags for node titles
- Automatic XSS protection by filtering disallowed HTML tags
- Page title support with HTML rendering on node view and edit pages
- Breadcrumb integration displaying HTML-formatted node titles
- Views integration with a dedicated node_html_title field plugin that renders HTML in title fields
- Search results integration showing formatted titles in search listings
- Field formatter for string fields to display HTML-formatted text
- RSS feed integration that strips HTML tags for proper XML output
- Node confirmation message support showing formatted titles after save
- Multilingual/translation support for HTML titles
- Safe uninstallation that preserves Views configurations using the title field
Use Cases
Book and Publication Titles
Libraries, publishers, and academic sites often need to display book titles with proper italicization. For example, 'The <em>Origin of Species</em> by Charles Darwin' can be entered as a node title and displayed correctly throughout the site.
Scientific and Mathematical Notation
Scientific content frequently requires superscript and subscript characters. Chemical formulas like 'H<sub>2</sub>O' or mathematical expressions like 'E=mc<sup>2</sup>' can be used directly in node titles.
Trademark and Copyright Symbols
Business and product sites can include trademark symbols using superscript, such as 'Acme Products<sup>™</sup>' or 'Widget Pro<sup>®</sup>' in their content titles.
Multi-line Titles
Using the <br> tag, content creators can create multi-line titles for stylistic purposes, such as poem titles or formatted headings.
Emphasized Key Terms
Educational or instructional content can emphasize key terms in titles using <strong> or <em> tags to draw attention to important concepts.
Tips
- Start with a minimal set of allowed tags and add more as needed. The default <br>, <sub>, and <sup> cover common use cases without exposing unnecessary formatting options.
- The module protects against XSS by only allowing configured tags, but avoid adding potentially dangerous tags like <script>, <style>, or <a> which could create security issues or problematic nesting.
- When using Views, the 'Link to entity' setting works correctly with HTML titles - the link will wrap the formatted title properly.
- The module can be safely uninstalled without breaking Views that use the title field, as it updates the field plugin provider to 'node' during installation.
- For fields other than node titles, you can use the 'HTML-title text' formatter on any string field to apply the same HTML filtering.
Technical Details
Admin Pages 1
/admin/config/user-interface/html_title
Configure which HTML tags are allowed in node titles. Enter the allowed tags in the format <tag> separated by spaces. Only the specified tags will be rendered as HTML in node titles; all other HTML will be stripped for security.
Permissions 1
Hooks 9
hook_preprocess_page_title
Preprocesses page title to render HTML markup in node titles on node view and edit pages
hook_preprocess_breadcrumb
Preprocesses breadcrumb to render HTML markup in breadcrumb links that reference nodes
hook_preprocess_search_result
Preprocesses search results to render HTML markup in node titles displayed in search listings
hook_preprocess_field__node__title
Preprocesses the node title field to render HTML markup when displayed as a field
hook_views_data_alter
Alters Views data to replace the default node title field handler with the custom node_html_title handler
hook_views_plugins_field_alter
Alters Views field plugins to change the provider of node_html_title to 'node' so Views continue working after module uninstallation
hook_theme_registry_alter
Alters theme registry to ensure HTML Title preprocess functions run last, overriding other theme implementations
hook_node_view
Alters node view to apply HTML title filtering when the title is displayed in the node build array
hook_form_node_form_alter
Alters node forms to add a custom submit handler that replaces the node confirmation message with HTML-formatted title
Troubleshooting 5
Check that the desired tags are added to the allowed tags list at /admin/config/user-interface/html_title. By default, only <br>, <sub>, and <sup> are enabled.
This is expected behavior. The module automatically strips HTML tags from RSS output to ensure valid XML. RSS readers typically don't support HTML in title elements.
Clear all caches after enabling the module. The Views data alterations require a cache rebuild to take effect.
The module includes theme registry alterations to ensure its preprocess functions run last. If issues persist, try clearing theme caches.
Clear caches and ensure the module is properly enabled. The module supports Layout Builder but may require cache clearing after initial setup.
Security Notes 4
- The module uses Drupal's Xss::filter() function combined with DOMDocument parsing to safely filter HTML content and prevent XSS attacks.
- All HTML tags not explicitly configured in the allowed tags list are stripped from titles before display.
- The permission 'administer html title settings' has restricted access and should only be granted to trusted administrators who understand the security implications of allowing HTML in titles.
- Avoid adding potentially dangerous tags like <script>, <iframe>, <object>, <embed>, or <a> to the allowed tags list as they could introduce security vulnerabilities.