diff --git a/lib/jsdom/browser/domtohtml.js b/lib/jsdom/browser/domtohtml.js
index <HASH>..<HASH> 100644
--- a/lib/jsdom/browser/domtohtml.js
+++ b/lib/jsdom/browser/domtohtml.js
@@ -92,15 +92,15 @@ var stringifyElement = function(element) {
 var formatHTML = function(html) {
     var formatted = '',
         reg = /(>)(<)(\/*)/g,
-        html = html.replace(reg, '$1\r\n$2$3'),
         pad = 0,
         tags = [];
 
-        for (i in singleTags) {
+        for (var i in singleTags) {
             tags.push(i);
         }
         tags = '<' + tags.join('|<');
 
+    html = html.replace(/(<(\/?\w+).*?>)(?=<(?!\/\2))/gi, '$1\r\n');
     html.split('\r\n').forEach(function(node, index) {
         var indent = 0, padding = '', i;
Don't break and indent empty tags, especially <textarea></textarea> as the resulting whitespace would be interpreted as literal field-value by the browser.