Forms in Drupal are render arrays too -- built by Form API, then themed by the exact same template-suggestion and preprocess system used for nodes and blocks, right down to individual form elements.
In this Drupal 11 theming tutorial, you'll learn:
• Form alter hooks work identically whether implemented in a module OR a theme's .theme file -- themes get the exact same Form API hook system as modules do.
• #attributes on a render element is Form API's real mechanism for adding classes/data attributes -- Twig then reads these through the {{ attributes }} variable inside form-element.html.twig.
• form|without() at the end ensures every OTHER field (revision log, publishing options, etc.) still renders -- just grouped after the explicitly-placed ones, so nothing gets silently dropped.
• Overriding the GENERIC form-element.html.twig affects the wrapper markup around every single field on every form site-wide -- powerful, but also the most likely override to cause unexpected layout shifts elsewhere.
• form--{form_id}.html.twig (with hyphens replacing underscores) is the most specific suggestion -- exactly mirroring the node--{type}--{view-mode} pattern from earlier in this series.
• Same as every other theming change in this series -- new preprocess functions and new template files both require this rebuild before Drupal's discovery layer picks them up.
Try it yourself: Add a hook_form_FORM_ID_alter() in your sub-theme's .theme file that adds a description and a CSS class to one form field.
This is part 15/25 of our free Drupal 11 Frontend Theming tutorial series -- new lessons every week.
👍 Subscribe for more web development tutorials!
On this page of the site you can watch the video online Theming Forms (Form API Render Elements in Twig) | Drupal Twig Tutorial with a duration of hours minute second in good quality, which was uploaded by the user Web Development Tutorials 05 August 2026, share the link with friends and acquaintances, this video has already been watched No times on youtube and it was liked by 0 viewers. Enjoy your viewing!