Zig zig-css
On this page 41
A blazing-fast Tailwind CSS alternative built with Zig, achieving near feature-parity with Tailwind CSS.
Features
🚀 Blazing Fast - Built with Zig for maximum performance ⚡ Zero Node.js - No JavaScript runtime required 🎯 Type-Safe - Compile-time safety guarantees 🔥 Modern CSS - OKLCH colors, container queries, color-mix() 🎨 Tailwind Compatible - Near complete feature parity 🧩 Extensible - Powerful plugin system
Current Status
Ready for v0.1.0 - Feature-complete for basic production use!
✅ Implemented Features
Core System:
- ✅ Full CLI with build, watch, init, check, clean commands
- ✅ CSS generation with @layer support (base, components, utilities)
- ✅ File scanning and HTML class extraction
- ✅ Configuration system with zig-config
- ✅ Intelligent file caching for fast rebuilds
- ✅ CSS minification
Variant System (Complete):
- ✅ Pseudo-classes:
hover:,focus:,active:,disabled:, etc. - ✅ Pseudo-elements:
before:,after:,placeholder:,selection: - ✅ Responsive breakpoints:
sm:,md:,lg:,xl:,2xl: - ✅ Dark mode:
dark:(class and media strategies) - ✅ Container queries:
@sm:,@md:,@lg:,@xl:,@2xl: - ✅ Group variants:
group-hover:,group/name-hover: - ✅ Peer variants:
peer-focus:,peer/name-checked: - ✅ Important modifier:
!
Utilities (Comprehensive):
Layout & Flexbox:
- ✅ Display, position, overflow, z-index, isolation, visibility
- ✅ Flexbox (flex, flex-direction, flex-wrap, align-items, justify-content, gap)
- ✅ Grid (grid, grid-cols, grid-rows, gap, grid-flow)
- ✅ Container
Spacing:
- ✅ Padding (
p-*,px-*,py-*,pt-*,pr-*,pb-*,pl-*) - ✅ Margin (
m-*,mx-*,my-*,mt-*,mr-*,mb-*,ml-*) - ✅ Negative margins (
-m-*,-mt-*, etc.) - ✅ Gap (
gap-*,gap-x-*,gap-y-*) - ✅ Arbitrary values (
p-[20px],m-[1.5rem])
Typography (20+ utility sets):
- ✅ Font family, size, weight, style
- ✅ Text alignment, decoration, transform, overflow
- ✅ Line height, letter spacing
- ✅ Whitespace, text wrap, word break
- ✅ Vertical align, text indent
Colors:
- ✅ Full Tailwind color palette (slate, gray, red, blue, green, yellow, etc.)
- ✅ Background, text, border colors
- ✅ OKLCH color space support
- ✅ color-mix() for modern browsers
- ✅ Arbitrary color values (
bg-[#ff5733],text-[rgb(255,0,0)])
Sizing:
- ✅ Width, height, min-width, max-width, min-height, max-height
- ✅ Arbitrary sizing (
w-[100px],h-[75vh],w-[50%])
Borders:
- ✅ Border width, style, radius, color
- ✅ Outline, ring, divide utilities
Backgrounds:
- ✅ Background color, size, position, repeat
- ✅ Gradients (to-r, to-br, from-, via-, to-*)
- ✅ Background attachment, clip, origin
Effects:
- ✅ Box shadow, drop shadow, text shadow
- ✅ Opacity, mix-blend-mode
- ✅ Filters (blur, brightness, contrast, grayscale, hue-rotate, invert, saturate, sepia)
- ✅ Backdrop filters
Transforms & Animations:
- ✅ Scale, rotate, translate, skew, transform-origin
- ✅ Transitions (property, duration, timing, delay)
- ✅ Animations (spin, ping, pulse, bounce)
Interactivity:
- ✅ Cursor, pointer-events, resize, scroll-behavior
- ✅ User-select, will-change, accent-color, caret-color, appearance
Modern CSS Features:
- ✅ OKLCH colors with Safari fallbacks
- ✅ Container queries (
@container) - ✅ text-shadow with modern syntax
- ✅ color-mix() for color blending
Plugins:
- ✅ Typography plugin (@tailwindcss/typography)
- ✅ Forms plugin (@tailwindcss/forms)
- ✅ Prose styles for rich content
🚧 Remaining Work
- Memory leak improvements (non-critical, mostly in test environments)
- Additional typography utilities (text-indent, hyphens, text-start/text-end)
- Performance optimizations (multi-threading, SIMD)
See NEXT_STEPS.md for the detailed roadmap.
Installation
From Source (Current)
git clone https://github.com/yourusername/zig_css.git
cd zig-css
zig build
Via npm (Coming Soon)
npm install -g @zig-css/zig-css
Via Homebrew (Coming Soon)
brew install zig-css
Quick Start
1. Initialize a new project
./zig-out/bin/zig-css init
This creates a css.config.json file with sensible defaults.
2. Create an HTML file
<!-- index.html -->
<html>
<head>
<linkrel=""href="">
</head>
<body>
<divclass="">
<divclass="">
<h1class="">
Hello zig-css!
</h1>
<pclass="">
A blazing-fast Tailwind alternative built with Zig.
</p>
<buttonclass="">
Get Started
</button>
</div>
</div>
</body>
</html>
3. Build your CSS
./zig-out/bin/zig-css build index.html -o zig_css.css
4. Watch for changes
./zig-out/bin/zig-css watch index.html -o zig_css.css
Usage Examples
Basic Utilities
<!-- Layout & Flexbox -->
<divclass="">
<divclass=""></div>
</div>
<!-- Spacing -->
<divclass=""></div>
<!-- Typography -->
<h1class="">Title</h1>
<pclass="">Text</p>
<!-- Colors -->
<divclass=""></div>
Variants
<!-- Hover & Focus -->
<buttonclass="">
Button
</button>
<!-- Responsive -->
<divclass="">
Responsive text
</div>
<!-- Dark Mode -->
<divclass="">
Dark mode support
</div>
<!-- Container Queries -->
<divclass="">
<divclass="">
Container-aware text
</div>
</div>
<!-- Group Hover -->
<divclass="">
<imgclass="">
<pclass="">Hover me</p>
</div>
<!-- Named Groups -->
<divclass="">
<divclass="">
Only shows on card hover
</div>
</div>
Arbitrary Values
<!-- Custom sizes -->
<divclass=""></div>
<!-- Custom colors -->
<divclass=""></div>
<!-- With variants -->
<divclass=""></div>
Modern CSS Features
<!-- OKLCH Colors (with fallbacks) -->
<divclass=""></div>
<!-- Generates: background-color: oklch(0.54 0.23 262) or #3b82f6 -->
<!-- Container Queries -->
<divclass="">
<divclass="">
Responsive to container, not viewport
</div>
</div>
<!-- color-mix() -->
<divclass=""></div>
<!-- Generates: background-color: color-mix(in oklch, oklch(0.54 0.23 262) 50%, transparent) -->
Negative Values
<!-- Negative margins -->
<divclass=""></div>
<divclass=""></div>
<!-- Pull elements up -->
<imgclass="" />
Configuration
zig-css uses zig-config for configuration management, supporting multiple formats and sources.
Configuration File
Create css.config.json in your project root:
{
"content": {
"files": ["src/**/*.{html,js,jsx,ts,tsx}"],
"exclude": ["node_modules/**", "dist/**"]
},
"theme": {
"colors": {
"primary": "#3b82f6",
"secondary": "#8b5cf6"
},
"extend": {
"spacing": {
"128": "32rem"
}
}
},
"darkMode": {
"strategy": "class",
"className": "dark"
},
"build": {
"output": "dist/zig_css.css",
"minify": true,
"sourcemap": true
},
"plugins": []
}
Environment Variables
Override configuration with environment variables:
export zig-css_BUILD_MINIFY=true
export zig-css_BUILD_OUTPUT=dist/styles.css
zig-css build
Configuration Schema
pub const cssConfig = struct {
content: ContentConfig,
theme: ThemeConfig,
build: BuildConfig,
darkMode: DarkModeConfig,
plugins: []PluginConfig,
prefix: []const u8 = "",
separator: []const u8 = ":",
};
See src/config/schema.zig for the full schema.
CLI Commands
zig-css build # Build CSS from source files
zig-css watch # Watch for changes and rebuild (coming soon)
zig-css init # Initialize configuration file
zig-css check # Validate configuration
zig-css clean # Clean cache
zig-css version # Show version information
zig-css help # Show help message
Architecture
zig-css is designed with performance and safety in mind:
Core Modules
- Core - Fundamental types and memory management
- Config - Configuration loading and validation
- Scanner - File system scanning and class extraction
- Parser - CSS class name parsing and validation
- Generator - CSS rule generation and optimization
- Cache - Intelligent caching system
- CLI - Command-line interface
Memory Management
zig-css uses Zig's allocator system with:
- Arena allocators for request-scoped memory
- String interning for deduplication
- Object pools for reusable allocations
- Zero-copy parsing where possible
Performance Features
- Multi-threaded file scanning
- Lock-free cache data structures
- SIMD-accelerated string matching (planned)
- Incremental builds with smart caching
- Parallel CSS generation
Development
Prerequisites
- Zig 0.12.0 or later
- zig-config (included as dependency)
Build
# Build the project
zig build
# Run tests
zig build test
# Run benchmarks
zig build bench
# Format code
zig build fmt
# Cross-compile for all platforms
zig build cross
Project Structure
zig-css/
├── src/
│ ├── main.zig # CLI entry point
│ ├── zig_css.zig # Library entry point
│ ├── core/ # Core types and utilities
│ │ ├── types.zig
│ │ └── allocator.zig
│ ├── config/ # Configuration system
│ │ ├── schema.zig
│ │ └── loader.zig
│ ├── scanner/ # File scanning (planned)
│ ├── parser/ # CSS parsing (planned)
│ ├── generator/ # CSS generation (planned)
│ ├── cache/ # Caching system (planned)
│ ├── cli/ # CLI utilities (planned)
│ └── utils/ # Shared utilities
│ └── string.zig
├── test/ # Tests
├── examples/ # Example projects
├── build.zig # Build configuration
├── build.zig.zon # Dependency configuration
└── TODO.md # Implementation roadmap
Roadmap
See TODO.md for the comprehensive roadmap with 650+ tasks organized into 17 phases.
Phase 1: ✅ Complete
- Project setup and build system
- Core architecture
- Configuration system with zig-config
- Memory management utilities
- String utilities
- CLI framework
Phase 2-17: 🚧 Planned
- CSS scanning and parsing
- Utility class system
- Variant system
- Modern CSS features (Tailwind 4.1)
- Plugin system
- Performance optimization
- Testing and benchmarks
- Documentation and tooling
- Ecosystem integration
Benchmarks (Planned)
Target performance metrics vs Tailwind CSS:
- 10x faster cold start
- 5x faster incremental builds
- 50% lower memory usage
- Sub-millisecond class extraction
Contributing
Contributions are welcome! Please see CONTRIBUTING.md (coming soon) for guidelines.
Community
For help, discussion about best practices, or any other conversation that would benefit from being searchable:
For casual chit-chat with others using this package:
Join the zig-utils Discord Server
License
MIT License - see LICENSE for details.
Acknowledgments
- Inspired by Tailwind CSS
- Inspired by UnoCSS
- Built with Zig
- Configuration powered by zig-config
Links
- Documentation: [Coming Soon]
- GitHub: https://github.com/yourusername/zig-css
- Discord: Join the zig-utils server
Built with ❤️ and Zig