Conventions Guide ยท Part 02

Conventions

Guides for building with Fluid UI Svelte. Learn how ids, styling, variants, and overrides fit together.

01

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.

02

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.

ElementClassId
Accordion rootfluid-accordionfluid-accordion-faq
Accordion headerfluid-accordion-headerfluid-accordion-header-faq
Accordion bodyfluid-accordion-bodyfluid-accordion-body-faq
AnchoredOverlay floatfluid-anchored-overlay-floatfluid-anchored-overlay-float-my-overlay
Id Convention svelte
<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" -->
03

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 ofUse
<div>, <p>, <span><Container>, <Text>
<button>, <a><Button>, <Link>
<table>, <canvas><Table>, <Canvas>
<input><InputField>
04

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.

PropTypeDefaultPurpose
idstringrequiredIdentifies the element in the DOM
underlyingElementHTMLElement | nullnull ($bindable)Exposed as $bindable(null) for bind:this
classstring""Added on top of the default fluid-* class
variant (Components/Prebuilt)string""A name you choose, added to the root element
05

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.

LayerHookExample
Baseclass, added on top of the default<Button class="rounded-full">
Componentsvariant, a name added to the root<Modal variant="faq-modal">
Prebuiltvariant, a name added to the root<InternationalInput variant="checkout-country">
06

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.

Stylesheet Copy bash
cp node_modules/fluid-ui-svelte/src/fluidui.css ./src/fluidui.css
07

Stylesheet 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.

Stylesheet Import css
/* src/styles.css */
@import "tailwindcss";
@import "./fluidui.css";
 
/* Your application styles go below, unlayered, so they win over the library */
08

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.

Colors css
/* 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 */
}
09

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.

RuleEffect
Unlayered application CSSBeats every library rule
Scoped selectors.fluid-accordion .fluid-accordion-body beats the single-class default of the same element
Equal specificityThe rule that comes later in fluidui.css wins
10

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.

ElementDefault class
Buttonfluid-button
Canvasfluid-canvas
Containerfluid-container
Formfluid-form
Imagefluid-image
InputFieldfluid-input-field
Labelfluid-label
Linkfluid-link
Listfluid-unordered-list or fluid-ordered-list
Tablefluid-table, with fluid-table-head, fluid-table-body, fluid-table-row, fluid-table-cell, and fluid-table-footer
Textfluid-text
11

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.

Overrides Through Class svelte
<Button id="save-button" class="rounded-full">Save</Button>
12

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.

Overrides Through CSS css
/* every fluid-button in the application */
.fluid-button {
  border-radius: 999px;
}
 
/* every fluid-button inside one variant */
.faq-tight .fluid-button {
  padding: 0.25rem;
}
13

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.

Variants svelte
<Accordion id="faq" variant="faq-tight">
  {#snippet header()}Shipping{/snippet}
  {#snippet body()}Delivery takes three days.{/snippet}
</Accordion>
14

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.

Variant Rules css
/* src/styles.css, after the import of fluidui.css */
.faq-tight .fluid-accordion-header {
  padding: 0.25rem;
  font-size: 0.875rem;
}
15

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.

Dark Mode svelte
<!-- 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>
16

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.

Snippets for Custom Markup svelte
{#snippet anchor({ toggle })}
  <Button onclick={async () => toggle()}>Open</Button>
{/snippet}
{#snippet overlay({ close })}
  <Container>...</Container>
{/snippet}
17

Import Paths

Import components from the package in your application. The internal paths below are used inside the library's own source and documentation.

ContextImport PathExample
Library source#src/lib/base/index.tsimport { Button } from "#src/lib/base/index.ts"
Library source (components)#src/lib/components/index.tsimport { AnchoredOverlay } from "#src/lib/components/index.ts"
Your applicationfluid-ui-svelte/baseimport { Button } from 'fluid-ui-svelte/base'
Your application (components)fluid-ui-svelte/componentsimport { Modal } from 'fluid-ui-svelte/components'
Your application (prebuilt)fluid-ui-svelte/prebuiltimport { Breadcrumb } from 'fluid-ui-svelte/prebuilt'
18

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.

KindFileContains
.svelteComponent.svelteMarkup, with helpers imported from component.ts
.ts helpercomponent.tsPure functions that compute state and values
fluidui.cssfluidui.cssOne block per element, part, and variant
19

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.

Naming and Error Handling typescript
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"];
}