Skip to content
πŸ› οΈToolsShed

CSS Minifier / Beautifier

Minify CSS to reduce file size, or beautify minified CSS for readability.

About this tool

CSS minification is a front-end optimization technique that reduces file size by removing unnecessary characters from stylesheets β€” whitespace, comments, and redundant punctuation β€” without changing how the CSS works. Smaller files load faster, reducing bandwidth costs and improving page load times for users on slow connections. While modern browsers and build tools handle minification automatically, understanding how it works helps developers optimize their assets and troubleshoot performance issues.

To minify CSS, paste your stylesheet into the input area and click Minify. The tool removes all comments, collapses whitespace, eliminates redundant punctuation, and outputs the compressed result. To beautify minified CSS, paste the one-liner into the input and click Beautify β€” the tool reformats it with proper indentation and line breaks, making it human-readable again. Both operations show file size savings, helping you quantify the optimization benefit.

This tool is useful for learning how minification works, doing quick optimizations before deployment, or reversing obfuscated stylesheets for study. However, for production builds, integrate minification into your build pipeline (Webpack, Vite, PostCSS with cssnano) so it runs automatically on every deploy. Always test minified CSS in your target browsers to ensure no edge-case styling breaks.

Frequently Asked Questions

Code Implementation

# pip install cssmin
import cssmin

css = """
/* Main layout */
body {
    margin: 0;
    padding: 0;
    background-color: #ffffff;
    font-family: Arial, sans-serif;
}

/* Navigation */
.nav {
    display: flex;
    align-items: center;
    padding: 16px 24px;
    background-color: #1a1a2e;
    border-bottom: 1px solid #333344;
}

.nav a {
    color: #ffffff;
    text-decoration: none;
    margin-right: 16px;
    font-size: 0.875rem;
}
"""

minified = cssmin.cssmin(css)
print(minified)
# body{margin:0;padding:0;background-color:#fff;font-family:Arial,sans-serif}
# .nav{display:flex;align-items:center;padding:16px 24px;background-color:#1a1a2e;border-bottom:1px solid #333344}
# .nav a{color:#fff;text-decoration:none;margin-right:16px;font-size:.875rem}

print(f"Original: {len(css)} bytes")
print(f"Minified: {len(minified)} bytes")
print(f"Reduction: {100 - len(minified)/len(css)*100:.1f}%")

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.