Search the documentation

Type to search page titles, component names and descriptions.

    Develop

    Styles and theming

    How to load the stylesheet, write your own CSS beside it, and override the design system: which tokens, where, and what stays out of reach.

    faifo-design/styles.css is one file: reset, tokens, fonts and the rules of every component. This page is the working guide to it: how to load it, how to write application CSS next to it, and how to change what it gives you.

    #Load it once

    /* app.css, the stylesheet your application already bundles */
    @import "faifo-design/styles.css";

    A page without a bundler links the built file instead:

    <link rel="stylesheet" href="/vendor/faifo-design/styles.css" />

    Components are styled only inside an element that carries data-faifo-design. Tokens are declared on :root, so they are available everywhere, also outside that element.

    <body>
      <main data-faifo-design>…</main>
    </body>

    #The four layers

    The stylesheet is written in cascade layers, declared in this order on its first line:

    @layer faifo.reset, faifo.theme, faifo.app, faifo.user;
    LayerHoldsYou write in it
    faifo.resetThe resetNo
    faifo.themeTokens: every --faifo-* custom propertyNo
    faifo.appComponent rulesNo
    faifo.userNothing from the design systemYes

    A later layer wins over an earlier one whatever the specificity of the selectors, and CSS outside any layer wins over every layer. So a rule of yours never needs !important or a longer selector to beat the design system: it needs to be in faifo.user, in a layer you declared after faifo.app, or in no layer at all.

    @import "faifo-design/styles.css";
    
    @layer faifo.user {
      :root {
        --faifo-accent: #0f766e;
      }
    }

    An application with layers of its own fixes where they stand by naming every layer in one statement before the import. The first statement that names a layer decides its place:

    @layer faifo.reset, faifo.theme, faifo.app, app.screens, faifo.user;
    @import "faifo-design/styles.css";
    
    @layer app.screens {
      .order-summary { … }
    }

    Two things to avoid. !important reverses the order of layers, so an important declaration in faifo.user loses to an important one in an earlier layer. revert-layer hands a property back to the design system from inside your rule and is reported by the layout audit.

    #Writing your own CSS

    Your screens have elements of their own: a summary beside a form, a map, a print header. Style them with your own class names and the system's tokens, so they follow the theme, the density and the dark scheme without a second set of values:

    @layer faifo.user {
      .order-summary {
        display: grid;
        gap: var(--faifo-space-3);
        padding: var(--faifo-surface-inset);
        border: 1px solid var(--faifo-panel-border);
        border-radius: var(--faifo-radius-lg);
        background: var(--faifo-panel-bg);
        color: var(--faifo-text-main);
        font-size: var(--faifo-text-sm);
        line-height: var(--faifo-line-sm);
      }
    
      .order-summary-note {
        color: var(--faifo-text-secondary);
      }
    
      .order-summary[data-pinned] {
        position: sticky;
        inset-block-start: 0;
        z-index: var(--faifo-layer-sticky);
        box-shadow: var(--faifo-shadow-md);
      }
    }
    ForUseNot
    ColourSemantic tokens: --faifo-text-*, --faifo-panel-*, --faifo-accent-*, --faifo-danger-*A hex value, or --faifo-ref-*
    Space--faifo-space-*A length of your own
    Type--faifo-text-* with the matching --faifo-line-*, --faifo-weight-*A font-size in pixels
    Corners--faifo-radius-*, --faifo-control-radiusA radius of your own
    Depth--faifo-shadow-*A box-shadow you drew
    Stacking--faifo-layer-*A numeric z-index
    Motion--faifo-duration-*, --faifo-ease-*A duration of your own

    Before writing layout CSS, look for the component that already does it: Stack, Inline, Grid, Surface and the page patterns own spacing and alignment, and they adapt to phones. The token reference lists every name with its value in both schemes.

    #Overriding: start with the least

    Reach for the first of these that does the job.

    You wantDo this
    A different look that the component offersA prop: variant, size, tone
    Another brand colour, radius or font everywhereRedefine tokens on :root
    A different density or scheme in one areadata-density or data-theme on that area
    One measure of one componentRedefine that component's token on a scope
    A look no prop or token givesChange the component in the design system

    #Tokens for the whole application

    Redefine tokens on :root, the element the design system declares them on:

    @layer faifo.user {
      :root {
        /* Brand colour: the fill of primary actions and its states. */
        --faifo-accent: #0f766e;
        --faifo-accent-hover: #0d5f59;
        --faifo-accent-active: #0a4d48;
        /* The tints and the text colour differ between the schemes. */
        --faifo-accent-subtle: light-dark(#e6f4f2, #12312e);
        --faifo-accent-muted: light-dark(#cfe9e5, #17403c);
        --faifo-accent-border: light-dark(#a7d6cf, #1f5a54);
        --faifo-accent-text: light-dark(#0b5a54, #5fd0c4);
        --faifo-focus-ring: 0 0 0 3px light-dark(#cfe9e5, rgb(95 208 196 / 24%));
    
        --faifo-control-radius: 0.375rem;
      }
    }

    --faifo-accent carries white text (--faifo-on-accent); keep at least 4.5:1 between the two. light-dark() picks the first value in the light scheme and the second in the dark one, which is how the system's own tokens are written.

    Why :root and not [data-faifo-design]: many tokens are defined from other tokens, and such a definition is resolved on the element that declares it. --faifo-action-primary-bg is var(--faifo-accent), declared on :root. Redefine --faifo-accent on :root and the primary button follows. Redefine it on an element further in, and that element's children inherit the new --faifo-accent but the old, already resolved --faifo-action-primary-bg: links and tints change, the primary button does not.

    #Tokens for one area

    A scope takes the tokens it needs, including the ones derived from them:

    @layer faifo.user {
      .partner-portal {
        --faifo-accent: #7c3aed;
        --faifo-accent-hover: #6d28d9;
        --faifo-accent-active: #5b21b6;
        --faifo-action-primary-bg: var(--faifo-accent);
        --faifo-action-primary-hover: var(--faifo-accent-hover);
        --faifo-action-primary-active: var(--faifo-accent-active);
      }
    }

    Density and the colour scheme need no CSS at all:

    <section data-faifo-design data-density="compact">…</section>
    <aside data-faifo-design data-theme="dark">…</aside>
    AttributeOnEffect
    data-faifo-designThe application root, or any areaComponents inside are styled
    data-theme="light" or "dark"The root element or a data-faifo-design elementPins the colour scheme; without it the system preference decides
    data-density="compact" or "comfortable"A data-faifo-design elementShifts control height, row height and gaps

    #Tokens of one component

    Some measures belong to one component and have a token of their own: the sidebar width, the height of a row, the height of a table header. Set them on your own element around the component, or on the component's hook. A rule that only sets custom properties on a hook is not a restyle, and the ratchet does not count it.

    @layer faifo.user {
      /* Your wrapper: a wider sidebar, and taller rows in every table and tree inside. */
      .warehouse {
        --faifo-sidebar-width: 17rem;
        --faifo-row-height: 3rem;
      }
    
      /* The hook itself, with nothing but a token. */
      [data-ui="table"] {
        --faifo-table-header-height: 3rem;
      }
    }

    Prefer the wrapper. A component may set one of its tokens itself to express a state (a collapsed sidebar sets --faifo-sidebar-width to zero on the shell), and a rule of yours on the same element would win over that state. A value inherited from a wrapper does not.

    --faifo-row-height and --faifo-control-height are set on the data-faifo-design element from the density, so a wrapper that redefines them has to be that element or one inside it.

    #Your elements beside a component

    A rule may mention a component as long as what it styles is yours:

    @layer faifo.user {
      /* Yours inside a component. */
      [data-ui="surface"] .order-summary-note {
        margin-block-start: var(--faifo-space-2);
      }
    
      /* Yours around a component. */
      .order-row:has([data-ui="badge"][data-tone="danger"]) {
        background: var(--faifo-danger-bg);
      }
    }

    #What not to override

    A rule whose subject is a design-system element, and that declares anything but a token on it, is a second definition of that component:

    /* Do not: the look of a badge is decided in the design system. */
    [data-ui="badge"] {
      border-radius: 0;
      text-transform: uppercase;
    }

    It works today, because your layer wins. It breaks later: the component's markup and rules change between versions, and only its props, its tokens and its data-ui names are public. When a component looks wrong on your screen, it is missing a variant or has a defect: change it in the design system, with a specimen and a test, and every screen gets the fix. The contract describes the ratchet that keeps such rules from growing, and the audit you can run over your own stylesheets:

    npx faifo-design-layout-audit src/screens/orders.css

    Also leave the --faifo-ref-* palette alone. It is read only by the token file, and the semantic tokens are what components and your CSS depend on.

    #Fonts

    Replace the typeface by redefining the family tokens on :root. --faifo-font-display is defined from --faifo-font-sans, so headings follow.

    @layer faifo.user {
      :root {
        --faifo-font-sans: "Your Sans", ui-sans-serif, system-ui, sans-serif;
        --faifo-font-mono: "Your Mono", ui-monospace, monospace;
      }
    }

    Porto Faifo Sans, Porto Faifo Mono and Inter are embedded in the stylesheet as WOFF2 under SIL OFL 1.1. Nothing is fetched from a font service. A content security policy must allow data: in font-src. When you bundle the package source yourself, as this site does, your bundler can emit the fonts as files instead.

    Fonts served as files arrive after the first paint. The token layer covers that period itself: each brand family is followed by a platform font with the same average advance, ascent and descent, so text does not re-break or shift when the brand font replaces it. There is nothing to configure, and no preload is required for a stable layout. Long-lived caching of the font files is still worth setting on your host, because it removes the change of letter shapes as well.

    #Tokens without components

    faifo-design/tokens.css exports the token layer alone, for a kit that shares the foundations and renders its own components:

    @import "faifo-design/tokens.css";
    
    .kit-card {
      padding: var(--faifo-space-4);
      border-radius: var(--faifo-radius-lg);
      background: var(--faifo-panel-bg);
    }

    #Check your work

    • Switch the scheme and the density on the screen you changed; a value that does not follow is a literal that should have been a token.
    • Run npx faifo-design-layout-audit over the stylesheets you touched.
    • Search your CSS for !important, hex colours and numeric z-index: each is a sign that a token or a component was skipped.