
NestYourCSS: Minify, beautify, denest, and nest CSS code
An Awwwards-inspired online converter tool to minify, beautify, denest, and nest CSS code according to the latest CSS specs. Originally created as a personal portfolio project, it has since evolved into a well-rounded, …
以下正文同步自 Hacker News 最新,版权归原站所有,已转换为易读排版。
An Awwwards-inspired online converter tool to minify, beautify, denest, and nest CSS code according to the latest CSS specs. Originally created as a personal portfolio project, it has since evolved into a well-rounded, publicly open-source tool for the modern front-end developer.
View Website · View Figma Design · View Codepen Collection
The NYCSS Suite
Features
NYCSS vs. Preprocessors
CLI Documentation
Monorepo Architecture
Accessibility Commitment
Contributing
License
Acknowledgements
The NYCSS Suite
Nest Your CSS is a full suite of tools designed to bring native CSS nesting and more, into any workflow, exactly how you need it:
Nest CSS: Convert any standard CSS to the latest native nested syntax.
Denest CSS: Flatten nested CSS back to standard, legacy-browser-compatible CSS.
Minify CSS: Optimize your stylesheets by removing unnecessary characters.
Beautify CSS: Format and indent your code for maximum readability.
Nesting Strategy: Choose how deeply the engine nests your CSS — balanced (splits deep selectors), maximize (prefers depth over readability), or flattened (caps at one level of nesting).
Configurable Depth Limit: Set a maximum depth of your choice to avoid overly specific selectors while maintaining readability (3-4 is industry standard).
Deduplication: Automatically remove duplicate declarations from your output CSS.
File Size Display: Toggle the display of file sizes in the editor tabs.
Minimap: Toggle a code minimap in the editor for quick visual navigation of your stylesheets.
Batch Processing: Watch and transform entire directories of stylesheets using the CLI.
Customizable Editor: Adjust font, font size, indentation, and word wrap to your preference.
Load External CSS: Fetch and convert stylesheets directly from a URL.
Deep Accessibility: Fully navigable and usable with screen readers, thanks to extensive ARIA implementation.
Awwwards-Inspired UI/UX: A focus on smooth animations, visual appeal, and a high-quality user experience.
Zero Dependencies: The core @nycss/engine is written in 100% Vanilla JavaScript without a single external dependency.
Custom Lexer/Parser: NYCSS achieves high performance on large stylesheets by avoiding expensive, heavy Regular Expressions. It parses code character-by-character statelessly, ensuring accurate AST generation without freezing the browser.
Modern Standards: Native support for complex pseudo-classes like :is(), relative color syntax, and structural grouping.
NYCSS vs. Preprocessors
How does Nest Your CSS compare to established preprocessors like Sass, Less, or PostCSS?
Native CSS nesting is the future of the web. NYCSS bridges the gap by letting you easily convert old codebases to modern standards, without locking you into a proprietary build ecosystem.
You can also use NYCSS directly into your terminal or build pipelines.
Install the CLI globally to use it anywhere:
npm install -g @nycss/cli
Basic Usage
Transform a single file and output it to a new destination:
nycss input.css -o output.css
You can also pipe standard input directly into NYCSS:
cat input.css | nycss --mode minify > output.min.css
Arguments Table
Flag Description Default
-m, --mode <mode> The processing mode. Valid options: nest, denest, minify, beautify. nest
-d, --depth <level> Max nesting depth. Limits how deep selectors can nest (use 0 for infinite). Infinite
-i, --indent <size> Indent size. Use a number (e.g; 2, 4) or tab. 4
-c, --comments Preserve comments in output. Negate with --no-comments to strip them. Stripped in minify, kept otherwise
--dedupe Removes duplicate rules and declarations from the output. false
-o, --out <path> Output destination (file or directory). N/A
--out-dir <dir> Output directory for batch processing. N/A
--base <dir> Base directory for preserving the folder structure during batch processing. Auto-detected
-w, --watch Watches the input files/globs for changes and recompiles automatically. false
Batch Processing
You can process entire directories using glob patterns. When doing so, use --out-dir (and optionally --base to preserve the exact folder hierarchy).
Process all CSS files in /src and output them to /dist
nycss "src/**/*.css" --out-dir dist --base src
Monorepo Architecture
The project is structured as a pnpm monorepo, separating core logic from user interfaces.
We believe developer tools should be accessible to all developers. NYCSS is built with deep adherence to a11y principles:
If you are a screen-reader user and experience friction, please open an issue! Your feedback is highly valued.
Contributions are the lifeblood of the open-source community and are greatly appreciated. If you have suggestions to improve this project, please feel free to fork the repo and create a pull request, or simply open an issue with the "enhancement" tag.
Want to contribute to the project? We use pnpm for workspace management.
Node.js (Recommended: v24)
pnpm (Recommended: v11)
Installation & Local Development
Clone the repo and navigate to the project directory: git clone https://github.com/NestYourCSS/NestYourCSS.git cd NestYourCSS
Install dependencies across all packages: pnpm install
Running the Development Servers:
(Built assets are output to the /dist directory via the postbuild script).
To test CLI changes locally during development:
cd packages/cli pnpm add -g .
You can now run the nycss command anywhere on your local machine.
Distributed under the MIT License. See LICENSE for more information.
正文由 探How 从来源站点 RSS 同步,内容未经改写;遇到排版缺失或需要图片、视频时请以原文为准。