Performance: Proper indentation
Proper indentation mainly affects code readability and maintainability, not the browser's rendering speed or page load time.
<html> <head> <title>Page</title> </head> <body> <div> <p>Text</p> </div> </body> </html>
<html><head><title>Page</title></head><body><div><p>Text</p></div></body></html>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| No indentation (all code in one line) | Same DOM nodes created | 0 reflows triggered by indentation | No paint cost difference | [OK] Good for performance but bad for readability |
| Proper indentation with spaces and new lines | Same DOM nodes created | 0 reflows triggered by indentation | No paint cost difference | [OK] Good for readability, no performance impact |
<div>\n <p>Hello</p>\n</div> uses two spaces to indent the <p> tag inside <div>, showing clear nesting. Closing tag aligns with opening.<ul> <li>Apple</li> <li>Banana</li> </ul>
<div>
<p>Welcome</p>
<span>User</span>
</div><section>
<article>
<h2>Title</h2>
</article>
</section>Pass the test and this pattern moves unknown