field_label_visibility
Introduction
Field Label Visibility lets site builders customize, per widget, how a field label element is rendered on a node form, directly from Manage form display. No custom code, no theme overrides, no hook_form_alter(): every option is exposed as a UI control on the widget settings panel.
Unlike Manage display, which targets the front-end view of an entity, this module operates at the form widget level and only affects the entity form display.
Features
For each enabled widget, the module exposes:
- Hide label — removes the
labelelement entirely from the rendered DOM (not just visually hidden). - Custom label text, with an optional Singular / Plural mode (
Singular|Plural) that picks one form at runtime depending on the number of field items. - Inline format toolbar with alignment radios (left, center, right) and three formatting toggles (bold, italic, underline), CKEditor-style.
- Optional inline wrapper tag applied inside the native
label:span,smallormark. These are the only phrasing-content tags valid aslabelchildren per the WHATWG specification; headings (h1–h6),pandlegendare not offered because they would produce invalid HTML. - CSS classes and id textfields, sanitized at render time.
How it works
The module has three operating modes, all targeting the native label for="…" Drupal already renders for the field — never a parallel decorative element:
- Default (no wrapper tag). The configured id, class and inline style flow directly to the native
labelthrough Drupal's form-element preprocess pipeline. Thefor=association with the input is preserved, and the configured attributes appear on thelabelelement itself. - Wrapper (
span,small,mark). The label text is wrapped in the chosen tag with the configured id/class/style; the surroundinglabel for="…"stays in place so the input keeps its accessible name. The configured attributes appear on the inner wrapper, not on the outerlabel. - Hide.
#title_displayis set to'none', which tells Drupal core not to render thelabelat all. The element is absent from the DOM, not visually hidden via CSS.
Configuration
- Go to Administration » Configuration » User interface » Field Label Visibility (
/admin/config/user-interface/field-label-visibility). - Select the content types where the per-widget controls should appear.
- Save the configuration.
- Open Structure » Content types » [type] » Manage form display, click the gear icon next to any field widget on an enabled content type, and configure the per-widget options.
The settings page requires the Administer Field Label Visibility permission, which is restricted by default.
Security and accessibility
All user-supplied values are sanitized before being rendered:
- The wrapper tag is restricted to an allowlist (
span,small,mark). - CSS classes are filtered to
[A-Za-z0-9_- ]. - The id is filtered to
[A-Za-z0-9_-]. - Alignment is restricted to
left,center,right. - The label text is HTML-escaped before being injected.
The module never breaks the accessible name of the input: in every mode the original label for="…" is either preserved (with custom text and/or attributes) or completely removed from the DOM. There is never a duplicate, decorative twin label competing with the real one.
Differences with similar projects
Field Label Visibility is intentionally narrow in scope: it customizes how the form-side label of an individual field widget is rendered, configured per widget from "Manage form display", without writing any custom code or theme overrides. Nothing comparable exists in Drupal core or in the most common contrib alternatives:
- Field UI (Drupal core) lets you reorder, group and pick widgets, but it does not expose any per-widget control over the
labelitself — you cannot change its text, hide it from the DOM, wrap it in an inline tag or attach an id/class/style without writinghook_form_alter()or template overrides. - Field Group groups several fields under a shared wrapper (fieldset, tab, accordion, …). It operates on the wrapper, not on the individual field labels, and it does not let you override a single
labelper widget. - Field Formatter Class adds CSS classes to display formatters on the front-end view of an entity. It does not touch entity forms, which is the surface this module operates on.
- Display Suite focuses on the entity render pipeline (Manage display) with its own layouts, fields and view modes. It does not expose per-widget label controls on Manage form display.
hook_form_alter()/ custom preprocess can of course replicate any of the above, but it requires PHP and a custom module or theme per project. Field Label Visibility makes the same outcome reachable for site builders directly from the UI.
In short: choose Field Label Visibility when you need to tune the label of a specific field widget on entity forms — change its text, hide it from the DOM, wrap it in span/small/mark, attach an id/class, align it or make it bold/italic/underline — from the UI, without touching code. For grouping fields use Field Group; for front-end display tweaks use Display Suite or Field Formatter Class; for everything else there is hook_form_alter().
Development
Parts of this module were written with the assistance of AI-assisted coding tools. All code has been reviewed, tested and maintained by the human maintainer listed below.