Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Format HTML from the command line

Is it possible to format HTML automatically with a tool, similar to how ESLint formats JavaScript?
Why does it seem that there aren't many customizable options that you can integrate as part of your development pipeline?

I would wish to format HTML in the following way automatically with a command run from the terminal:

<input
  class="input-style"
  placeholder="Replace me!"
/>

For example, I could npm run html-lint and it would fix the syntax in HTML files and warn about cases it can't fix.

like image 646
Waltari Avatar asked Oct 27 '25 13:10

Waltari


2 Answers

js-beautify also works on HTML.

npm install js-beautify
js-beautify --type html file.html

Notice all this beautifying makes the file size increase substantially. The indentation is great for revision and editing, but not so much for hosting. For that reason, you might find html-minifier equally useful.

like image 104
Havenard Avatar answered Oct 30 '25 03:10

Havenard


maybe what you are looking for is prettier, this also supports CLI, even you can also make config, see the complete documentation here. Prettier CLI

I hope this helps.

like image 20
Sigit Avatar answered Oct 30 '25 04:10

Sigit



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!