PlainSv

PlainSv is a collection of accessible Svelte 5 components that follow the shadcn design, written the Svelte way. Each component keeps its state in runes, its styles in a scoped <style> block, and builds on native elements such as dialog where the browser already does the work, with no Tailwind, no PostCSS setup, and no headless UI library underneath. Alongside the components, PlainSv ships utilities for the rest of a Svelte app, such as CSS effects, typed server functions, and Vite plugins for Markdown pages and icon imports. PlainSv is not a package you install from npm: each item's source is copied into your project with the remote0 CLI, so you own the code and can change anything you need.

Create a project

To get started with PlainSv, create a TypeScript SvelteKit project with the sv CLI. Replace project-name with the name of your project, and pick the adapter for the host you deploy to when sv asks, such as node, vercel, cloudflare, or static.

pnx sv@latest create project-name

Optionally, delete the default files and folders that PlainSv does not use.

Terminal
rm src/lib/index.ts && rm -rf src/lib/assets

Add init

Inside the new project, add the init item.

pnx remote0 add https://plainsv.com/r/init.json

The init item adds the PlainSv core files and installs their packages:

  • Add the theme, resets, CSS utilities, and typeset styles in src/styles
  • Replace src/app.d.ts with the global types that components use
  • Add the app context in src/lib/context/app.svelte.ts and the app data in src/lib/data/app.ts
  • Add the Logo and PageMeta components in src/lib/components/shared
  • Replace vite.config.ts with a config that registers the dev and svx plugins and compiles .svx pages
  • Replace src/routes/+layout.svelte with a root layout that imports the styles, creates the app context, and renders toasts
  • Add src/routes/+layout.server.ts, which passes the theme and device to the app context
  • Add src/hooks.server.ts, which sets dark mode on the server so pages never flash light
  • Add the favicon, icons, Open Graph image, manifest.json, and robots.txt in static
  • Add .env and .env.production with DOMAIN_URL
  • Add .vscode/settings.json, which sorts the VS Code explorer by file type so each component's .svelte parts sit together, apart from its .ts files
  • Add the toaster component and the dev-plugin and svx-plugin-simple Vite plugins

Since init replaces src/app.d.ts, vite.config.ts, and src/routes/+layout.svelte, remote0 asks before it overwrites them. Copy anything you added to those files back in afterward, and see the adapter notes below.

Vite config

There is nothing to set up here, since init writes vite.config.ts with the dev and svx plugins already registered and .svx pages enabled. Update it only if your project needs something different. It uses adapter-node, so if sv picked another adapter, change the adapter import to the one sv installed, such as @sveltejs/adapter-vercel. You can also add your own plugins or compiler options. This is the file init writes.

vite.config.ts
import adapter from "@sveltejs/adapter-node";
import devPlugin from "#lib/server/plugins/dev/index.js";
import svxPlugin from "#lib/server/plugins/svx/index.js";
import { sveltekit } from "@sveltejs/kit/vite";
import { defineConfig } from "vite";

export default defineConfig(() => {
	return {
		plugins: [
			devPlugin(),
			svxPlugin(),
			sveltekit({
				adapter: adapter(),
				extensions: [".svelte", ".svx"],
				compilerOptions: {
					// Force runes mode for the project, except for libraries. Can be removed in svelte 6.
					runes: ({ filename }) => (filename.split(/[/\\]/).includes("node_modules") ? undefined : true),
					// Allow reading props once, such as `setAppCtx(data)` in the root layout
					warningFilter: (warning) => (warning.code === "state_referenced_locally" ? false : true),
				},
			}),
		],
	};
});

Scripts recommendation

When using the node adapter on Node 26 or later, we recommend this setup. --env-file-if-exists loads .env natively without a package, and the preview script also loads .env.production.

It also runs the dev and preview servers through portless, which gives each one a stable named URL such as https://project-name.localhost instead of a port number you have to remember. portless assigns a free port through $PORT, which the scripts pass to Vite with --strictPort, and the .prod suffix gives the preview server its own URL so it can run beside the dev server. Replace project-name with your project's name.

pn add -g portless

Set the scripts as follows.

