Pages

Sunday, 1 December 2024

HTML Minifier Tool




HTML Minifier Tool

HTML Minifier Tool

Paste your HTML code below and click on "Minify" to reduce its size.

* { margin: 0; padding: 0; box-sizing: border-box; } body { font-family: Arial, sans-serif; background-color: #f4f4f4; color: #333; padding: 20px; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; } .container { background-color: white; padding: 30px; border-radius: 10px; box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1); width: 80%; max-width: 800px; } h1 { text-align: center; color: #4CAF50; margin-bottom: 20px; } p { text-align: center; margin-bottom: 20px; font-size: 16px; } .editor { margin-bottom: 20px; } label { display: block; margin-bottom: 5px; font-size: 16px; color: #555; } textarea { width: 100%; height: 150px; padding: 10px; font-family: monospace; font-size: 14px; border: 1px solid #ccc; border-radius: 5px; background-color: #fafafa; resize: vertical; } textarea:focus { border-color: #4CAF50; outline: none; background-color: #fff; } button.minify-btn { background-color: #4CAF50; color: white; font-size: 18px; padding: 10px 20px; border: none; border-radius: 5px; width: 100%; cursor: pointer; transition: background-color 0.3s; } button.minify-btn:hover { background-color: #45a049; } function minifyHTML() { const htmlInput = document.getElementById('htmlInput').value; // Remove unnecessary whitespaces, line breaks, and comments const minifiedHTML = htmlInput .replace(/\n/g, "") // Remove line breaks .replace(/\s+/g, " ") // Remove extra spaces .replace(//g, "") // Remove comments .trim(); // Display the minified HTML document.getElementById('htmlOutput').value = minifiedHTML; }