Last updated
What HTML Beautification Does
HTML beautification (also called pretty-printing) reformats HTML code to be more readable by adding consistent indentation, line breaks, and spacing. It's the opposite of minification. Beautified HTML is easier to read, debug, and maintain — especially when working with HTML generated by tools, CMS exports, or copied from browser DevTools.
Beautification Rules
- Block elements (
div,p,section,article) get their own lines with indented children. - Inline elements (
span,a,strong,em) stay on the same line as their content. - Void elements (
img,br,input,meta) are self-closing and don't indent. - Pre/code blocks preserve their whitespace exactly — beautifiers should not reformat content inside
<pre>.
Using Prettier for HTML
# Install Prettier
npm install -D prettier
# Format a single HTML file
npx prettier --write index.html
# Format all HTML files
npx prettier --write "**/*.html"
# Check without modifying (CI)
npx prettier --check "**/*.html"
Prettier HTML Configuration
// .prettierrc
{
"printWidth": 100,
"tabWidth": 2,
"useTabs": false,
"htmlWhitespaceSensitivity": "css",
"bracketSameLine": false,
"singleAttributePerLine": false
}