Speed & Code Optimization Studio

CSS / JS / HTML Minifier & Formatter

Compress CSS stylesheets, JavaScript files, HTML templates, and JSON payloads by up to 80% to accelerate page speed, or beautify minified code into clean syntax.

Original Size
0 B
0 lines
Output Size
0 B
0 lines
File Reduction
0%
0 bytes saved
Execution Speed
0 ms
100% Client-Side
Source Code (CSS)
Output (Minified)
style.min.css

Compression Options

Indentation (Beautify):

Why Minify CSS & JavaScript Files?

Minifying production assets is a mandatory best practice recommended by Google Lighthouse and Core Web Vitals to maximize website loading speed.

Faster PageSpeed Scores

Smaller CSS and JS bundles require fewer network packets over HTTP/2 and HTTP/3, slashing Time to Interactive (TTI) and First Contentful Paint (FCP).

Up to 80% Bandwidth Savings

Stripping redundant whitespace, unneeded comments, and newlines significantly lowers hosting CDN bandwidth consumption.

100% Client-Side Privacy

Your proprietary code and internal configurations are processed directly in your web browser. No code is transmitted to external servers.

Explore More Free Developer Tools

Enhance your website performance with our suite of free online utilities.

`, json: `{"company":"Hawks Infotech","services":["Web Development","SEO Services","Cloud Management"],"established":2018,"active":true,"ratings":{"score":4.9,"reviews":250}}` }; // Language Tab Switching const langTabs = document.querySelectorAll('.lang-btn'); langTabs.forEach(btn => { btn.addEventListener('click', () => { langTabs.forEach(b => b.className = 'lang-btn px-5 py-2.5 rounded-2xl text-xs font-bold border border-slate-800 text-slate-300 bg-slate-900 hover:text-white hover:bg-slate-800 transition flex items-center gap-2'); btn.className = 'lang-btn lang-tab-active px-5 py-2.5 rounded-2xl text-xs font-bold border border-cyan-600 text-white bg-sky-600 transition flex items-center gap-2'; currentLang = btn.dataset.lang; sourceLangLabel.textContent = currentLang.toUpperCase(); updateOutputFileName(); processCode(); }); }); // Operation Mode Switching (Minify vs Beautify) btnModeMinify.addEventListener('click', () => { currentMode = 'minify'; btnModeMinify.className = 'op-tab-btn op-tab-active flex-1 sm:flex-none px-6 py-2.5 rounded-xl text-xs font-bold transition flex items-center justify-center gap-2'; btnModeBeautify.className = 'op-tab-btn flex-1 sm:flex-none px-6 py-2.5 rounded-xl text-xs font-bold text-slate-600 hover:text-slate-900 transition flex items-center justify-center gap-2'; outputModeLabel.textContent = 'Minified'; updateOutputFileName(); processCode(); }); btnModeBeautify.addEventListener('click', () => { currentMode = 'beautify'; btnModeBeautify.className = 'op-tab-btn op-tab-active flex-1 sm:flex-none px-6 py-2.5 rounded-xl text-xs font-bold transition flex items-center justify-center gap-2'; btnModeMinify.className = 'op-tab-btn flex-1 sm:flex-none px-6 py-2.5 rounded-xl text-xs font-bold text-slate-600 hover:text-slate-900 transition flex items-center justify-center gap-2'; outputModeLabel.textContent = 'Beautified'; updateOutputFileName(); processCode(); }); function updateOutputFileName() { const ext = (currentLang === 'js') ? 'js' : (currentLang === 'html' ? 'html' : (currentLang === 'json' ? 'json' : 'css')); if (currentMode === 'minify') { outputFileName.textContent = `output.min.${ext}`; } else { outputFileName.textContent = `output.formatted.${ext}`; } } // Live Code Processing Engine codeInput.addEventListener('input', processCode); optStripComments.addEventListener('change', processCode); optRemoveLogs.addEventListener('change', processCode); optIndentSize.addEventListener('change', processCode); loadSampleCodeBtn.addEventListener('click', () => { codeInput.value = samples[currentLang] || samples.css; processCode(); }); clearAllBtn.addEventListener('click', () => { codeInput.value = ''; codeOutput.value = ''; updateMetrics(0, 0, 0, 0, 0); }); function processCode() { const input = codeInput.value; if (!input.trim()) { codeOutput.value = ''; updateMetrics(0, 0, 0, 0, 0); return; } const t0 = performance.now(); let result = ''; try { if (currentMode === 'minify') { result = minifyCode(input, currentLang); } else { result = beautifyCode(input, currentLang); } } catch (err) { result = 'Error formatting code: ' + err.message; } const t1 = performance.now(); codeOutput.value = result; const origBytes = new Blob([input]).size; const newBytes = new Blob([result]).size; const origLines = input.split('\n').length; const newLines = result.split('\n').length; const elapsed = Math.round(t1 - t0); updateMetrics(origBytes, newBytes, origLines, newLines, elapsed); } function minifyCode(str, lang) { let code = str; const stripComments = optStripComments.checked; if (lang === 'css') { if (stripComments) { code = code.replace(/\/\*[\s\S]*?\*\//g, ''); } code = code.replace(/\s+/g, ' ') .replace(/\s*([\{\}:;,>+~])\s*/g, '$1') .replace(/;}/g, '}') .replace(/0px/g, '0') .replace(/#([0-9a-f])\1([0-9a-f])\2([0-9a-f])\3/gi, '#$1$2$3') .trim(); } else if (lang === 'js') { if (optRemoveLogs.checked) { code = code.replace(/console\.(log|debug|info|warn|error)\([^)]*\);?/g, ''); } if (stripComments) { // Remove multi-line comments code = code.replace(/\/\*[\s\S]*?\*\//g, ''); // Remove single line comments code = code.replace(/(^|[^\\])\/\/.*$/gm, '$1'); } // Collapse whitespaces safely code = code.replace(/\r\n/g, '\n') .split('\n') .map(line => line.trim()) .filter(line => line.length > 0) .join('\n'); // Safe inline minify code = code.replace(/\s*([=+\-*/%&|!<>?:,;{}()[\]])\s*/g, '$1') .replace(/;\n/g, ';') .replace(/{\n/g, '{') .replace(/}\n/g, '}'); } else if (lang === 'html') { if (stripComments) { code = code.replace(//g, ''); } code = code.replace(/>\s+<') .replace(/\s+/g, ' ') .trim(); } else if (lang === 'json') { const parsed = JSON.parse(code); code = JSON.stringify(parsed); } return code.trim(); } function beautifyCode(str, lang) { let indentVal = optIndentSize.value; let indentSize = (indentVal === 'tab') ? 1 : parseInt(indentVal); let indentChar = (indentVal === 'tab') ? '\t' : ' '; if (lang === 'json') { const parsed = JSON.parse(str); return JSON.stringify(parsed, null, (indentVal === 'tab' ? '\t' : indentSize)); } if (typeof css_beautify !== 'undefined' && lang === 'css') { return css_beautify(str, { indent_size: indentSize, indent_char: indentChar }); } if (typeof js_beautify !== 'undefined' && lang === 'js') { return js_beautify(str, { indent_size: indentSize, indent_char: indentChar }); } if (typeof html_beautify !== 'undefined' && lang === 'html') { return html_beautify(str, { indent_size: indentSize, indent_char: indentChar }); } return str; } function updateMetrics(origBytes, newBytes, origLines, newLines, elapsed) { metricOrigSize.textContent = formatBytes(origBytes); metricOrigLines.textContent = `${origLines} lines`; metricNewSize.textContent = formatBytes(newBytes); metricNewLines.textContent = `${newLines} lines`; metricSpeed.textContent = `${elapsed} ms`; if (origBytes > 0) { const diff = origBytes - newBytes; const pct = Math.round((diff / origBytes) * 100); if (pct >= 0) { metricSavings.textContent = `-${pct}%`; metricSavings.className = 'text-lg font-black text-emerald-600 mt-0.5'; metricSavedBytes.textContent = `${formatBytes(diff)} saved`; } else { metricSavings.textContent = `+${Math.abs(pct)}%`; metricSavings.className = 'text-lg font-black text-amber-600 mt-0.5'; metricSavedBytes.textContent = 'Formatted / Expanded'; } } else { metricSavings.textContent = '0%'; metricSavedBytes.textContent = '0 bytes saved'; } } function formatBytes(bytes) { if (bytes === 0) return '0 B'; if (bytes < 1024) return `${bytes} B`; if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`; return `${(bytes / (1024 * 1024)).toFixed(2)} MB`; } // File Upload Handler uploadFileBtn.addEventListener('click', () => codeFileInput.click()); codeFileInput.addEventListener('change', (e) => { const file = e.target.files[0]; if (!file) return; const ext = file.name.split('.').pop().toLowerCase(); if (ext === 'css') selectLanguage('css'); else if (ext === 'js') selectLanguage('js'); else if (ext === 'html' || ext === 'htm') selectLanguage('html'); else if (ext === 'json') selectLanguage('json'); const reader = new FileReader(); reader.onload = function(evt) { codeInput.value = evt.target.result; processCode(); }; reader.readAsText(file); }); function selectLanguage(lang) { const targetBtn = document.querySelector(`.lang-btn[data-lang="${lang}"]`); if (targetBtn) targetBtn.click(); } // Clipboard & Download Handlers copyOutputBtn.addEventListener('click', async () => { if (!codeOutput.value) return; try { await navigator.clipboard.writeText(codeOutput.value); copyOutputBtn.innerHTML = ' Copied!'; setTimeout(() => { copyOutputBtn.innerHTML = ' Copy'; }, 1800); } catch (err) { codeOutput.select(); document.execCommand('copy'); } }); pasteCodeBtn.addEventListener('click', async () => { try { const text = await navigator.clipboard.readText(); if (text) { codeInput.value = text; processCode(); } } catch (err) { alert('Please press Ctrl+V to paste your code directly into the editor.'); } }); downloadOutputBtn.addEventListener('click', () => { if (!codeOutput.value) return; const blob = new Blob([codeOutput.value], { type: 'text/plain;charset=utf-8' }); const name = outputFileName.textContent || 'output.txt'; saveAs(blob, name); }); // Auto-load sample CSS on first load loadSampleCodeBtn.click(); });
Frequently Asked Questions

CSS & JS Minifier FAQs

How does code minification improve website performance?

Minification strips comments, extra tabs, line breaks, and redundant whitespace from CSS, JavaScript, HTML, and JSON files. Smaller payloads download and parse faster in the browser, reducing Total Blocking Time and Largest Contentful Paint.

Will minifying JavaScript break my website code?

Safe whitespace and comment minification preserves functional logic and required syntax. Before deploying minified code to production, always test interactive scripts in a staging browser console if your file omits trailing semicolons.

Can I format and unminify compressed or obfuscated code?

Yes. Switch to Beautify mode to unminify, indent, and structure compact CSS, JavaScript, HTML, or JSON into readable code with your preferred spacing.

Which code languages does this minifier support?

The tool supports CSS, JavaScript, HTML, and JSON formatting and compression, making it handy for both front-end asset optimization and API payload debugging.

Is my source code uploaded to external servers?

No. All minification and code formatting run locally inside your browser using JavaScript, so proprietary code never leaves your machine.

Chat on WhatsApp Call Us Now

Talk to an Expert