# Design principles

Sections 1 to 13 cover engineering choices. This one names the design principles behind the look and the behavior,
and where each is applied. The principles are borrowed and linked. Only the "how we apply it" lines are ours.

## Composition

- **Hierarchy and scale.** One page title, then a small, fixed type scale, so size alone tells you what matters.
  Applied by the heading and UI text tokens (`--dui-font-size-page-title`, `--dui-font-size-ui`) in
  [Semantic tokens](https://domestic-ui.odonckers.dev/principles/theming.md#semantic-tokens-public-api).
- **Contrast.** Text, controls and focus rings meet the WCAG contrast minimums in light, dark and forced colors;
  the primary fill is the strongest mark on a page. See [§ 3](https://domestic-ui.odonckers.dev/principles/accessibility-baseline-wcag-22-aa.md)
  and [Color](https://domestic-ui.odonckers.dev/principles/theming.md#color).
- **Proximity and negative space.** Related things sit closer than unrelated ones, using the `--dui-space-*` scale
  and the [layout primitives](https://domestic-ui.odonckers.dev/principles/layout-primitives.md) (stack, cluster, grid), never one-off margins.
- **Alignment.** Every item sits on one of a container's named lines. See
  [§ 13 Edges and alignment](https://domestic-ui.odonckers.dev/principles/edges-and-alignment.md).
- **Repetition and consistency.** One element, one look, everywhere: a `<button>` is styled once in
  [button](https://domestic-ui.odonckers.dev/components/atoms/button.md) and reused, and the same control keeps the same name across pages
  ([WCAG 3.2.4](https://www.w3.org/WAI/WCAG22/Understanding/consistent-identification.html)).
- **Balance.** Surfaces are quiet and neutral so content and the one primary action carry the weight. Elevation
  separates layers rather than decorating them. See [§ 7 Elevation](https://domestic-ui.odonckers.dev/principles/elevation.md).

## Dieter Rams' principles for good design

Named from [Vitsœ's page on Dieter Rams' ten principles](https://www.vitsoe.com/us/about/good-design). How
domestic-ui applies nine of them:

- **Useful:** every component exists because a real view needs it. Nothing ships as a showcase.
- **Aesthetic:** the default theme looks finished with zero CSS written by the consumer ([§ 5](https://domestic-ui.odonckers.dev/principles/theming.md)).
- **Understandable:** the markup is the API. A native element looks and behaves like itself
  ([§ 1](https://domestic-ui.odonckers.dev/principles/native-element-first.md)).
- **Unobtrusive:** paper surfaces, brown ink and one accent leave room for the product's own content.
- **Honest:** a control never looks like something it is not. Links stay underlined, buttons look pressable
  ([§ 8](https://domestic-ui.odonckers.dev/principles/opinions-we-hold.md)).
- **Long-lasting:** we build on web standards, so the system ages with the platform rather than a framework.
- **Thorough down to the last detail:** focus, forced colors, reduced motion, right-to-left and 320px widths are
  part of every component, not follow-ups ([§ 3](https://domestic-ui.odonckers.dev/principles/accessibility-baseline-wcag-22-aa.md)).
- **Environmentally friendly.** **Our choice:** read as lightweight pages: system fonts by default, zero-build CSS and no
  runtime dependencies, so a page costs few bytes and no extra requests.
- **As little design as possible:** a few semantic tokens and no per-component knobs.

We leave out **Innovative**, because domestic-ui packages the platform and claims no originality.

## Laws of UX

From [Laws of UX](https://lawsofux.com/):

- [Jakob's Law](https://lawsofux.com/jakobs-law/): people expect a site to work like the ones they already know.
  Native elements keep the platform's own behavior ([§ 1](https://domestic-ui.odonckers.dev/principles/native-element-first.md)).
- [Hick's Law](https://lawsofux.com/hicks-law/): more choices take longer to decide. One primary action per view;
  everything else is secondary or quiet ([button](https://domestic-ui.odonckers.dev/components/atoms/button.md)).
- [Fitts's Law](https://lawsofux.com/fittss-law/): bigger, closer targets are faster to hit. Controls are 36px,
  44px under a coarse pointer, above [WCAG 2.5.8](https://www.w3.org/WAI/WCAG22/Understanding/target-size-minimum.html)'s
  24px minimum (`--dui-size-target`).
- [Miller's Law](https://lawsofux.com/millers-law/): people hold only a few items in mind at once. Long forms are
  grouped into fieldsets and sections ([large forms](https://domestic-ui.odonckers.dev/patterns/large-forms.md)), and navigation into
  groups ([nav](https://domestic-ui.odonckers.dev/patterns/nav.md)).
- [Aesthetic-Usability Effect](https://lawsofux.com/aesthetic-usability-effect/): people find good-looking interfaces
  easier to use. We polish the default look, but never at the cost of an accessibility requirement
  ([§ 3](https://domestic-ui.odonckers.dev/principles/accessibility-baseline-wcag-22-aa.md)).

## Rules of thumb

- **Reduce cognitive load.** Show one task at a time. Progressive disclosure with `<details>` and dialogs keeps
  secondary options out of the way ([disclosure](https://domestic-ui.odonckers.dev/patterns/disclosure.md)).
- **One primary action per view.** `type="submit"` gets the primary fill. A second primary on the same view points to a problem.
- **Intentional spacing.** Every gap comes from `--dui-space-*`. A value off the scale means the layout is wrong
  ([§ 13](https://domestic-ui.odonckers.dev/principles/edges-and-alignment.md)).
- **Compose before you create.** Most of what a design system calls a component is native elements put together
  well. Before adding a component class or a web component, try a canonical example: a snippet in `examples/` that
  combines existing elements (a card of a heading, text and actions; a settings form of fieldsets) and looks finished
  as written. Add a new component only when composition can't express it. The
  [decision ladder](https://github.com/odonckers/domestic-ui/blob/main/docs/ARCHITECTURE.md#3-the-decision-ladder) says what comes next.
- **Familiarity over novelty.** Use the pattern people already know, the native element or the
  [APG pattern](https://www.w3.org/WAI/ARIA/apg/patterns/), before inventing one.
