styl Template
The styl template literal lets you write styles using Stylus syntax.
Basic Usage
Placement
Inside a function — styles are scoped to that component:
At module level — styles are shared across all components in the file:
Stylus Syntax
Minimal Syntax
Braces, colons, and semicolons are optional:
Parent Reference (&)
Use & to reference the parent selector:
Compiles to .button.primary, .button.disabled.
Variables
Define and use Stylus variables:
Mixins
Define reusable style patterns:
Global Configuration
Create styles/index.styl in your project root. This file is automatically imported into every styl block:
Use anywhere in your app:
The u Unit
CSSX adds a custom u unit where 1u = 8px (Material Design grid):
Supported CSS Features
Media Queries
Viewport Units
CSS Variables
See CSS Variables for runtime variable updates.
Selectors
Note: Descendant selectors (
.parent .child) are not supported. Apply modifiers directly to each element that needs styling.
Note: Pseudo-classes (
:hover,:focus,:active, etc.) and pseudo-elements (::before,::after) are not supported. Use state-based modifiers instead (e.g.,&.focused,&.active).
Part Selector
Target internal parts of child components:
Single colon shorthand also works: .button:part(icon)
See Component Parts for details.
Style Priority
When the same property is defined in multiple places (highest to lowest):
- Inline
styleprop - Local styles (
stylinside function) - Global styles (
stylat module level) - File styles (imported
.cssx.stylfiles)
Limitations
- No expression interpolations:
styl`color ${color}`is not allowed - Must be a plain template literal
- For dynamic values, use CSS variables or the
styleprop
See Also
- css Template — Plain CSS alternative
- styl() Function — Apply styles via spread
- styleName Prop — Connect elements to styles