How to use HTML tags in form error messages I'm using \Drupal\Core\Form\FormState::setError() in a form validation hook to display a message if the validation fails. I want to include some HTML on it, but the second parameter of setError(), the error message, is escaped. As a result, the HTML code is visible in the message box. How can I avoid this and have HTML in the box?
All errors added to the form state will be finally handled by drupal_set_message.
That means that you can either use strings, or any class that implements the MarkupInterface.
Looking at that list I would say that what you are looking for is FormattableMarkup or even better TranslatableMarkup.  

An example would then be:

$your_error = new TranslatableMarkup('&lt;b&gt;@message!&lt;/b&gt;', array('@message' =&gt; 'A bold error'));
$form_state-&gt;setError($element, $your_error); 


Good luck!