# Bulma CSS — v1.x Features Reference

Complete reference for CSS Variables, Themes, Dark Mode, Color Palettes, and Skeletons.

---

## CSS Variables System

### Naming Convention
All Bulma CSS variables use the `--bulma-` prefix (configurable via `$cssvars-prefix`).

Pattern: `--bulma-[property]` or `--bulma-[component]-[property]`

### Two Scope Levels
- **Global** (`:root`) — default values
- **Component** (e.g., `.button`, `.title`) — component-specific overrides that take precedence

```css
:root {
  --bulma-size-medium: 1.25rem; /* global default */
}
.button {
  --bulma-size-medium: 1.5rem; /* button-specific override */
}
```

### Key Global CSS Variables

**Scheme (Background/Surface):**
- `--bulma-scheme-h` — scheme hue
- `--bulma-scheme-s` — scheme saturation
- `--bulma-scheme-main-l` — main background lightness (100% light, 11% dark)
- `--bulma-scheme-main-bis-l` — secondary bg lightness (98% light, 13% dark)
- `--bulma-scheme-main-ter-l` — tertiary bg lightness (98% light, 15% dark)

**Text:**
- `--bulma-text-l` — text lightness (29% light, 71% dark)
- `--bulma-text-weak-l` — weak text lightness (48% light, 53% dark)
- `--bulma-text-strong-l` — strong text lightness (21% light, 93% dark)
- `--bulma-text-title-l` — title lightness (14% light, 100% dark)

**Borders:**
- `--bulma-border-l` — border lightness (86% light, 24% dark)
- `--bulma-border-weak-l` — weak border lightness (93% light, 21% dark)
- `--bulma-background-l` — background lightness (96% light, 14% dark)

**Interaction Deltas:**
- `--bulma-hover-background-l-delta` — `5%`
- `--bulma-active-background-l-delta` — `10%`
- `--bulma-hover-border-l-delta` — `10%`
- `--bulma-active-border-l-delta` — `20%`
- `--bulma-hover-color-l-delta` — `5%`
- `--bulma-active-color-l-delta` — `10%`

---

## Themes

Themes are collections of CSS variables applied within specific selectors.

### Built-in Themes
- **Light** — `sass/themes/light.scss` (required)
- **Dark** — `sass/themes/dark.scss` (optional)

### CSS Output Structure
```css
:root { /* Light theme (default) */ }

@media (prefers-color-scheme: light) {
  :root { /* Light theme */ }
}
@media (prefers-color-scheme: dark) {
  :root { /* Dark theme */ }
}

[data-theme=light], .theme-light { /* Light overrides */ }
[data-theme=dark], .theme-dark { /* Dark overrides */ }
```

### Switching Methods
1. **Data attribute**: `<html data-theme="dark">`
2. **CSS class**: `<html class="theme-dark">`
3. **System preference**: automatic via `prefers-color-scheme`
4. **Element-level**: `<div data-theme="dark">` or `<div class="theme-dark">`

### Theme Sass Mixins

```scss
// Generate [data-theme=X] and .theme-X selectors
@include cv.bulma-theme($name: "my-theme") {
  // CSS variable declarations
}

// Wrap in @media (prefers-color-scheme: X)
@include cv.system-theme($name: "dark") {
  // CSS variable declarations
}
```

### Key Theme Functions
| Function | Description |
|----------|-------------|
| `register-vars()` | Batch CSS variable registration with prefix, accepts Sass maps |
| `generate-on-scheme-colors()` | Creates color variants for all 7 colors with contrast |
| `setup-theme()` | Redefines composite CSS variables after updating lightness values |

### Creating a Custom Theme
```scss
@use "bulma/sass/utilities/css-variables" as cv;

@include cv.bulma-theme($name: "sunrise") {
  --bulma-scheme-h: 35;
  --bulma-scheme-s: 20%;
  --bulma-scheme-main-l: 98%;
  --bulma-primary-h: 25;
  --bulma-primary-s: 100%;
  --bulma-primary-l: 55%;
}
```

Activating: `<html data-theme="sunrise">` or `<html class="theme-sunrise">`

---

## Dark Mode

### Activation

**Automatic** (system preference):
```css
@media (prefers-color-scheme: dark) { /* applied automatically */ }
```

**Manual override** (takes precedence):
```html
<!-- Full page -->
<html data-theme="dark">
<html class="theme-dark">

<!-- Partial page -->
<div data-theme="dark">Only this section is dark</div>
<div class="theme-dark">Also dark</div>
```

### Complete Lightness Variables (Light vs Dark)

| CSS Variable | Light | Dark |
|-------------|-------|------|
| `--bulma-scheme-main-l` | 100% | 11% |
| `--bulma-scheme-main-bis-l` | 98% | 13% |
| `--bulma-scheme-main-ter-l` | 98% | 15% |
| `--bulma-background-l` | 96% | 14% |
| `--bulma-border-weak-l` | 93% | 21% |
| `--bulma-border-l` | 86% | 24% |
| `--bulma-text-weak-l` | 48% | 53% |
| `--bulma-text-l` | 29% | 71% |
| `--bulma-text-strong-l` | 21% | 93% |
| `--bulma-text-title-l` | 14% | 100% |
| `--bulma-hover-background-l-delta` | 5% | 5% |
| `--bulma-active-background-l-delta` | 10% | 10% |
| `--bulma-hover-border-l-delta` | 10% | 10% |
| `--bulma-active-border-l-delta` | 20% | 20% |
| `--bulma-hover-color-l-delta` | 5% | 5% |
| `--bulma-active-color-l-delta` | 10% | 10% |

