# Building applications with Focus UI

Use Focus UI when you want a compact, familiar interface in plain HTML or a framework application. A small admin panel, project tracker, or client portal is a suitable first use case. Start with a real workflow: list records → filter → edit → confirm → show success/error feedback.

## Load the library

For new installs, follow the CDN assets section of the [agent index](https://focus-ui.de/llms.txt) or self-host the selected release. This example is pinned and verified for v2.2.0.

```html
<link rel="stylesheet" href="https://cdn.focus-ui.de/v2.2.0/focus-ui.css"
  integrity="sha384-iz2loH2fX1Pdfi76LeGHJMB2ccX7qDN5tLT4V5zCrSyRZU5kHPbnbw8HkFHELeet" crossorigin="anonymous">
<script defer src="https://cdn.focus-ui.de/v2.2.0/focus-ui.min.js"
  integrity="sha384-X/B/o6M0YdU/ae/s9Jdw91FeT4pVT/F2CV1Ab4hWsZ5A6YzfgzHX8vRMVpleBYru" crossorigin="anonymous"></script>
```

Load application JavaScript after the library (a following deferred script works). With self-hosted ESM, use named exports from your local `focus-ui.esm.js`. The runtime requires a browser DOM; initialize it on the client in SSR applications. No npm package, default npm import, or React/Vue component wrapper is promised.

## Compose a page

Use a container, responsive row/columns, and card sections. Existing layout classes include `focus-row`, `focus-col-12`, `focus-col-md-6`, `focus-d-flex`, and `focus-gap-4`. Do not invent `focus-grid-cols-2` or unprefixed Bootstrap utilities.

```html
<main class="focus-container focus-p-4">
  <h1>Projects</h1>
  <div class="focus-row">
    <section class="focus-col-12 focus-col-md-6">
      <div class="focus-card">
        <header class="focus-card-header">
          <h2 class="focus-card-title">Active projects</h2>
        </header>
        <div class="focus-card-body">Your project list</div>
        <footer class="focus-card-footer">
          <button type="button" class="focus-btn focus-btn-primary">New project</button>
        </footer>
      </div>
    </section>
  </div>
</main>
```

Cards already have padding and a hover effect; check their behavior before adding wrappers or extra padding. Use `focus-table` for tabular information and real form controls for editing. Interactive helpers do not replace application state, persistence, or server validation.

## Preserve the style

Use blue primary buttons for the principal action, secondary buttons for alternatives, and danger only for destructive actions. Keep neutral surfaces and use semantic alerts/toasts for feedback. Use existing spacing utilities and token values; keep dense screens readable with clear headings and one principal action per section.

The default typeface is Source Sans Pro with system fallbacks. Load a font yourself if needed. Icons in several components/examples use Font Awesome; it is not bundled. Provide it separately or use options such as `icon: false` for Toast. Do not rely on icons alone to explain an action.

For theme selection use `FocusUI.Theme.set('light' | 'dark' | 'auto')`. The root attribute is `data-focus-theme`, not `data-theme`; auto removes it and follows the OS. Theme changes use localStorage. If overriding colors, override related hover/background/border/text tokens and test both themes.

```css
/* Load application overrides after Focus UI. */
:root {
  --focus-font-family: system-ui, sans-serif;
  --focus-radius-md: 0.5rem;
}
```

## Interactions and accessibility

The browser bundle initializes supported data attributes on DOM ready. After adding markup dynamically, call `FocusUI.init()`; Searchbar, Tables, and TOC have separate initialization APIs. Prefer direct component methods with framework event handlers so the framework owns the element lifecycle. Never combine an inline handler and data attribute for the same action.

Use `Modal.confirm()` for simple confirmations and handle cancellation:

```js
try {
  await FocusUI.Modal.confirm({
    title: 'Archive project?',
    message: 'You can restore it later.',
    confirmText: 'Archive'
  })
  // Persist the change here, then report the actual result.
  FocusUI.Toast.show({ type: 'success', message: 'Project archived', icon: false })
} catch {
  // User cancelled (or the operation failed; distinguish this in application code).
}
```

Supply meaningful labels, visible focus, native button types, and heading hierarchy. CSS-only styling does not implement focus trapping, menu navigation, or dialogs. Check keyboard access and contrast in your actual application; the kit's tests do not certify your screen. Test narrow layouts and reduced motion. Keep messages as plain text and use server validation for submitted data.

## Reference order

1. [API.md](https://focus-ui.de/ai/API.md): exact signatures and options.
2. [COMPONENTS.md](https://focus-ui.de/ai/COMPONENTS.md): required markup structure.
3. [STYLING.md](https://focus-ui.de/ai/STYLING.md): available classes and token families.
4. [RECIPES.md](https://focus-ui.de/ai/RECIPES.md): composition ideas; verify them against the current API.
5. [FRAMEWORKS.md](https://focus-ui.de/ai/FRAMEWORKS.md): client integration sketches.

When documentation disagrees, inspect `src/lib/` in the source repository. Generated docs templates at `layout/templates/` are useful starting points, but application-specific logic belongs in your project.
