How do I display a form element only if the above checkbox is checked?
Use like this:

$form['count_prefix'] = [
  '#type' =&gt; 'textfield',
  '#title' =&gt; t('Count prefix'),
  '#description' =&gt; t('Set a prefix to be displayed before count number e.g. (5), [5] or &lt;5&gt;'),
  '#required' =&gt; FALSE,
  '#default_value' =&gt; $config['count_prefix'],
  '#states' =&gt; array(
    'visible' =&gt; array(
      ':input[name="display_count"]' =&gt; array('checked' =&gt; TRUE),
    ),
  ),
];
$form['count_suffix'] = [
  '#type' =&gt; 'textfield',
  '#title' =&gt; t('Count suffix'),
  '#description' =&gt; t('Set a suffix to be displayed after count number e.g. (5), [5] or &lt;5&gt;'),
  '#required' =&gt; FALSE,
  '#default_value' =&gt; $config['count_suffix'],
  '#states' =&gt; array(
    'visible' =&gt; array(
      ':input[name="display_count"]' =&gt; array('checked' =&gt; TRUE),
    ),
  ),
];