Custom Properties
Runtime-Anpassung: Jeder forma-css-Token ist eine CSS Custom Property. Setze sie auf :root oder scope sie pro Element \u2013 ohne Rebuild.
Beschreibung
Jeder Token in forma-css ist eine CSS-Custom-Property mit dem Präfix --forma-. Setze sie auf :root, um die ganze Seite umzuthemen, oder auf ein beliebiges Element, um die Änderung zu scopen: forma löst alles zur Laufzeit, verpackt in light-dark(), also bedient eine Regel beide Themes.
Jede Farbe erhält neben der hellen eine -dark-Custom-Property; lässt du -dark ungesetzt, löst ihre Fallback-Kette den hellen Wert auf, der dunkle Modus bricht also nie. Ein typisches Theme braucht nur eine Handvoll Deklarationen:
:root {
--forma-color-primary: #083cc0;
--forma-color-primary-dark: oklch(70% 0.12 250);
--forma-color-background: white;
--forma-color-background-dark: oklch(20% 0.02 250);
--forma-color-text: #222;
--forma-color-text-dark: white;
--forma-color-success: green;
--forma-color-success-dark: #4caf50;
--forma-font-family: "Inter", sans-serif;
--forma-border-radius-button: 0.25rem;
--forma-transition-fast: 0.15s;
}Kein Build-Schritt, kein Recompile: das kompilierte forma-css bleibt unberührt, und Nutzer können Themes sogar zur Laufzeit wechseln. Eine Variable auf einer Komponenten-Scope betrifft nur diesen Teilbaum, also kosten Mikro-Themes (eine Warn-Card, ein dunkler Footer) eine Deklaration.
Nutze für Markfarben bevorzugt oklch oder relative Farben, damit Hover-, Active- und Secondary-Zustände weiter automatisch abgeleitet werden. Scope Overrides möglichst auf das nächste Element statt auf :root, und halte Dark-Varianten neben ihrem hellen Wert.
Rethemen ohne Rebuild
Zwei Deklarationen auf einem div rethemieren den Teilbaum: Primärfarbe und Button-Radius, ganz ohne Rebuild. Dieselben Tokens auf :root rethemieren die ganze Seite.
<div style="--forma-color-primary: oklch(55% 0.2 150); --forma-border-radius-button: 1.25em;">
<button>Thematischer Button</button>
<a href="#">Thematischer Link</a>
</div>Alle Custom Properties
Die vollständige Referenz. Die Farb-Tabelle führt beide Custom Properties, hell und dunkel, nebeneinander auf; Tokens außerhalb der Farbgruppe sind in beiden Modi identisch. Icon-Variablen haben keinen Standardwert: Du zeigst sie auf dein eigenes Inline-SVG-Bild. Das Präfix --forma- selbst stammt aus $css-var-prefix in der Sass-Konfiguration, ein Rebranding des Präfixes ist also ein Build-Schritt.
Farben
So funktioniert der Fallback: Die -dark-Property hat keine feste Fallback-Farbe. Sie fällt auf ihren hellen Zwilling zurück, --forma-color-primary-dark löst also zu var(--forma-color-primary) auf, und nur dann zu #083cc0, wenn du auch primary nicht neu definiert hast. Deshalb zeigen primary und secondary in beiden Spalten denselben Standard: Im dunklen Modus übernehmen sie schlicht den hellen Wert, solange du die -dark-Variante nicht definierst. Redefinierst du nur --forma-color-primary, folgt der dunkle Modus automatisch deinem neuen Wert.
| Heller Modus | Dunkler Modus | Standard (hell) | Standard (dunkel) | Steuert |
|---|---|---|---|---|
--forma-color-primary | --forma-color-primary-dark | #083cc0 | #083cc0 | Primäre Marke: Buttons, Links, aktive Zustände |
--forma-color-secondary | --forma-color-secondary-dark | #05a5d1 | #05a5d1 | Sekundäre Akzente |
--forma-color-text | --forma-color-text-dark | #222 | white | Text und currentColor-Icons |
--forma-color-background | --forma-color-background-dark | white | #2a2a2a | Seitenhintergrund |
--forma-color-backdrop | --forma-color-backdrop-dark | white 40% | black 20% | Overlay hinter Modals, Off-canvas, Toasts |
--forma-color-panel | --forma-color-panel-dark | white | black | Karten, Modals, Dropdowns, Nav-Leisten |
--forma-color-border-panel | --forma-color-border-panel-dark | #e0e0e0 | #2a2a2a | Ränder von Panels und Inputs |
--forma-color-gray-highlight | --forma-color-gray-highlight-dark | #cccccc | #505050 | Dezente Ränder, disabled-Füllungen, Switch-Tracks |
--forma-color-success | --forma-color-success-dark | green | #4caf50 | Gültiger Zustand, .text-success |
--forma-color-danger | --forma-color-danger-dark | #ff4800 | #ff7043 | Ungültiger Zustand, .text-danger |
--forma-color-info | --forma-color-info-dark | #0059ff | #5b8cff | Info-Hervorhebungen, .text-info |
--forma-color-warning | --forma-color-warning-dark | #fef600 | #ffe014 | Warnungs-Hervorhebungen, .text-warning |
Typografie
| Property | Standard | Steuert |
|---|---|---|
--forma-font-family | Arial | Fließtext |
--forma-font-family-headings | Arial | Überschriften h1–h6 |
--forma-font-family-buttons | Arial | Buttons und Formular-Controls |
--forma-font-weight | normal | Grundschriftstärke |
--forma-line-height | 120% | Grund-Zeilenhöhe |
--forma-font-size-base | 16px | Root-Größe, die die Breakpoint-Skala multipliziert |
--forma-font-size | 16px | Basis-Schriftgröße der Elemente |
Abstände und Skalen
| Property | Standard | Steuert |
|---|---|---|
--forma-gutter | 1em | Grid- und Layout-Gutter |
--forma-scale-sm | 0.7 | .sm-Utility-Skala (Badge, kleiner Text) |
--forma-scale-lg | 1.3 | .lg-Utility-Skala |
--forma-scale-xl | 1.5 | .xl-Utility-Skala |
--forma-mobile-modal-margin | 0em | Rand um Vollbild-Modals auf Mobil |
Form, Bewegung und Tiefe
| Property | Standard | Steuert |
|---|---|---|
--forma-border-radius-panel | 0.5rem | Eckenradius von Karten, Modals, Inputs |
--forma-border-radius-button | 0.25rem | Eckenradius von Buttons |
--forma-transition-slow | 0.5s | Langsame Transitionen (Modals, Off-canvas) |
--forma-transition-fast | 0.2s | Schnelle Transitionen (Hover, Fokus) |
--forma-elevation-1 | 0 0 0.25rem rgba(0,0,0,.2) | Schatten Ebene 1: Karten, Nav |
--forma-elevation-2 | 0 0 0.75rem rgba(0,0,0,.3) | Schatten Ebene 2: Fokus, Dropdowns, Inputs |
--forma-elevation-3 | 0 0 1.5rem rgba(0,0,0,.4) | Schatten Ebene 3: Modals, Toasts |
--forma-filter-backdrop | none | Filter auf Overlays (z. B. blur(2px)) |
--forma-filter-panel | none | Filter auf Panels |
Formular-Icons
| Property | Standard | Steuert |
|---|---|---|
--forma-icon-search | – | Lupe des Suchfelds und der Hidden Search |
--forma-icon-date | – | Kalender-Icon von Date-Inputs |
--forma-icon-time | – | Uhr-Icon von Time-Inputs |
--forma-icon-expand | – | Chevron von Selects und Akkordeons |
--forma-icon-check | – | Häkchen in Checkboxen |
--forma-icon-invalid-true | – | Icon bei aria-invalid="true" |
--forma-icon-invalid-false | – | Icon bei aria-invalid="false" |