Create your first StyleSheet
This guide will walk you through creating a styled card component using rbx-css.Create a CSS file
Create a new file called
styles.css with some basic styles:styles.css
CSS variables on
:root become StyleSheet attributes that you can reference throughout your styles.Use in Roblox
Import and use the generated StyleSheet in your Roblox project:The
card Frame will now have:- Dark background color from
--bg - 8px border radius via
UICorner - 1px white stroke via
UIStroke - 16px padding via
UIPadding - Vertical flex layout via
UIListLayout - 12px gap between children
- Hover state that changes background color
Understanding the output
Let’s break down what rbx-css generated:Design tokens
CSS variables become StyleSheet attributes:- Colors →
Color3.fromRGB() - Lengths with units →
UDim.new() - Plain numbers →
number - Strings →
string
Class selectors
CSS class selectors map directly to Roblox class attributes:class = "card" attribute.
Pseudo-instances
CSS properties that require Roblox child instances are automatically created:State selectors
Pseudo-classes map to Roblox GuiState:Common patterns
Responsive sizing
Responsive sizing
Use percentage units for responsive layouts:
Flexbox layouts
Flexbox layouts
Use familiar flexbox properties:
Typography
Typography
Style text with standard CSS properties:
Theme switching
Theme switching
Implement dark mode with data attributes:Then use the generated
setTheme() function:Multiple input files
Compile multiple CSS files into a single StyleSheet:- Define tokens in
base.css - Override for themes in
theme.css - Add component styles in
components.css
Watch mode for development
Use watch mode to automatically recompile on file changes:src/styles/ and recompiles whenever you save changes.
Watch mode is perfect for development workflows where you’re frequently iterating on styles.
CLI options
Customize compilation with these options:--name- Custom StyleSheet instance name (default:StyleSheet)--minify- Minify the generated Luau output--strict- Treat warnings as errors--warn- Warning level:all,unsupported, ornone--manifest- Generate a.manifest.jsonfile with metadata
Programmatic usage
You can also use rbx-css as a library in your build tools:Next steps
CSS mapping reference
Learn how CSS properties map to Roblox
CLI reference
Explore all CLI commands and options
Supported properties
See all supported CSS properties
Examples
View real-world examples and patterns