以整洁缩进美化 CSS,或将其压缩以缩小文件体积。处理媒体查询、calc() 和许可注释。
如何使用 CSS 格式化
将你的 CSS 粘贴到输入框。
选择美化以格式化它,或压缩以压缩它。
选择缩进大小,然后复制结果。
This is a CSS formatter that beautifies stylesheets with clean, consistent indentation, or minifies them to shrink file size. You choose the indent size for beautifying, and switch to minify when you want the smallest output.
Readable CSS is easier to scan, review and debug: when each rule and declaration is indented consistently, you can see selectors, nesting and the shape of your media queries at a glance.
Minifying is for production. It removes the whitespace and comments that browsers do not need, so the file downloads faster. On a large stylesheet the saving adds up, especially before gzip compression on the server.
The minifier is careful where it matters. It keeps the spaces around plus and minus inside calc(), so calc(100% - 30px) stays valid, and it only strips spaces around structural characters such as braces, colons and semicolons. It also handles nested media queries correctly.
License comments written in the /*! ... */ form are preserved, which is the standard convention for keeping copyright and license notices in minified output even when ordinary comments are removed.
Both beautify and minify run entirely in your browser, so your stylesheets never leave your device. The tool formats for readability and size; it does not validate that your CSS is correct.
常见问题
不会。压缩工具会保留值内加号和减号周围的空格,因此 calc(100% - 30px) 仍然有效。它只移除大括号、冒号和分号等结构字符周围的空格。
普通注释会被移除以节省空间,但写成 /*! ... */ 的许可注释会被保留,这是保留版权声明的标准约定。
不会。美化和压缩都完全在你的浏览器中运行,因此你的样式表永远不会离开你的设备。
嵌入此工具
将此工具添加到你自己的网站。复制下方代码片段即可,它会自动保持最新。
<iframe src="https://monu.tools/embed/zh/css-formatter" width="100%" height="640" style="border:1px solid #e5e5e5;border-radius:12px;max-width:680px" loading="lazy" title="Monu Tools"></iframe>相关工具