Drupal 10: Adding Classes To Form Element Wrapper

$form['name'] = [
  '#type' => 'textfield',
  '#title' => $this->t('Name'),
  '#wrapper_attributes' => [
    'class' => [
      'wrapper-class',
    ],
  ],
];

This creates the following HTML.

<div class="wrapper-class">
  <label for="edit-name">Name</label>
  <input class="form-text" type="text" id="edit-name" name="name" value="test">
</div>

 

Add new comment

The content of this field is kept private and will not be shown publicly.