package.json
{
	"vite:dev": "node --env-file-if-exists=.env ./node_modules/vite/bin/vite.js",
	"build": "node --env-file-if-exists=.env ./node_modules/vite/bin/vite.js build",
	"vite:preview": "node --env-file-if-exists=.env --env-file-if-exists=.env.production ./node_modules/vite/bin/vite.js preview",
	"dev": "portless project-name sh -c 'pnpm vite:dev --port $PORT --strictPort --host ${HOST:-127.0.0.1}'",
	"preview": "portless project-name.prod sh -c 'pnpm vite:preview --port $PORT --strictPort --host ${HOST:-127.0.0.1}'",
	"prepare": "svelte-kit sync || echo ''",
	"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
	"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
}

Root layout and dark mode

The root layout imports app.css once so every page has the theme tokens, creates the app context from the layout data, and renders the toasts. Components render without color, spacing, or radius until these styles load. Render PageMeta in each page to set its title, description, and Open Graph tags.

src/routes/+page.svelte
<script lang="ts">
	import { PageMeta } from "#lib/components/shared/index.js";
	import { useAppCtx } from "#lib/context/app.svelte.js";

	const app = useAppCtx();
</script>

<PageMeta title="Home" />

<button onclick={() => app.toggleDarkMode()}>Toggle theme</button>

The app context saves the theme in a theme cookie. src/hooks.server.ts reads the cookie and adds the dark class to body before the page is sent, and src/routes/+layout.server.ts passes it to the app context with isMobile and userData.

Adapter notes

The src/app.d.ts that init writes works with the auto, node, bun, vercel, and static adapters. A few adapters need one more step.

For Cloudflare, init replaces the App.Platform types that sv added, so add them back inside namespace App in src/app.d.ts, then run npx wrangler types to generate the Env type in worker-configuration.d.ts.

src/app.d.ts
declare global {
	namespace App {
		// Cloudflare bindings, request context, and cache, typed by `wrangler types`
		interface Platform {
			env: Env;
			ctx: ExecutionContext;
			caches: CacheStorage;
			cf?: IncomingRequestCfProperties;
		}
	}
}

For a static site, set prerender to true in src/routes/+layout.server.ts. Prerendered pages are built once, so the hook cannot read the theme cookie, and dark mode applies after the page loads.

For Bun, add bunfig.toml so package scripts such as vite build run on the Bun runtime, which adapter-bun requires.

bunfig.toml
[run]
bun = true

Run the app

Start the dev server, then open http://localhost:5173.

pn run dev

Make it yours

The init item ships with placeholder content. Replace it with your own before you deploy.

Update src/lib/data/app.ts with your app's name, title, and description. The page meta reads these values. Update the same name and description in static/manifest.json for the web app manifest, and the name field in package.json.

src/lib/data/app.ts
/** App core data */
export const appData = {
	name: "Acme",
	title: "Acme, the app that does it all",
	description: "A short sentence that describes your app.",
};

Replace the images in static/images with your own and keep the same file names: favicon.svg, apple-icon.png, manifest-192.png, manifest-512.png, and og.png. The page meta uses the favicon, the Apple icon, and the Open Graph image, and the web app manifest uses the two manifest icons. Then swap the SVG in src/lib/components/shared/logo.svelte for your own logo.

Set DOMAIN_URL in .env.production to the URL where your app will run. The .env file keeps http://localhost:3000 for local development. A server build will not start without DOMAIN_URL, so also set it as an environment variable on your host, or under vars in wrangler.jsonc for Cloudflare.

.env.production
DOMAIN_URL="https://acme.com"

Installation

Add a component with the remote0 CLI and its registry URL. The source files are copied into your project at the same paths they have here.

pnx remote0 add https://plainsv.com/r/button.json

Replace button with the component name, which matches the last part of its docs URL, such as card or dropdown-menu. Components that build on other components install those too. Components expect the global types and the styles, which the init item installs, so add init before your first component.

Theme

Components read their colors, radii, spacing, and font sizes from the CSS variables in src/styles/theme.css, which the init item installs. The global src/styles/app.css imports the theme, the CSS utilities, and the typeset styles, and the root layout imports app.css once so every page has the tokens.

