title: How to Pretty Print HTML to a file, with indentation
body: <p>I am using <a href="http://lxml.de/lxmlhtml.html" rel="noreferrer">lxml.html</a> to generate some HTML. I want to pretty print (with indentation) my final result into an html file. How do I do that?</p>
  <p>This is what I have tried and got till now</p>
  <pre><code>import lxml.html as lh
  from lxml.html import builder as E
  sliderRoot=lh.Element(&quot;div&quot;, E.CLASS(&quot;scroll&quot;), style=&quot;overflow-x: hidden; overflow-y: hidden;&quot;)
  scrollContainer=lh.Element(&quot;div&quot;, E.CLASS(&quot;scrollContainer&quot;), style=&quot;width: 4340px;&quot;)
  sliderRoot.append(scrollContainer)
  print lh.tostring(sliderRoot, pretty_print = True, method=&quot;html&quot;)
  </code></pre>
  <p>As you can see I am using the <code>pretty_print=True</code> attribute. I thought that would give indented code, but it doesn't really help. This is the output :</p>
  <p><code>&lt;div style=&quot;overflow-x: hidden; overflow-y: hidden;&quot; class=&quot;scroll&quot;&gt;&lt;div style=&quot;width: 4340px;&quot; class=&quot;scrollContainer&quot;&gt;&lt;/div&gt;&lt;/div&gt;</code></p>