Fluid UI Svelte
A pragmatic Svelte 5 component library designed for flexibility and ease of use. It separates low-level semantic wrappers from high-level interactive components, giving you complete control over your application's architecture.
Scope
This document covers how a consumer installs, configures, and uses the fluid-ui-svelte package. It describes the three layers, their components, the global styling setup, and the rules that every usage follows.
It does not cover how to contribute to the repository. The development commands, test suites, and release process are described in the Development section and in tests/tests.md.
Architecture
The library is organized into three layers with strict boundaries. Each layer imports from the layers below it and never from the layers above it.
Base Layer
The base layer holds the fundamental, low-level semantic wrappers around native HTML elements. It reduces HTML tag fatigue, enforces semantic consistency and accessibility, and handles class deduplication, merging, and attribute sanitization.
Import path: fluid-ui-svelte/base
Components Layer
The components layer holds focused, cohesive functional primitives assembled strictly from base elements. These components are purely visual and interactive, and they contain no application business logic.
Import path: fluid-ui-svelte/components
Prebuilt Layer
The prebuilt layer holds turnkey domain workflows that compose the base and components layers. These components are ready for immediate application use.
Import path: fluid-ui-svelte/prebuilt
Design Pillars
Each component is built from three parts that stay separate.
- Reactive UI markup in
.sveltefiles defines what is rendered, the structure, the snippets, and the event binding. - Pure TypeScript logic in
.tshelper files defines state machines, calculations, and handlers. This logic is pure, immutable, and free of side effects. - Central styling defaults in
fluidui.cssdefine a dedicated class block for each element, so theming happens in one place.
Requirements
- Svelte 5 in Runes mode (
$state,$derived,$props,$bindable,$effect,Snippet). The peer dependency issvelte^5.0.0. - Tailwind CSS 4.
fluidui.cssuses Tailwind 4 syntax, and the application defines its colors in its own@themeblock.
Installation
Install the package
npm install fluid-ui-svelte
Configure global styles
Fluid UI does not inject styles automatically. This keeps library styling and application styling separate.
- Copy
node_modules/fluid-ui-svelte/src/fluidui.cssinto the root of your project. The copy belongs to your application, so you can edit it, and it does not update by itself. - Import it in your main CSS file, after Tailwind.
/* src/app.css */
@import "tailwindcss";
@import "./fluidui.css";
Usage
Import components from the layer that owns them. Svelte 5 in Runes mode is required.
<script>
import { Button } from "fluid-ui-svelte/base";
import { Accordion } from "fluid-ui-svelte/components";
import { Breadcrumb } from "fluid-ui-svelte/prebuilt";
</script>
<Button id="submit-button" onclick={async () => {}}>Submit</Button>
Usage Rules
- Every element requires an
idprop from the outside. - Component and prebuilt parts build their ids from the class name and the id: the root is
fluid-<component>-<id>and each part isfluid-<component>-<part>-<id>, for examplefluid-accordion-header-faq. - Snippets are preferred over configuration objects for custom markup.
- Base elements accept
class, which is added on top of the default. Components and prebuilt elements acceptvariant, a name the application chooses for the root element, and do not acceptclass.
Example: Drawer With Snippet Content
<Drawer id="my-drawer" bind:isOpen position="left">
<Container id="my-drawer-panel">...</Container>
</Drawer>
Component Reference
The table lists each layer, its import path, and its components. The documentation registry in src/documentation/documentation.ts holds the full description and props table of each component.
| Layer | Import path | Components |
|---|---|---|
| Base | fluid-ui-svelte/base |
Button, Canvas, Container, Form, Image, InputField, Label, Link, List, Table, Text |
| Components | fluid-ui-svelte/components |
Accordion, AnchoredOverlay, CalendarGrid, Carousel, CodeBlock, Draggable, Drawer, Dropzone, ImageCrop, Modal, Page, Pagination, Switch, TimePicker |
| Prebuilt | fluid-ui-svelte/prebuilt |
Breadcrumb, InternationalInput, NotificationArea, SearchableSelector |
Naming Conventions
- No shortened names. Use
button, notbtn, andconfiguration, notcfg. PascalCasefor Svelte components and type aliases.camelCasefor variables, functions, and helper files.kebab-casefor registry slugs.
Development
Run these commands from the repository root.
npm install
npm run dev
npm run build
npm run lint
npm run format
npm run check
npx playwright install chromium
npm run test:browser
npm run devstarts the documentation site.npm run buildbuilds the site and the library intodist/, then checks the package with publint.npm run lintruns oxlint with automatic fixes.npm run formatformats the source with oxfmt.npm run checkruns the Svelte and TypeScript checks.npm run test:browserruns the Playwright browser suites intests/browser/.
License
This project is licensed under the MIT License. See the LICENSE file for details.