簡化您的工作流程:搜尋 miniwebtool。
添加插件
相關工具
CSS美化工具CSS盒陰影產生器Googlebot抓取大小檢測器HTML轉Markdown轉換器圖片Base64轉換器javascript壓縮/美化工具🔍 抄襲檢測器SQL格式化工具XML轉JSON轉換器YAML格式化/驗證器
主頁 > 文本工具 > 文本修改工具 > HTML美化器
 

HTML美化器

免費在線 HTML美化器與格式化工具。立即格式化壓縮或混亂的 HTML,並具有正確的縮排、標籤對齊和屬性整理。客戶端處理 — 您的代碼絕不會離開瀏覽器。

HTML美化器
🔒 100% 客戶端處理 — 您的代碼永遠不會離開瀏覽器
快速範例
⚡ 壓縮後的 HTML 🔀 混亂的縮進 📐 語義佈局 📝 表單元素
輸入 HTML
輸出結果
縮進:
⚠ 標籤警告
    0
    標籤總數
    0
    唯一元素
    0
    最大深度
    0
    屬性數
    0
    輸入 (字節)
    0
    輸出 (字節)
    ⟨/⟩ 標籤細分
    體積變化
    0%
    ', messy: '\n\n\n 部落格文章\n \n\n \n
    \n
    \n

    理解 Flexbox

    \n
    \n Jane Doe\n \n
    \n

    Flexbox 是一個強大的 CSS 佈局模組,讓設計靈活的響應式佈局結構變得簡單。

    \n

    關鍵概念

    \n
      \n
    • Flex 容器
    • \n
    • Flex 項目
    • \n
    • 主軸 vs 交叉軸
    • \n
    • Flex 換行
    • \n
    \n
    \n

    Flexbox 永遠改變了我們對 CSS 佈局的思考方式。

    \n
    \n

    閱讀更多關於 CSS Grid 的二維佈局內容。

    \n
    \n
    \n \n', semantic: '\n\n\n \n \n 語義化 HTML5 佈局\n\n\n
    \n \n
    \n
    \n
    \n
    \n

    文章標題

    \n

    發佈於

    \n
    \n
    \n

    簡介

    \n

    本篇文章展示了提升可訪問性和 SEO 的語義化 HTML5 元素。

    \n
    \n HTML5 語義化元素圖解\n
    語義化元素為文檔結構提供含義。
    \n
    \n
    \n \n \n
    \n
    \n
    \n

    © 2026 我的網站。使用語義化 HTML 構建。

    \n
    \n\n', form: '註冊表單
    個人資訊
    偏好設置
    ' }; function hbLoadExample(key) { document.getElementById('htmlInput').value = HB_EXAMPLES[key]; document.getElementById('htmlOutput').value = ''; hbHideStats(); } /* ── Utility Functions ───────────────────── */ function hbClearInput() { document.getElementById('htmlInput').value = ''; document.getElementById('htmlOutput').value = ''; hbHideStats(); } function hbPasteFromClipboard() { navigator.clipboard.readText().then(function(text) { document.getElementById('htmlInput').value = text; }).catch(function() {}); } function hbCopyOutput() { var text = document.getElementById('htmlOutput').value; if (!text) return; var btn = document.getElementById('hbCopyBtn'); navigator.clipboard.writeText(text).then(function() { btn.classList.add('copied'); btn.textContent = '✓ 已複製'; setTimeout(function() { btn.classList.remove('copied'); btn.textContent = '\u29C9 複製'; }, 1500); }).catch(function() {}); } function hbDownloadOutput() { var code = document.getElementById('htmlOutput').value; if (!code) return; var blob = new Blob([code], { type: 'text/html' }); var a = document.createElement('a'); a.href = URL.createObjectURL(blob); a.download = 'beautified.html'; a.click(); URL.revokeObjectURL(a.href); } function hbHideStats() { document.getElementById('hbStatsRibbon').classList.remove('visible'); document.getElementById('hbTagBreakdown').classList.remove('visible'); document.getElementById('hbDiffBar').classList.remove('visible'); document.getElementById('hbWarnings').classList.remove('visible'); } /* ── HTML Element Classifications ─────────── */ var VOID_ELEMENTS = ['area','base','br','col','embed','hr','img','input','link','meta','param','source','track','wbr']; var INLINE_ELEMENTS = ['a','abbr','acronym','b','bdo','big','br','button','cite','code','dfn','em','i','img','input','kbd','label','map','object','output','q','samp','select','small','span','strong','sub','sup','textarea','time','tt','u','var']; var RAW_TEXT_ELEMENTS = ['script','style']; var PRESERVE_ELEMENTS = ['pre','code','textarea','script','style']; /* ── HTML Beautifier Engine ──────────────── */ function hbTokenize(html) { var tokens = []; var i = 0; var len = html.length; while (i < len) { // Comment if (html.substr(i, 4) === '', i + 4); if (end === -1) end = len - 3; tokens.push({ type: 'comment', value: html.substring(i, end + 3) }); i = end + 3; } // DOCTYPE else if (html.substr(i, 9).toUpperCase() === '', i); if (end === -1) end = len - 1; tokens.push({ type: 'doctype', value: html.substring(i, end + 1) }); i = end + 1; } // CDATA else if (html.substr(i, 9) === '', i + 9); if (end === -1) end = len - 3; tokens.push({ type: 'cdata', value: html.substring(i, end + 3) }); i = end + 3; } // Closing tag else if (html.substr(i, 2) === '', i); if (end === -1) end = len - 1; var tag = html.substring(i + 2, end).trim().toLowerCase(); tokens.push({ type: 'close', tag: tag, value: html.substring(i, end + 1) }); i = end + 1; } // Opening tag else if (html[i] === '<' && i + 1 < len && /[a-zA-Z]/.test(html[i + 1])) { var end = i + 1; var inQuote = false; var quoteChar = ''; while (end < len) { var ch = html[end]; if (inQuote) { if (ch === quoteChar) inQuote = false; } else { if (ch === '"' || ch === "'") { inQuote = true; quoteChar = ch; } else if (ch === '>') break; } end++; } if (end >= len) end = len - 1; var tagContent = html.substring(i + 1, end); var selfClosing = tagContent.charAt(tagContent.length - 1) === '/'; if (selfClosing) tagContent = tagContent.substring(0, tagContent.length - 1); // Parse tag name and attributes var spaceIdx = tagContent.search(/[\s\/]/); var tagName, attrStr; if (spaceIdx === -1) { tagName = tagContent.trim(); attrStr = ''; } else { tagName = tagContent.substring(0, spaceIdx).trim(); attrStr = tagContent.substring(spaceIdx).trim(); } tagName = tagName.toLowerCase(); var isVoid = VOID_ELEMENTS.indexOf(tagName) !== -1; // Parse attributes var attrs = hbParseAttributes(attrStr); tokens.push({ type: 'open', tag: tagName, attrs: attrs, selfClosing: selfClosing || isVoid, isVoid: isVoid, raw: html.substring(i, end + 1) }); i = end + 1; // Handle raw text elements (script, style) if (RAW_TEXT_ELEMENTS.indexOf(tagName) !== -1 && !selfClosing && !isVoid) { var closeTag = ''); return parts.join(''); } function hbBeautifyCode(html, opts) { var indent = opts.indent || ' '; var sortAttrs = opts.sortAttrs || false; var removeComments = opts.removeComments || false; var preserveInline = opts.preserveInline !== false; var tokens = hbTokenize(html); var output = []; var level = 0; var preserveStack = 0; function addIndent(d) { var r = ''; for (var j = 0; j < d; j++) r += indent; return r; } function isInline(tagName) { return preserveInline && INLINE_ELEMENTS.indexOf(tagName) !== -1; } function isPreserve(tagName) { return PRESERVE_ELEMENTS.indexOf(tagName) !== -1; } for (var i = 0; i < tokens.length; i++) { var token = tokens[i]; if (token.type === 'comment') { if (!removeComments) { if (preserveStack > 0) { output.push(token.value); } else { output.push(addIndent(level) + token.value); } } } else if (token.type === 'doctype') { output.push(token.value); } else if (token.type === 'cdata') { output.push(addIndent(level) + token.value); } else if (token.type === 'open') { var tag = hbBuildTag(token.tag, token.attrs, token.selfClosing, sortAttrs); if (preserveStack > 0) { output.push(tag); if (isPreserve(token.tag) && !token.selfClosing) preserveStack++; } else if (isInline(token.tag)) { // Check if previous output ends with text on the same line if (output.length > 0) { var last = output[output.length - 1]; // If last line has text content, append inline tag to same line var lastNewline = last.lastIndexOf('\n'); var lastLine = lastNewline === -1 ? last : last.substring(lastNewline + 1); if (lastLine.trim() && !lastLine.trim().match(/^<\/(div|section|article|main|header|footer|nav|aside|ul|ol|li|table|tr|td|th|thead|tbody|tfoot|form|fieldset|dl|dt|dd|details|summary|figure|figcaption|blockquote|p|h[1-6]|pre|hr)>/i)) { output[output.length - 1] = last + tag; } else { output.push(addIndent(level) + tag); } } else { output.push(addIndent(level) + tag); } if (!token.selfClosing) { // Don't increase indent for inline elements } } else { output.push(addIndent(level) + tag); if (!token.selfClosing) { if (isPreserve(token.tag)) preserveStack++; level++; } } } else if (token.type === 'close') { if (preserveStack > 0) { if (isPreserve(token.tag)) preserveStack--; output.push(''); } else if (isInline(token.tag)) { // Append closing inline tag to previous line if (output.length > 0) { output[output.length - 1] = output[output.length - 1] + ''; } else { output.push(''); } } else { level--; if (level < 0) level = 0; output.push(addIndent(level) + ''); } } else if (token.type === 'text') { if (preserveStack > 0 || token.preserve) { output.push(token.value); } else { var text = token.value; // Collapse whitespace for non-preserve context var trimmed = text.replace(/\s+/g, ' ').trim(); if (trimmed) { // Check if adjacent to inline elements var prevToken = i > 0 ? tokens[i - 1] : null; var nextToken = i < tokens.length - 1 ? tokens[i + 1] : null; var prevIsInline = prevToken && ((prevToken.type === 'open' && isInline(prevToken.tag)) || (prevToken.type === 'close' && isInline(prevToken.tag))); var nextIsInline = nextToken && ((nextToken.type === 'open' && isInline(nextToken.tag)) || (nextToken.type === 'close' && isInline(nextToken.tag))); if (prevIsInline || nextIsInline) { // Append to previous line for inline continuity if (output.length > 0) { output[output.length - 1] = output[output.length - 1] + trimmed; } else { output.push(trimmed); } } else { output.push(addIndent(level) + trimmed); } } } } } var result = output.join('\n'); // Clean up multiple blank lines result = result.replace(/\n{3,}/g, '\n\n'); return result.trim(); } function hbMinifyCode(html) { // Remove comments html = html.replace(//g, ''); // Collapse whitespace between tags html = html.replace(/>\s+<'); // Collapse internal whitespace html = html.replace(/\s+/g, ' '); // Trim return html.trim(); } /* ── Stats Calculation ───────────────────── */ function hbGetStats(html) { var stats = { totalTags: 0, uniqueTags: {}, maxDepth: 0, attrCount: 0, warnings: [], tagTypes: { block: {}, inline: {}, void_el: {}, semantic: {} } }; var SEMANTIC = ['article','aside','details','figcaption','figure','footer','header','main','mark','nav','section','summary','time']; var BLOCK = ['div','p','h1','h2','h3','h4','h5','h6','ul','ol','li','table','tr','td','th','thead','tbody','tfoot','form','fieldset','legend','blockquote','pre','dl','dt','dd','hr']; var tokens = hbTokenize(html); var stack = []; var depth = 0; for (var i = 0; i < tokens.length; i++) { var t = tokens[i]; if (t.type === 'open') { stats.totalTags++; stats.uniqueTags[t.tag] = (stats.uniqueTags[t.tag] || 0) + 1; if (t.attrs) stats.attrCount += t.attrs.length; // Classify tag if (SEMANTIC.indexOf(t.tag) !== -1) { stats.tagTypes.semantic[t.tag] = (stats.tagTypes.semantic[t.tag] || 0) + 1; } else if (VOID_ELEMENTS.indexOf(t.tag) !== -1) { stats.tagTypes.void_el[t.tag] = (stats.tagTypes.void_el[t.tag] || 0) + 1; } else if (INLINE_ELEMENTS.indexOf(t.tag) !== -1) { stats.tagTypes.inline[t.tag] = (stats.tagTypes.inline[t.tag] || 0) + 1; } else if (BLOCK.indexOf(t.tag) !== -1 || t.tag === 'html' || t.tag === 'head' || t.tag === 'body') { stats.tagTypes.block[t.tag] = (stats.tagTypes.block[t.tag] || 0) + 1; } else { stats.tagTypes.block[t.tag] = (stats.tagTypes.block[t.tag] || 0) + 1; } if (!t.selfClosing) { stack.push(t.tag); depth = stack.length; if (depth > stats.maxDepth) stats.maxDepth = depth; } } else if (t.type === 'close') { stats.totalTags++; // Find matching open tag var found = false; for (var j = stack.length - 1; j >= 0; j--) { if (stack[j] === t.tag) { // Warn about any unclosed tags above this for (var k = stack.length - 1; k > j; k--) { stats.warnings.push('未關閉的 <' + stack[k] + '> 標籤'); } stack.splice(j); found = true; break; } } if (!found) { stats.warnings.push('異常的閉合標籤 '); } } } // Any remaining tags on stack are unclosed for (var s = 0; s < stack.length; s++) { stats.warnings.push('未關閉的 <' + stack[s] + '> 標籤'); } return stats; } /* ── Display Functions ───────────────────── */ function hbShowStats(inputHtml, outputHtml) { var stats = hbGetStats(inputHtml); var inputSize = new Blob([inputHtml]).size; var outputSize = new Blob([outputHtml]).size; document.getElementById('hbStatTags').textContent = stats.totalTags; document.getElementById('hbStatUnique').textContent = Object.keys(stats.uniqueTags).length; document.getElementById('hbStatDepth').textContent = stats.maxDepth; document.getElementById('hbStatAttrs').textContent = stats.attrCount; document.getElementById('hbStatInputSize').textContent = hbFormatSize(inputSize); document.getElementById('hbStatOutputSize').textContent = hbFormatSize(outputSize); document.getElementById('hbStatsRibbon').classList.add('visible'); // Tag breakdown var grid = document.getElementById('hbTagGrid'); grid.innerHTML = ''; var types = [ { obj: stats.tagTypes.semantic, cls: 'tag-pill-semantic', label: '語義元素' }, { obj: stats.tagTypes.block, cls: 'tag-pill-block', label: '塊級元素' }, { obj: stats.tagTypes.inline, cls: 'tag-pill-inline', label: '內聯元素' }, { obj: stats.tagTypes.void_el, cls: 'tag-pill-void', label: '空元素' } ]; var hasAny = false; for (var t = 0; t < types.length; t++) { var keys = Object.keys(types[t].obj).sort(); for (var k = 0; k < keys.length; k++) { hasAny = true; var pill = document.createElement('span'); pill.className = 'tag-pill ' + types[t].cls; pill.innerHTML = '<' + keys[k] + '> ' + types[t].obj[keys[k]] + ''; grid.appendChild(pill); } } if (hasAny) { document.getElementById('hbTagBreakdown').classList.add('visible'); } // Warnings if (stats.warnings.length > 0) { var list = document.getElementById('hbWarningsList'); list.innerHTML = ''; // Deduplicate var unique = []; var seen = {}; for (var w = 0; w < stats.warnings.length; w++) { if (!seen[stats.warnings[w]]) { seen[stats.warnings[w]] = true; unique.push(stats.warnings[w]); } } for (var u = 0; u < unique.length && u < 10; u++) { var li = document.createElement('li'); li.textContent = unique[u]; list.appendChild(li); } document.getElementById('hbWarnings').classList.add('visible'); } // Diff bar var pct, isShrink; if (inputSize === 0) { pct = 0; isShrink = true; } else { var change = ((outputSize - inputSize) / inputSize) * 100; isShrink = change < 0; pct = Math.abs(change); } var fill = document.getElementById('hbDiffFill'); var cappedPct = Math.min(pct, 100); fill.style.width = cappedPct + '%'; fill.className = 'diff-fill ' + (isShrink ? 'shrink' : 'grow'); document.getElementById('hbDiffValue').textContent = (isShrink ? '-' : '+') + pct.toFixed(1) + '%'; document.getElementById('hbDiffBar').classList.add('visible'); } function hbFormatSize(bytes) { if (bytes < 1024) return bytes + ''; return (bytes / 1024).toFixed(1) + 'K'; } /* ── Main Actions ────────────────────────── */ function hbBeautify() { var input = document.getElementById('htmlInput').value; if (!input.trim()) return; var indentSel = document.getElementById('hbIndentSize').value; var indent; if (indentSel === 'tab') indent = '\t'; else indent = new Array(parseInt(indentSel) + 1).join(' '); var opts = { indent: indent, sortAttrs: document.getElementById('hbOptSortAttrs').checked, removeComments: document.getElementById('hbOptRemoveComments').checked, preserveInline: document.getElementById('hbOptPreserveInline').checked }; var output = hbBeautifyCode(input, opts); document.getElementById('htmlOutput').value = output; hbShowStats(input, output); } function hbMinify() { var input = document.getElementById('htmlInput').value; if (!input.trim()) return; var output = hbMinifyCode(input); document.getElementById('htmlOutput').value = output; hbShowStats(input, output); }

    Embed HTML美化器 Widget

    HTML美化器

    引用此內容、頁面或工具為:

    "HTML美化器" 於 https://MiniWebtool.com/zh-tw/html美化器/,來自 MiniWebtool,https://MiniWebtool.com/

    由 miniwebtool 團隊提供。更新日期:2026-03-07

    文本修改工具:

    常用工具:

    隨機撲克牌產生器分數計算機斜邊計算機真心話大冒險產生器隨機信用卡生成器比例計算機百分比增加計算機相對標準偏差計算機圓計算機最簡分數計算機樣本標準差計算機🎮 遊戲靈敏度轉換器kg到lbs轉換器百分比增長率計算機kpa到psi轉換器羅馬數字轉換器百分比折扣計算機百分比減少計算機磅轉公斤轉換器毛利率計算機Instagram用戶ID查詢商和餘數計算機HEX計算機質數分解計算機校正鈣計算機MAC地址查找圖片分割器坡度與傾斜度計算機年齡計算機隨機名稱生成器隨機餐點產生器最小公倍數計算機查找並替換文字ANC計算機太陽、月亮與上升星座計算機 🌞🌙✨影片轉圖片擷取器百分比誤差計算機標準偏差計算機 - 高精度加價計算機Bar to PSI 轉換器凱薩密碼工具隨機字母生成器🌡️ 體感溫度計算機AI內容檢測器CAGR計算機反向文字畢達哥拉斯定理計算機調整影片速度簡單利息計算機音訊分割器因子計算機分數百分比轉換器年份天數計算機 - 今天是今年的第幾天SRT時間偏移賓果卡生成器血壓解讀器考拉茲猜想計算機對數計算機定期存款計算機百分比變化計算機兩點間距離計算機📅 日期計算機二次公式計算機複利計算機分數到小數計算機合併影片剪刀石頭布產生器小字體生成器 ⁽ᶜᵒᵖʸ ⁿ ᵖᵃˢᵗᵉ⁾樂透號碼生成器隨機數學題產生器棒球打擊率計算機克到磅轉換器影片壓縮器psi到kpa轉換器出生星期計算機隨機選擇器比率與百分比計算機心算訓練器土星回歸計算機文字重複工具橢圓 周長計算機⏱️ 小時計算機FPS 轉換器可整除測試計算機直角三角形計算機我的幸運數字是什麼磅到克轉換器Facebook用戶ID查詢HEX轉換器SRT轉換為TXT工具YouTube頻道統計積分計算機壓力轉換器平均值計算機百分比到ppm轉換器迷宮產生器隨機錦標賽對陣生成器騎行速度計算機總體標準差計算機-高精度填字遊戲製作器OPS計算機多分數計算機cpm計算機隨機英文單字產生器純利潤計算機星期幾計算機組合計算機總和計算機質數檢查器鋼筋計算機預期壽命計算機最大公因子計算機隨機物品生成器中位數計算機演講時間計算機公因子計算機條碼產生器每局被上壘率 WHIP 計算機GUID / UUID 生成器MAC地址產生器排序數字小數到分數計算機隨機顏色生成器影片分割器速度計算機步數距離計算機複數計算機隨機生日生成器上壘率計算機弧長計算機隨機日期生成器愛情兼容性計算機數獨產生器與求解器汽車貸款計算機百分比計算機速度轉換器階乘計算機工作搜尋器樓梯計算機汽車折舊計算機移除標點符號線上工具刪除線文字產生器斜率計算機跑步配速計算機為影片新增浮水印ERA計算機圖片打碼工具歐姆定律計算機線規計算機AI標點符號添加器保齡球計分計算機文件大小轉換器常規時間到小數時間轉換器💧 露點計算機科學記數法計算機隨機時間生成器黃金比例計算機PSI 轉 Bar 轉換器⏱️ 倒數計時器分數簡化鋼材重量計算機三相功率計算機碳水化合物計算機GIF 製作器比率計算機比較分數計算機體積轉換器密度計算機自行車齒輪比計算機預產期計算機ASCII碼表半衰期計算機行數統計工具GIF 轉 MP4 轉換器YouTube收益估算器WHtR計算機YouTube Shorts 收益計算機圓柱體體積計算機 高精度圖片旋轉器年金現值計算機kVA計算機凱利公式計算機摩爾斯電碼生成器比例模型換算計算機泊松分佈計算機混凝土計算機旋轉影片棒球長打率計算機隨機辯論題目產生器Log Base 10 計算機mah到wh轉換器厘米到英尺和英寸轉換器燃油費用計算機🌐 時區轉換器橢圓面積計算機發音音標轉換器血糖轉換器質數列表隨機貓狗名字產生器小數到百分比轉換器租賃買斷計算機辛烷值混合計算機二衝程機油混合計算機引擎排氣量計算機沙發過門計算機木柴考得計算機空氣清淨機cadr計算機除濕機尺寸計算機吊扇尺寸計算機窗簾尺寸計算機地毯尺寸計算機掛畫高度計算機電視安裝高度計算機電視尺寸計算機池塘容積與襯墊計算機泳池鹽量計算機泳池容積計算機熱水器尺寸計算機環氧樹脂計算機欄杆立柱間距計算機踢腳板與飾條計算機壁板計算機露臺木器染色劑計算器草籽計算機草皮計算機瀝青計算機立方碼計算機天線長度計算機電線管填充率計算機串聯並聯電容計算機感抗計算機房間照明計算機勒克斯轉流明計算機流明轉瓦特轉換器發電機功率計算機安培轉瓦特計算機瓦特轉安培計算機串聯電阻計算機摩擦力計算機斜面計算機機械利益計算機聲速計算機波速計算機浮力計算機終端速度計算機德布羅意波長計算機光子能量計算機emc2計算機時間膨脹計算機克卜勒第三定律計算機逃逸速度計算機萬有引力計算機比爾-朗伯定律計算機能斯特方程式計算機滲透壓計算機沸點上升計算機凝固點下降計算機百分比組成計算機當量濃度計算機重量莫耳濃度計算機pKa到Ka轉換器亨德森-哈塞爾巴爾赫計算機理論產量計算機限量試劑計算機電子組態計算機互動式元素週期表AI教案產生器AI測驗產生器引用產生器 (APA/MLA/Chicago)出席率計算機AP分數計算機ACT分數計算機SAT分數計算機百分比轉CGPA轉換器CGPA轉百分比轉換器簡易評分器 EZ Grader養育孩子成本計算機寶寶奶量計算機尿布尺寸計算機嬰兒名字產生器寶寶眼睛顏色預測器兒童BMI百分位計算機兒童身高預測器hcg翻倍時間計算機試管嬰兒預產期計算機著床計算機中國生男生女預測器ISO 8601 日期格式化工具儒略日轉換器午睡計算機月相計算機日出日落計算機世界時鐘日期至羅馬數字轉換器退休倒數計時戒癮天數計算機半歲生日計算機紀念日計算機週數計算機小費分配計算機電子郵件行銷ROI計算機每筆潛在客戶成本計算機營運資本計算機隨機RPG角色生成器