首页 全栈极客与开发辅助内容详情

CSS Minifier & Beautifier: Nested Media Queries Indented Right, Comments Optional - One line or one tree, one click apart

2026-11-17 3 访客
CSS Minifier & Beautifier: Nested Media Queries Indented Right, Comments Optional

站点名称:CSS Minifier & Beautifier: Nested Media Queries Indented Right, Comments Optional

所属分类:全栈极客与开发辅助

官方网址:https://www.9314.cn/tools/css-formatter/en/

SEO查询: 爱站网 站长工具

进入网站

站点介绍

CSS Minifier & Beautifier: Nested Media Queries Indented Right, Comments Optional

Inheriting an old project this January meant facing a stylesheet minified six years ago - one line, thirty thousand characters. Changing a responsive breakpoint required un-minifying it by hand first; that afternoon of toggling the blob back and forth in a formatter left me wanting one simple comfort: the rule count staying put after compression. This page is that afternoon's product: minify, beautify, comment toggle, rule counting, all present.

The short version

  • Minify/expand one click apart: minify strips whitespace and comments (/*! bang comments survive by default, regular ones obey a toggle); beautify expands each block, declarations one per line, 2/4-space indent selectable.
  • Nesting indented right: rules inside @media, @supports and @keyframes indent one level deeper than the outer layer, level by level - breakpoint surgery reads at a glance.
  • Lenient, not blocking: a missing final semicolon warns without blocking (the CSS standard permits it), and minified output adds semicolons back; colon-less declarations warn then get ignored. The rule count survives round-trips between modes, shown right in the status line.
  • Fair warning: no Sass/Less/Stylus variable or mixin syntax - those are preprocessors; compile to standard CSS first.

The rule count is this page's conscience

The scariest minifier failure is not failing to shrink - it is silently dropping rules. A selector that fails to parse, an unclosed block, an @media whose contents get swallowed: none of it shows to the naked eye after compression, and the broken site is what tells you.

This page puts the rule count in the status line: 47 rules before compressing, 47 after; switch to beautify and back, still 47. An unchanged number does not prove correctness, but a changed one proves a bug - and that one glance is worth it.

Comments stay or go - your call

Minify strips comments by default - saving bytes is the point. Two exceptions: bang-prefixed /*! important comments survive by default (the copyright convention; deleting them can be a licensing problem), and a toggle keeps regular /* */ comments too when checked.

Beautify mode keeps every comment, indented with its rule. In team codebases comments are documentation - present when reading, out of the way when shipping. Two shapes, each doing its job.

FAQ

Can it handle Sass / Less / Stylus?

No, and it will not pretend to. $variables, @mixin, nested selectors, .less mixins - that is preprocessor syntax; both browsers and this tool parse standard CSS, so those get treated as plain text or flagged with a warning. Compile your Sass to CSS first (a one-command sass file.scss job), then paste it here. This page's job is minifying and beautifying standard CSS.

Does minification remove my comments?

By default yes - that is the point of minification, and every byte counts. Two exceptions: /*! bang-prefixed important comments */ (the copyright-notice convention) survive by default, and a "keep comments" toggle preserves regular /* */ comments too when checked. Beautify mode keeps every comment by default, indented along with its rule.

What happens to rules with missing semicolons?

They warn, they do not block. Standard CSS allows the last declaration in a block to omit its semicolon (though appending another declaration later would break), so the tool warns which rule is missing one and processes the declaration anyway - more useful in practice than refusing. Minified output adds the semicolons back automatically, so later edits stay safe.

Is @media nesting indented correctly? Does the rule count change?

Yes. Rules inside @media (and block-level at-rules like @supports, @keyframes) indent one level deeper than the outer layer, and deeper nesting indents further - the hierarchy reads at a glance. The rule count does not change between minify and beautify: each selector-plus-declaration-block is one rule, and both modes count the same set. The status line shows rule count and byte savings so you can verify yourself.

Is my stylesheet uploaded anywhere?

No. Minification, beautification and checks all happen inside this device's browser - there is no upload endpoint and it works offline. Only preferences like indent width and the comment toggle live in this browser's localStorage; they do not follow you to another device, and "Clear my data" in the footer removes them.

中文版:https://www.9314.cn/tools/css-formatter/

 暂无评论,快来抢沙发吧~

发布评论