Signature
Parameters
Configuration object for the variant component
Returns
A React component that accepts the base component’s props plus variant props.Variant Props:Each variant name becomes an optional prop with its value names as the type.Features:
- Type-safe variant props with autocomplete
- Automatic sanitization (prevents CSS injection)
- Variant classes follow BEM-like pattern:
base--variantName-value - Variant props are automatically removed from the DOM
Examples
Basic Usage
With Default Variants
With Compound Variants
With React Components
Without css Helper (Plain Strings)
Type Definitions
Notes
- IDE Syntax Highlighting: Wrap CSS strings in
css\…“ to get IDE syntax highlighting from the vscode-styled-components extension - Build-Time Extraction: All CSS is extracted at build time. Only class name logic runs at runtime.
- Security: Variant values are automatically sanitized to prevent CSS injection
- Class Pattern: Generated classes follow BEM-like naming:
ss-{hash}for base,ss-{hash}--{variant}-{value}for variants - Zero Runtime CSS: No runtime CSS generation. The component just maps props to pre-generated class names.
See Also
- cssVariants - Get a variant function that returns class strings
- css - Get a scoped class name for CSS
- styled - Create styled components without variants