Webform Message / Custom Module
One of the features and APIs of the Webform module for Drupal 8 that I personally enjoy using is support for inline messages using the WebformMessage element 

The WebformMessage element supports dismissal messages and #states API.

Here is the YAML version of a Message element

message:
  '#type': webform_message 
  '#message_type': warning 
  '#message_close': true,
  '#message_storage': user,
  '#message_message': 'This message can be dismissed by a user'


Here is the PHP syntax, which can be used in your custom code.

$build['message'] = [
  '#type' =&gt; 'webform_message',
  '#message_id' =&gt; 'custom_message_id',
  '#message_type' =&gt; 'warning',
  '#message_close' =&gt; TRUE,
  '#message_storage' =&gt; WebformMessage::STORAGE_USER,
  '#message_message' =&gt; $this-&gt;t('This message can be dismissed by a user'),
];