html Copy code HTML Minifier Tool

HTML Minifier Tool

CSS css Copy code /* styles.css */ body { font-family: Arial, sans-serif; background: #f5f5f5; margin: 0; padding: 0; display: flex; justify-content: center; align-items: center; height: 100vh; } .container { background: #fff; padding: 20px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); border-radius: 8px; max-width: 600px; width: 100%; } h1 { text-align: center; color: #333; margin-bottom: 20px; } .editor { display: flex; flex-direction: column; } textarea { width: 100%; height: 150px; margin-bottom: 10px; padding: 10px; border: 1px solid #ddd; border-radius: 4px; resize: vertical; font-family: monospace; } textarea:focus { border-color: #007bff; outline: none; } button { padding: 10px; background: #007bff; color: #fff; border: none; border-radius: 4px; cursor: pointer; font-size: 16px; } button:hover { background: #0056b3; } JavaScript javascript Copy code // script.js document.addEventListener('DOMContentLoaded', () => { const minifyBtn = document.getElementById('minifyBtn'); const htmlInput = document.getElementById('htmlInput'); const htmlOutput = document.getElementById('htmlOutput'); minifyBtn.addEventListener('click', () => { const htmlCode = htmlInput.value; if (htmlCode.trim() === '') { alert('Please enter some HTML code to minify.'); return; } const minifiedHtml = minify(htmlCode, { collapseWhitespace: true, removeComments: true, removeRedundantAttributes: true, removeEmptyAttributes: true, minifyCSS: true, minifyJS: true }); htmlOutput.value = minifiedHtml; }); });