"#markup" form element can't have children I have my form, but any child of the "#markup" element will not appear when the form is being rendered.

$form['html'] = array(
  '#type' =&gt; 'markup',
  '#markup' =&gt; '&lt;h2&gt;My Heading&lt;/h2&gt;',
  '#tree' =&gt; true,
);

$form['html']['element'] = array(
  '#type' =&gt; 'textfield',
  '#title' =&gt; 'Foo',
);


In this example the "element" form field will not be rendered.

Is this a Drupal bug, or do I need to do something specific?
Not being able to use "#tree" with a "#markup" element seems a bug of Drupal, as the reference page for the form API reports that "#tree" is supported by the "#markup" element.

As workaround, you can also use the "#prefix" property, as in the following code:

$form['html']['element'] = array(
  '#type' =&gt; 'textfield',
  '#title' =&gt; 'Foo',
  '#prefix' =&gt; '&lt;h2&gt;My Heading&lt;/h2&gt;',
);


If it is not rendered as you expect, then you can simply remove "#tree" from your code, which doesn't seem to be needed, if all you want is to render the &lt;h2&gt;My Heading&lt;/h2&gt; tag before the form fields. The form API renders the elements following the order they appear in the array; if you want to alter the order, you can use the "#weight" property.

$form['html'] = array(
 '#type' =&gt; 'markup',
 '#markup' =&gt; '&lt;h2&gt;My Heading&lt;/h2&gt;',
);

$form['html']['element'] = array(
  '#type' =&gt; 'textfield',
  '#title' =&gt; 'Foo',
);