Adding an HTML 5 placeholder attribute to a webform component in a theme
Last updated on
30 April 2025
You are browsing documentation for an older version of Drupal, which is not supported any longer, and the information may not be correct. See current documentation for Contributed modules
An HTML 5 placeholder attribute is added to a theme by using a preprocess hook. This example is for an e-mail component:
<?php
function THEMENAME_preprocess_webform_email(&$variables) {
$variables['element']['#attributes']['placeholder'] = t('Email Address');
}
?>
For anyone using an older or outdated version of Webform, it's worth noting that HTML5 placeholder support was added in the 7.x-4.x branch (June 2013) and is now a native, built-in option when adding or editing a form component.
Help improve this page
Page status: Not set
You can:
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion