Beautify_Html is (almost) direct PHP port of beautify-html.js, part of JS Beautifier project. It indents HTML code, making it beautiful.
Done for fun, no profit, MIT license.
$html = '<ul><li>Html</li><li>to</li><li>indent</li></ul>';
$beautify = new Beautify_Html(array(
'indent_inner_html' => false,
'indent_char' => " ",
'indent_size' => 2,
'wrap_line_length' => 32786,
'unformatted' => ['code', 'pre'],
'preserve_newlines' => false,
'max_preserve_newlines' => 32786,
'indent_scripts' => 'normal' // keep|separate|normal
));
echo $beautify->beautify($html);
All options are optional.