CSS to Stylus Converter
Convert standard CSS code to Stylus preprocessor syntax instantly. Removes braces, semicolons, supports nesting, and configurable output options.
About
Stylus is a CSS preprocessor that strips syntactic noise - braces, semicolons, colons - to produce a cleaner, indentation-based stylesheet. Manual conversion introduces transcription errors: a misplaced indent breaks the entire cascade, a forgotten removal of ; creates invalid Stylus output. This converter parses your CSS token-by-token, resolves selector nesting depth, preserves @media and @keyframes block hierarchy, and emits valid Stylus with configurable indentation (2 spaces, 4 spaces, or tabs). It handles edge cases including CSS custom properties (--var-name), multi-selector rules, !important annotations, and quoted url() values containing special characters.
The tool approximates Stylus output assuming standard CSS input without Sass/Less-specific syntax. Nested output is optional: flat conversion preserves original selector strings while nested mode groups child selectors under parents. Note: CSS @import statements remain as-is since Stylus uses identical syntax. Pro tip: always validate the generated Stylus in your build pipeline before committing - edge cases in minified CSS or browser-hacked selectors (e.g., _:-ms-fullscreen) may require manual adjustment.
Formulas
The conversion process follows a deterministic pipeline of string transformations. No mathematical formulas are involved; instead, the logic applies a sequential rule-based transpilation:
Where d = current brace nesting depth (0 = root), indentSize = user-selected indent width (2, 4, or 1 tab character).
Reference Data
| CSS Feature | CSS Syntax | Stylus Equivalent | Notes |
|---|---|---|---|
| Declaration terminator | ; required | Omitted | Line break acts as terminator |
| Block braces | { } required | Omitted | Indentation defines scope |
| Property colon | color: red | color red or color: red | Colon is optional in Stylus |
| Nesting | Flat selectors only | Indent children under parent | Reduces repetition |
| Parent reference | N/A | & prefix | Used for pseudo-classes, BEM |
| Variables | --name: value | name = value | This tool preserves CSS custom properties as-is |
| @media blocks | @media (max-width: 768px) { ... } | @media (max-width: 768px) + indent | Block content indented |
| @keyframes | @keyframes name { 0% { ... } } | @keyframes name + indent | Percentage selectors indented |
| @font-face | @font-face { ... } | @font-face + indent | Properties indented one level |
| @import | @import url(...) | @import url(...) | Identical syntax |
| @charset | @charset "UTF-8" | @charset "UTF-8" | Preserved verbatim |
| Comments (block) | /* ... */ | /* ... */ | Preserved |
| Comments (line) | N/A in CSS | // ... | Stylus-only feature; not generated |
| Multi-selector | h1, h2, h3 { ... } | h1, newline h2, newline h3 | Each selector on own line |
| !important | color: red !important; | color red !important | Preserved as-is |
| Pseudo-classes | .btn:hover { ... } | &:hover nested or flat | Depends on nesting mode |
| Pseudo-elements | .el::before { ... } | &::before nested or flat | Depends on nesting mode |
| Attribute selectors | [type="text"] { ... } | [type="text"] | Preserved verbatim |
| Combinators | .a > .b { ... } | .a > .b or nested | Direct child preserved |
| calc() expressions | width: calc(100% - 20px) | width calc(100% - 20px) | Function arguments preserved |
| Custom properties | --my-color: #333 | --my-color #333 | Colon kept if option enabled |