Conventions
Guides for building with Fluid UI Svelte. Learn how ids, styling, variants, and overrides fit together.
Conventions
These guides show how to build with Fluid UI. They cover the id and class conventions, how to style the library, and how to customize components with variants and CSS.
Id Convention
Give every element an id. Component and prebuilt elements build the ids of their parts from their class name and that id. The root is fluid-<component>-<id>, and each part is fluid-<component>-<part>-<id>, so an id and a class use the same words. Base elements keep the id you give them.
| Element | Class | Id |
|---|---|---|
Accordion root | fluid-accordion | fluid-accordion-faq |
Accordion header | fluid-accordion-header | fluid-accordion-header-faq |
Accordion body | fluid-accordion-body | fluid-accordion-body-faq |
AnchoredOverlay float | fluid-anchored-overlay-float | fluid-anchored-overlay-float-my-overlay |
<Accordion id="faq"> {#snippet header()}Shipping{/snippet} {#snippet body()}Delivery takes three days.{/snippet}</Accordion> <!-- rendered ids and classes --><!-- root: id="fluid-accordion-faq" class="fluid-accordion" --><!-- header: id="fluid-accordion-header-faq" class="fluid-accordion-header" --><!-- body: id="fluid-accordion-body-faq" class="fluid-accordion-body" -->Using Base Elements
Build components, prebuilt elements, and pages from base elements instead of raw HTML tags. Base elements merge classes and handle accessibility, so your markup stays consistent.
| Instead of | Use |
|---|---|
<div>, <p>, <span> | <Container>, <Text> |
<button>, <a> | <Button>, <Link> |
<table>, <canvas> | <Table>, <Canvas> |
<input> | <InputField> |
Base Element Props
Base elements are low-level wrappers around native HTML. They merge classes and keep markup consistent, so you add styles to them with class.
| Prop | Type | Default | Purpose |
|---|---|---|---|
id | string | required | Identifies the element in the DOM |
underlyingElement | HTMLElement | null | null ($bindable) | Exposed as $bindable(null) for bind:this |
class | string | "" | Added on top of the default fluid-* class |
variant (Components/Prebuilt) | string | "" | A name you choose, added to the root element |
Styling Hooks
Every element gets its default look from fluidui.css. You change the look in three ways: a class on a base element, a variant on a component or prebuilt element, or a CSS rule in your application. Components and prebuilt elements do not accept class, so you change their look through variants and CSS.
| Layer | Hook | Example |
|---|---|---|
Base | class, added on top of the default | <Button class="rounded-full"> |
Components | variant, a name added to the root | <Modal variant="faq-modal"> |
Prebuilt | variant, a name added to the root | <InternationalInput variant="checkout-country"> |
Stylesheet Copy
fluidui.css ships inside the package. Copy it into the root of your project. The copy belongs to your application, so you can edit it. Copies do not update themselves, so copy the file again after each release.
cp node_modules/fluid-ui-svelte/src/fluidui.css ./src/fluidui.cssStylesheet Import
Import the copied file in your main stylesheet after Tailwind. Fluid UI styles use Tailwind 4 syntax, so your application must run Tailwind 4. Rules you write below the import have no layer, so they win over the library.
/* src/styles.css */@import "tailwindcss";@import "./fluidui.css"; /* Your application styles go below, unlayered, so they win over the library */Colors
The library uses Tailwind theme names, such as bg-primary-500. You define the values in your own @theme block. Define every shade from 50 to 950 for primary, secondary, neutral, success, warning, error, and info. The library ships no design tokens in this version. A token layer is planned for a later release.
/* src/styles.css */@import "tailwindcss";@import "./fluidui.css"; @theme { --color-primary-500: #3e6ff3; --color-secondary-500: #8b5cf6; /* every shade from 50 to 950 for primary, secondary, neutral, success, warning, error, and info */}Layers and Specificity
All library rules sit in one layer named fluid, placed after the base rules and before utilities. Your unlayered CSS beats every library rule, so overrides need no !important.
| Rule | Effect |
|---|---|
Unlayered application CSS | Beats every library rule |
Scoped selectors | .fluid-accordion .fluid-accordion-body beats the single-class default of the same element |
Equal specificity | The rule that comes later in fluidui.css wins |
Base Defaults
Every base element has one default class that holds its look. Components build their parts from base elements, so the parts inherit these defaults unless the component's own rules change them.
| Element | Default class |
|---|---|
Button | fluid-button |
Canvas | fluid-canvas |
Container | fluid-container |
Form | fluid-form |
Image | fluid-image |
InputField | fluid-input-field |
Label | fluid-label |
Link | fluid-link |
List | fluid-unordered-list or fluid-ordered-list |
Table | fluid-table, with fluid-table-head, fluid-table-body, fluid-table-row, fluid-table-cell, and fluid-table-footer |
Text | fluid-text |
Overrides Through Class
Add a class to a base element to change one instance. The class is added on top of the default, so the element keeps its default look except where your class sets a different value.
<Button id="save-button" class="rounded-full">Save</Button>Overrides Through CSS
Write a rule in your application to change every element of a kind, or only the elements inside one variant. Start a variant rule from the variant name so it reaches the parts of the component.
/* every fluid-button in the application */.fluid-button { border-radius: 999px;} /* every fluid-button inside one variant */.faq-tight .fluid-button { padding: 0.25rem;}Variants
A variant is a name you choose. It is added to the root element of a component or prebuilt element. The library never sets a variant, so the defaults stay unchanged. Variant names must be unique in your application.
<Accordion id="faq" variant="faq-tight"> {#snippet header()}Shipping{/snippet} {#snippet body()}Delivery takes three days.{/snippet}</Accordion>Variant Rules
Every rule for a variant starts from the variant name, so the variant reaches the parts of its component without the parts carrying the name themselves.
/* src/styles.css, after the import of fluidui.css */.faq-tight .fluid-accordion-header { padding: 0.25rem; font-size: 0.875rem;}Dark Mode
Dark values use the Tailwind dark variant, which applies inside any element with the dark class. Set the class on the container of the root layout, in src/routes/+layout.svelte, so every page inside it switches together.
<!-- src/routes/+layout.svelte --><script lang="ts"> import { Container } from "fluid-ui-svelte/base"; let { children } = $props(); let isDarkMode = $state(false);</script><Container id="global-layout" class={["min-h-screen", isDarkMode ? "dark" : ""].join(" ")}> {@render children()}</Container>Snippets for Custom Markup
Use Svelte 5 snippets instead of configuration objects when you need custom markup, such as a slot or an item template. Snippets keep the markup flexible and the components consistent.
{#snippet anchor({ toggle })} <Button onclick={async () => toggle()}>Open</Button>{/snippet}{#snippet overlay({ close })} <Container>...</Container>{/snippet}Import Paths
Import components from the package in your application. The internal paths below are used inside the library's own source and documentation.
| Context | Import Path | Example |
|---|---|---|
Library source | #src/lib/base/index.ts | import { Button } from "#src/lib/base/index.ts" |
Library source (components) | #src/lib/components/index.ts | import { AnchoredOverlay } from "#src/lib/components/index.ts" |
Your application | fluid-ui-svelte/base | import { Button } from 'fluid-ui-svelte/base' |
Your application (components) | fluid-ui-svelte/components | import { Modal } from 'fluid-ui-svelte/components' |
Your application (prebuilt) | fluid-ui-svelte/prebuilt | import { Breadcrumb } from 'fluid-ui-svelte/prebuilt' |
Where Code Lives
Keep markup, logic, and styles in separate files. Markup in .svelte files describes what is rendered. Logic in .ts helpers holds pure functions that compute values. Styles in fluidui.css hold the look.
| Kind | File | Contains |
|---|---|---|
.svelte | Component.svelte | Markup, with helpers imported from component.ts |
.ts helper | component.ts | Pure functions that compute state and values |
fluidui.css | fluidui.css | One block per element, part, and variant |
Naming and Error Handling
Use full names for variables and functions, keep functions short, and return early when a precondition fails, so the main path stays at the top level.
function getCountryData(isoCode: string): CountryData { if (!isoCode) return COUNTRY_DATA_MAP["US"]; const upperCode = isoCode.toUpperCase(); return COUNTRY_DATA_MAP[upperCode] ?? COUNTRY_DATA_MAP["US"];}