Skip to main content

Overview

Svelte Atoms Core is designed to be headless - giving you complete control over styling while providing sensible defaults. Customize components through variants, props, presets, and standard HTML/CSS attributes.

Styling with Variants

Variants provide a type-safe way to define component styles with different options.

Defining Variants

Create variant configurations using defineVariants:

Using Variants in Components

Compound Variants

Apply styles when multiple variant conditions match:
Compound variants are perfect for edge cases where specific combinations need special styling.

Dynamic Variants with Bonds

Access component state through bonds for reactive styling:

Reactive Variant Functions

Individual variant values can also be functions:
Variant functions receive the component’s bond and can return both classes and other attributes (aria-, data-, etc.).

Component Props

Common Props

All components support standard HTML attributes and additional custom props:

Base Prop for Composition

Transform components using the base prop:

Global Presets

Define global styling presets for consistent theming across your application.

Creating a Preset

Using Presets

Extending Component Types

Add custom properties to components through TypeScript interface extension:

Styling Patterns

Use Tailwind utility classes directly:

Theming

CSS Variables

Use CSS custom properties for themeable components:

Dark Mode

Implement dark mode with class-based toggling:

Best Practices

1

Start with base styles

Define a consistent base class for all variants:
2

Use semantic variant names

Name variants based on purpose, not appearance:
3

Keep variants composable

Make variants work together independently:
4

Use presets for consistency

Define global presets for shared styling:

Next Steps

Using Components

Learn component patterns and composition

State Management

Master bonds and reactive state

TypeScript

Type-safe customization

Examples

Browse customization examples