HTML Formatter
Beautify compressed or difficult-to-read HTML markup
HTML Formatter — what it does
Paste compressed or badly indented HTML and get it back properly structured, with nesting made visible through consistent indentation. Reading minified markup is guesswork; reading indented markup is just reading, and the difference shows the moment you need to find which div actually closes where.
Worked example
A one-line card snippet with a comment, inline elements and two void elements (br, img), run through Format.
HTML source — one line
<!-- invoice card --><div class="card"><h2>Invoice 1042</h2><p>Due <strong>2026-11-05</strong><br>Pay by bank transfer.</p><ul><li>Desk lamp</li><li>USB cable</li></ul><img src="logo.png" alt="Logo"></div>
Output — formatted
<!-- invoice card -->
<div class="card">
<h2>
Invoice 1042
</h2>
<p>
Due
<strong>
2026-11-05
</strong>
<br>
Pay by bank transfer.
</p>
<ul>
<li>
Desk lamp
</li>
<li>
USB cable
</li>
</ul>
<img src="logo.png" alt="Logo">
</div>Every run of text gets its own line, inline tags such as strong are indented like block tags, and br and img are recognised as void elements so nothing is indented under them.
When this tool helps
- Making a minified page source readable while debugging a layout problem.
- Tidying markup copied out of a CMS or email template before editing it.
- Reviewing generated HTML to check the structure a template actually produced.
How to use it
- Paste the HTML source into the input box.
- Format the markup.
- Read the indented structure.
- Copy the formatted HTML back into your editor.
Accuracy, limits, and good practice
- Formatting rewrites whitespace, and whitespace between inline elements is meaningful in HTML — check spacing around links and spans after reformatting.
- Inside pre and textarea elements, whitespace is content; treat reformatted output there with care.
- Unbalanced tags become obvious once indentation is applied, which makes formatting a fast way to find a missing closing tag.
- Format before diffing two versions of a page. A minified file produces one enormous changed line, while formatted markup diffs element by element.
Frequently asked questions
Will formatting change how the page renders?
Usually not, but whitespace-sensitive inline layouts can shift slightly. Compare before deploying reformatted markup.
Does it fix invalid HTML?
No. It arranges what you give it; a validator is the tool for correctness. Odd indentation often reveals where the structure is broken.
Can I minify it again afterwards?
Yes, the HTML minifier reverses the operation for production output.
Can I format a whole page including its scripts?
Inline script and style blocks pass through as text. Run the JavaScript and CSS formatters on those blocks separately.
What indentation does it use, and can I change it?
Two spaces per level, fixed; there is no tab or four-space option. Attributes are left exactly as written on the tag line, including their quoting and order.
How does it treat self-closing tags and custom elements?
A tag ending in /> is treated as closed, so <my-icon /> does not indent what follows; a custom element written <my-icon>…</my-icon> indents like a div. The list of void elements that never indent is the HTML one (area, base, br, col, embed, hr, img, input, link, meta, param, source, track, wbr), so an unclosed <p> or <li> still pushes the following lines one level deeper.
Related tools on this site
- Email Address Extractor — Find and clean email addresses from pasted text
- JWT Decoder — Decode JWT header and payload without verification
- Slug Generator — Turn titles into clean URL-friendly slugs
Further reading: Cleaning Up Text You Pasted From Somewhere Else
Everything above runs inside this page. HTML Formatter needs no account, no upload, and no server round trip — close the tab and nothing is left behind.
HTML 格式化能做什麼
貼上壓縮過或縮排混亂的 HTML,取回結構清楚、以一致縮排呈現巢狀關係的版本。讀壓縮標記是在猜,讀縮排標記就只是在讀——當你要找出某個 div 到底在哪裡收尾時,差別立刻顯現。
實際範例
一行卡片片段,含註解、行內元素與兩個空元素(br、img),按下格式化。
HTML 原始碼:單獨一行
<!-- invoice card --><div class="card"><h2>Invoice 1042</h2><p>Due <strong>2026-11-05</strong><br>Pay by bank transfer.</p><ul><li>Desk lamp</li><li>USB cable</li></ul><img src="logo.png" alt="Logo"></div>
格式化後
<!-- invoice card -->
<div class="card">
<h2>
Invoice 1042
</h2>
<p>
Due
<strong>
2026-11-05
</strong>
<br>
Pay by bank transfer.
</p>
<ul>
<li>
Desk lamp
</li>
<li>
USB cable
</li>
</ul>
<img src="logo.png" alt="Logo">
</div>每段文字各佔一行,strong 這類行內標籤和區塊標籤一樣縮排;br 與 img 被辨識為空元素,後面的內容不會縮進去。
什麼時候用得上
- 除錯版面問題時,把壓縮過的頁面原始碼變得可讀。
- 整理從 CMS 或郵件範本複製出來的標記,再進行編輯。
- 檢視產生出來的 HTML,確認範本實際輸出的結構。
使用步驟
- 把 HTML 原始碼貼進輸入框。
- 執行格式化。
- 閱讀縮排後的結構。
- 把整理好的 HTML 複製回編輯器。
精確度、限制與實務建議
- 格式化會改寫空白,而 HTML 中行內元素之間的空白是有意義的——重排後請檢查連結與 span 周圍的間距。
- 在 pre 與 textarea 元素內,空白就是內容,重排結果請謹慎處理。
- 縮排一套上去,標籤不對稱就無所遁形,因此格式化也是找漏掉結束標籤的快方法。
- 比對兩版頁面前請先格式化。壓縮檔會產生一整行巨大的差異,格式化後的標記則能逐元素比對。
常見問題
格式化會改變頁面呈現嗎?
通常不會,但對空白敏感的行內排版可能略有位移。部署前請先比對。
會修正無效的 HTML 嗎?
不會。它只整理你給的內容,正確性請交給驗證工具。不過奇怪的縮排常常正好指出結構壞在哪。
之後可以再壓縮嗎?
可以,HTML 壓縮工具能把它變回適合上線的形式。
可以連內嵌腳本一起格式化嗎?
內嵌的 script 與 style 區塊會原樣通過,請另外用 JavaScript 與 CSS 工具處理那些區塊。
縮排是幾格?可以改嗎?
固定每層兩個空格,沒有 Tab 或四格的選項。屬性照標籤行上原本的寫法保留,包括引號與順序。
自閉合標籤與自訂元素會怎麼縮排?
以 /> 結尾的標籤視為已關閉,所以 <my-icon /> 不會讓後面的內容縮排;寫成 <my-icon>…</my-icon> 的自訂元素則和 div 一樣縮排。永不縮排的空元素清單就是 HTML 的那份(area、base、br、col、embed、hr、img、input、link、meta、param、source、track、wbr),因此沒關閉的 <p> 或 <li> 仍會讓後續各行多縮一層。
本站相關工具
- Email 地址提取器 — 從貼上的文字中找出並整理 Email 地址
- JWT 解碼器 — 在不驗證簽章的情況下解碼 JWT 標頭與內容
- 網址別名產生器 — 將標題轉換成乾淨的網址 Slug
延伸閱讀: 清理從別處貼上的文字
以上步驟全部在這個頁面內完成,HTML 格式化 不需要註冊、不上傳檔案、也不經過伺服器,關閉分頁後不會留下任何資料。