### JavaScript Toggle
```js
document.getElementById('themeToggle').addEventListener('click', () => {
  const html = document.documentElement;
  const isDark = html.dataset.theme === 'dark';
  html.dataset.theme = isDark ? 'light' : 'dark';
});
```

---

## Color Palettes

Bulma generates extensive CSS variables for 7 primary colors: `text`, `link`, `primary`, `info`, `success`, `warning`, `danger`.

### Variables Per Color (using `primary` as example)

**Base:**
- `--bulma-primary` — base color
- `--bulma-primary-base` — equals base
- `--bulma-primary-rgb` — for custom RGBA: `rgba(var(--bulma-primary-rgb), 0.5)`
- `--bulma-primary-h` — hue
- `--bulma-primary-s` — saturation
- `--bulma-primary-l` — lightness

**Tonal Variants:**
- `--bulma-primary-invert`
- `--bulma-primary-light`
- `--bulma-primary-light-invert`
- `--bulma-primary-dark`
- `--bulma-primary-dark-invert`
- `--bulma-primary-soft`
- `--bulma-primary-soft-invert`
- `--bulma-primary-bold`
- `--bulma-primary-bold-invert`
- `--bulma-primary-on-scheme`

**21 Lightness Shades (0–100%, step 5):**
- `--bulma-primary-00` through `--bulma-primary-100`
- Each has `-invert` counterpart: `--bulma-primary-00-invert` through `--bulma-primary-100-invert`
- Each has lightness variable: `--bulma-primary-00-l` through `--bulma-primary-100-l`

**HSL Construction:**
```css
--bulma-primary-75: hsla(
  var(--bulma-primary-h),
  var(--bulma-primary-s),
  var(--bulma-primary-75-l),
  1
);
```

### Total Variables Per Color
~70+ CSS variables per color = ~490+ color CSS variables total

### CSS Helper Classes
For every color and variant:
- `has-text-{color}` / `has-background-{color}`
- `has-text-{color}-light` / `has-background-{color}-light`
- `has-text-{color}-dark` / `has-background-{color}-dark`
- `has-text-{color}-soft` / `has-background-{color}-soft`
- `has-text-{color}-bold` / `has-background-{color}-bold`
- `has-text-{color}-on-scheme` / `has-background-{color}-on-scheme`
- `has-text-{color}-00` through `has-text-{color}-100`
- `has-background-{color}-00` through `has-background-{color}-100`
- All shade classes have `-invert` counterparts

### Light/Dark Behavior
- **Soft** colors = light backgrounds in light mode, dark in dark mode
- **Bold** colors = dark text in light mode, light in dark mode
- They swap automatically when theme changes

---

## Skeletons

Loading placeholder components for use while content is loading.

### CSS Variables
| Variable | Default |
|----------|---------|
| `--bulma-skeleton-background` | `var(--bulma-border)` |
| `--bulma-skeleton-radius` | `var(--bulma-radius-small)` |
| `--bulma-skeleton-block-min-height` | `4.5em` |
| `--bulma-skeleton-lines-gap` | `0.75em` |
| `--bulma-skeleton-line-height` | `0.75em` |

### Standalone Elements

**Skeleton Block** — rectangular placeholder:
```html
<div class="skeleton-block"></div>
```

**Skeleton Lines** — multiple line placeholders:
```html
<div class="skeleton-lines">
  <div></div>
  <div></div>
  <div></div>
</div>
```

### Modifier Classes

**`is-skeleton`** — transforms an entire component into loading state:
```html
<button class="button is-skeleton">Loading</button>
<span class="tag is-skeleton">Tag</span>
<h1 class="title is-skeleton">Title</h1>
<input class="input is-skeleton" placeholder="Loading...">
```

**`has-skeleton`** — applies skeleton only to content portion:
```html
<h1 class="title has-skeleton">Title</h1>
```

### Supported Components
| Component | `is-skeleton` | `has-skeleton` |
|-----------|:---:|:---:|
| Button | yes | — |
| Icon | yes | — |
| Image | yes (all sizes) | — |
| Input | yes | — |
| Textarea | yes | — |
| Notification | yes | — |
| Tag | yes (all colors) | — |
| Title | yes | yes |
| Subtitle | yes | yes |
| Media Object | yes (on children) | — |

### Animation
Skeletons use CSS keyframes with a pulsating effect. Duration, size, and colors are configurable via CSS variables.

### Example — Card Skeleton
```html
<div class="card">
  <div class="card-image">
    <figure class="image is-4by3 is-skeleton"></figure>
  </div>
  <div class="card-content">
    <div class="media">
      <div class="media-left">
        <figure class="image is-48x48 is-skeleton"></figure>
      </div>
      <div class="media-content">
        <p class="title is-4 is-skeleton">Loading</p>
        <p class="subtitle is-6 is-skeleton">Loading</p>
      </div>
    </div>
    <div class="skeleton-lines">
      <div></div>
      <div></div>
      <div></div>
    </div>
  </div>
</div>
```