src/styles/app.css
@import "./theme.css";
@import "./utils.css";
@import "./typeset.css";

The theme defines a light palette on :root and a dark palette that applies when the dark class is set. Override any token to restyle every component at once.

src/styles/theme.css
:root {
	--radius: 0.625rem;
	--primary: oklch(0.205 0 0);
	--primary-foreground: oklch(0.985 0 0);
}

CSS utilities

A few components, such as ai-action and prompt-input, use the shimmer and scroll-fade classes from src/styles/utils.css. The init item installs the file, and app.css imports it after the theme so the classes work on every page.

+page.svelte
<span class="shimmer">Generating response...</span>

<ul class="list scroll-fade-y">
	<!-- Long list -->
</ul>

Read more about the classes and their variables on the CSS utilities page.

Global types

Components share the UiSize and UiRounded types, the Snippet and Component types, and the CompProps helpers that type props from an HTML element. The init item declares them globally in src/app.d.ts, so components can use them without imports.

src/app.d.ts
import type { Snippet as SvSnippet, Component as SvComponent, ComponentProps as SvComponentProps } from "svelte";
import type { SvelteHTMLElements } from "svelte/elements";

declare global {
	type Snippet<T extends unknown[] = []> = SvSnippet<T>;
	type Component = SvComponent;
	type ComponentProps<T> = SvComponentProps<T>;
	type CompAttrs<TagName extends keyof HTMLElementTagNameMap> = Omit<SvelteHTMLElements[TagName], `on${string}` | `bind:${string}` | "children">;
	type CompEvents<TagName extends keyof HTMLElementTagNameMap> = { [K in keyof HTMLElementTagNameMap[TagName] as K extends `on${string}` ? K : never]?: (e: any) => any };
	type CompProps<TagName extends keyof HTMLElementTagNameMap> = CompAttrs<TagName> & CompEvents<TagName>;
	type CompPropsWithChild<TagName extends keyof HTMLElementTagNameMap> = CompProps<TagName> & { children: SvSnippet };
	type CompPropsWithChildSimple<ExtraT> = { children: SvSnippet } & ExtraT;
	type UiSize = "xs" | "sm" | "md" | "lg";
	type UiRounded = "xs" | "sm" | "md" | "lg" | "xl" | "2xl" | "3xl" | "4xl" | "pill";
}

export {};

Using a component

Each component lives in its own folder with a _.svelte file and an index.ts file that exports the component and its props type. Import components from the folder's index.js.

+page.svelte
<script lang="ts">
	import { Button } from "#lib/components/ui/button/index.js";
</script>

<Button>Sign in</Button>

Sizes and corners

Sized components accept size and rounded props. When rounded is omitted, the corner radius follows the size.

+page.svelte
<Button size="sm">Small</Button>
<Button size="lg" rounded="pill">Large pill</Button>

Variants

Components that have visual styles accept a variant prop with the shadcn names default, secondary, outline, ghost, destructive, and link.

+page.svelte
<Button variant="outline">Cancel</Button>
<Button variant="destructive">Delete</Button>

Styling

Components pass extra attributes through to the root element, so the recommended way to override one is the style attribute. They also render their props as data-variant, data-size, and data-rounded attributes on the root element.

+page.svelte
<Button style="margin-top: 1rem">Save</Button>

Read more about inline styles, theme tokens, other ways to override, and new variants on the styling page.

Server functions

Add type-safe server functions with the functions item. Define a function's input and output with Zod in src/lib/functions/schemas.ts, export a handler with the same name from src/lib/functions/handlers, and call it from the client with useFunc.

pnx remote0 add https://plainsv.com/r/functions.json
+page.svelte
<script lang="ts">
	import { useFunc } from "#lib/functions/index.js";

	const response = await useFunc("userCreate", { email: "[email protected]" });
</script>

Read more about validation, private functions, uploads, and streaming on the functions page. The utilities page also covers the Vite plugins that compile .svx pages and speed up icon imports.

Browse components

Browse every component and its demos on the components page, and see them working together in full-screen apps on the examples page.

For LLMs

Every component page is also available as plain Markdown by adding .md to its URL, such as /docs/components/button.md. The llms.txt file lists them all.