Dec 17, 2019 in Drupal 8, Snippets

Getting the output like you want it to be an be quite a challenge in drupal. This snippet shows you how you can add markup to your form labels in drupal 8.

use Drupal\Core\Render\Markup;

$form['my_element'] = [
   '#type' => 'radios',
   '#title' => Markup::create('<span class="title">My options</span><span class="fa fa-question"></span>'),
   '#options' => ['option 1','option 2']
];