webform drupal 8 view only field

This is a simple checkbox in the webform UI:

Note that neither of these enforces the read only aspect on a code level, so do not use this for anything that needs to be securely locked down. Visitors can manipulate the DOM (as through browser tools) and change the “read only” value.

If building your webform element programatically, as for any form element, the