 <p>i found this problem earlier and the work around was to use the builder directly</p> <pre><code>def test = { def sw = new StringWriter() def b = new MarkupBuilder(sw) b.html(contentType: "text/html") { div(id: "myDiv") { p "somess text inside the div" b.form(action: 'get') { p "inside form" } } } render sw } </code></pre> <p>will render the following HTML</p> <pre><code>&lt;html contentType='text/html'&gt; &lt;div id='myDiv'&gt; &lt;p&gt;somess text inside the div&lt;/p&gt; &lt;form action='get'&gt; &lt;p&gt;inside form&lt;/p&gt; &lt;/form&gt; &lt;/div&gt; &lt;/html&gt; </code></pre>