I want to format HTML source files from the command line, one file at a time or in bulk.
Should be installable on Windows, Linux, and macOS.
Must be capable of formatting in place, overwriting the current HTML file(s).
Should allow setting the indent size to a single space. 1
Should merely format the HTML code – not validate it.
Must not make any false claims about the HTML code.
<body>tags should not be indented.
The maximum number of line breaks to be preserved may be set to zero.
A tool I tried but discarded
An online tool
The online formatter I've found to best meet my requirements, is HTML Formatter.
- The documentation of the NPM package
- List of HTML Self-Closing Tags
- An example HTML file
- The download page for Node.js
- Screenshot from running
- Closing elements that have implied end tags
- HTML Formatter – an online formatter
1 The rationale for one-space indents is two-fold.
I want to keep down the file size.
When watching the file in a text editor, I want to use up as little horizontal space as possible.
npm install --global prettier
Then I downloaded the file
form-demo.html – in a zip file, so that the unformatted file can easily be restored.
It has a
<form> tag with a property
action set to
/search (instead of
I tried to format