Elements Preset
Overview
The useGlobalPreset composable applies base styles to all common HTML elements in a single function call. It registers CSS custom properties for body, headings, links, paragraphs, lists, code blocks, and more — with sensible defaults that reference your design token system.
Why use the preset?
- Quick start: Style every HTML element with one function call
- Sensible defaults: All values reference standard design tokens (
@color.primary,@spacing,@font-family, etc.) - Fully customizable: Override any element's config or disable elements entirely
- Theme-aware: Supports centralized per-theme overrides for dark mode or brand themes
- Incremental adoption: Disable individual elements with
falseand replace them with custom composable calls
Quick Start
import { styleframe } from 'styleframe';
import { useGlobalPreset } from '@styleframe/theme';
const s = styleframe();
const { body, heading, link } = useGlobalPreset(s);
export default s;
:root {
--body--color: var(--color--text);
--body--background: var(--color--background);
--body--font-family: var(--font-family);
--body--font-size: var(--font-size);
--body--line-height: var(--line-height);
--heading--color: inherit;
--heading--font-family: inherit;
--heading--font-weight: var(--font-weight--bold);
--heading--line-height: var(--line-height--tight);
--heading--h1--font-size: var(--font-size--4xl);
/* ... heading h2-h6 sizes ... */
--link--color: var(--color--primary);
--link--text-decoration: none;
--link--hover--color: var(--color--primary-700);
--link--hover--text-decoration: underline;
/* ... all other element variables ... */
}
body {
font-family: var(--body--font-family);
font-size: var(--body--font-size);
line-height: var(--body--line-height);
color: var(--body--color);
background: var(--body--background);
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
h1, h2, h3, h4, h5, h6 { /* ... */ }
a { /* ... */ }
p { /* ... */ }
/* ... all other element selectors ... */
useGlobalPreset
Signature
function useGlobalPreset(
s: Styleframe,
config?: GlobalPresetConfig
): GlobalPresetResult
Configuration Options
Each element can be configured as:
- Omitted/
undefined(default): Use the element's default values false: Skip this element entirely (no variables or selectors registered)WithThemes<Config>: Use custom values with optional per-theme overrides
| Option | Type | Default | Description |
|---|---|---|---|
body | WithThemes<BodyElementConfig> | false | Enabled | Body color, background, font family, size, line height |
heading | WithThemes<HeadingElementConfig> | false | Enabled | Heading font family, weight, line height, per-level sizes |
paragraph | WithThemes<ParagraphElementConfig> | false | Enabled | Paragraph top/bottom margins |
link | WithThemes<LinkElementConfig> | false | Enabled | Link color, decoration, hover states |
ol | WithThemes<OlElementConfig> | false | Enabled | Ordered list margin and padding |
ul | WithThemes<UlElementConfig> | false | Enabled | Unordered list margin and padding |
dl | WithThemes<DlElementConfig> | false | Enabled | Definition list bottom margin |
dt | WithThemes<DtElementConfig> | false | Enabled | Definition term font weight |
dd | WithThemes<DdElementConfig> | false | Enabled | Definition description margins |
code | WithThemes<CodeElementConfig> | false | Enabled | Code font family and size |
pre | WithThemes<PreElementConfig> | false | Enabled | Pre font family, size, bottom margin |
kbd | WithThemes<KbdElementConfig> | false | Enabled | Keyboard input background, color, font, padding |
samp | WithThemes<SampElementConfig> | false | Enabled | Sample output font family |
abbr | WithThemes<AbbrElementConfig> | false | Enabled | Abbreviation cursor and text decoration |
mark | WithThemes<MarkElementConfig> | false | Enabled | Mark background, color, padding |
hr | WithThemes<HrElementConfig> | false | Enabled | Horizontal rule border and margin |
caption | WithThemes<CaptionElementConfig> | false | Enabled | Table caption color, padding, text alignment |
address | WithThemes<AddressElementConfig> | false | Enabled | Address bottom margin |
selection | WithThemes<SelectionStateConfig> | false | Enabled | Text selection background and color |
focus | WithThemes<FocusStateConfig> | false | Enabled | Focus-visible outline styles |
img | boolean | true | Image and SVG vertical alignment |
iframe | boolean | true | Iframe border removal |
output | boolean | true | Output display mode |
legend | boolean | true | Legend form layout |
summary | boolean | true | Summary cursor style |
themes | Record<string, GlobalThemeOverrides> | — | Centralized per-theme overrides for all elements |
Return Value
The useGlobalPreset function returns a GlobalPresetResult object containing the result of each enabled element composable:
const {
body, // BodyElementResult
heading, // HeadingElementResult
link, // LinkElementResult
paragraph, // ParagraphElementResult
code, // CodeElementResult
selection, // SelectionStateResult
focus, // FocusStateResult
// ... all other element results
} = useGlobalPreset(s);
Each result contains the CSS variable tokens for that element. For example, body.bodyColor is a Variable<"body.color"> that you can use with ref().
Examples
Customizing Individual Elements
import { styleframe } from 'styleframe';
import { useGlobalPreset } from '@styleframe/theme';
const s = styleframe();
const { body, heading, link } = useGlobalPreset(s, {
body: {
color: '#333333',
background: '#ffffff',
fontFamily: '"Inter", sans-serif',
},
heading: {
fontWeight: '600',
sizes: {
h1: '2.5rem',
h2: '2rem',
},
},
link: {
color: '@color.info',
hoverColor: '@color.info-700',
},
});
export default s;
:root {
--body--color: #333333;
--body--background: #ffffff;
--body--font-family: "Inter", sans-serif;
--body--font-size: var(--font-size);
--body--line-height: var(--line-height);
--heading--font-weight: 600;
--heading--h1--font-size: 2.5rem;
--heading--h2--font-size: 2rem;
--link--color: var(--color--info);
--link--hover--color: var(--color--info-700);
/* ... */
}
Disabling Specific Elements
import { styleframe } from 'styleframe';
import { useGlobalPreset } from '@styleframe/theme';
const s = styleframe();
// Only apply body, headings, and links — skip everything else
const { body, heading, link } = useGlobalPreset(s, {
paragraph: false,
ol: false,
ul: false,
dl: false,
dt: false,
dd: false,
code: false,
pre: false,
kbd: false,
samp: false,
abbr: false,
mark: false,
hr: false,
caption: false,
address: false,
focus: false,
selection: false,
img: false,
iframe: false,
output: false,
legend: false,
summary: false,
});
export default s;
Centralized Theme Overrides
The themes option lets you define per-theme overrides for multiple elements in one place:
import { styleframe } from 'styleframe';
import { useGlobalPreset } from '@styleframe/theme';
const s = styleframe();
useGlobalPreset(s, {
themes: {
dark: {
body: {
color: '#e2e8f0',
background: '#0f172a',
},
heading: {
color: '#f1f5f9',
},
link: {
color: '@color.primary-300',
hoverColor: '@color.primary-200',
},
hr: {
borderColor: '@color.gray-700',
},
},
},
});
export default s;
:root {
--body--color: var(--color--text);
--body--background: var(--color--background);
--heading--color: inherit;
--link--color: var(--color--primary);
--hr--border-color: var(--color--gray-200);
/* ... */
}
[data-theme="dark"] {
--body--color: #e2e8f0;
--body--background: #0f172a;
--heading--color: #f1f5f9;
--link--color: var(--color--primary-300);
--link--hover--color: var(--color--primary-200);
--hr--border-color: var(--color--gray-700);
}
Per-Element vs. Centralized Themes
You can define theme overrides both on individual elements and in the centralized themes map. When both exist, they are merged — centralized themes take precedence:
import { styleframe } from 'styleframe';
import { useGlobalPreset } from '@styleframe/theme';
const s = styleframe();
useGlobalPreset(s, {
// Per-element theme override
body: {
color: '@color.text',
themes: {
dark: {
color: '#cccccc',
},
},
},
// Centralized theme override — takes precedence
themes: {
dark: {
body: {
color: '#e2e8f0', // This value wins
},
},
},
});
export default s;
Importing Default Values
You can import the default options for any element to reference or extend them:
import {
defaultBodyOptions,
defaultHeadingOptions,
defaultHeadingSizeConfig,
defaultLinkOptions,
defaultCodeOptions,
defaultPreOptions,
defaultHrOptions,
defaultKbdOptions,
defaultMarkOptions,
defaultCaptionOptions,
defaultAbbrOptions,
defaultAddressOptions,
defaultDlOptions,
defaultDtOptions,
defaultDdOptions,
defaultOlOptions,
defaultUlOptions,
defaultParagraphOptions,
defaultSampOptions,
defaultFocusOptions,
defaultSelectionOptions,
} from '@styleframe/theme';
Best Practices
- Start with defaults: Call
useGlobalPreset(s)with no config to get a complete set of element styles - Disable rather than override: Use
element: falseto skip elements you don't need, instead of overriding everything to empty values - Prefer centralized themes: Use the
themesoption to define dark mode overrides in one place rather than spreading them across individual element configs - Reference design tokens: Use
@references (e.g.,@color.primary,@spacing.lg) to keep element styles in sync with your token system - Use the return value: Destructure the returned variables to reference them elsewhere with
ref()
FAQ
Yes. You can disable specific elements in the preset and use individual composables instead:
const preset = useGlobalPreset(s, { link: false });
const { linkColor } = useLinkElement(s, { color: '@color.info' });
@color.text, @color.background, @color.primary, @font-family, @font-size, @line-height, @spacing, @font-weight.bold, and others. These are typically created by useDesignTokensPreset.img, iframe, output, legend, and summary apply fixed styles and are controlled by a boolean flag (true/false). They do not create CSS custom properties or appear in the return value.The preset supports two levels of theme configuration:
- Per-element themes: Defined directly on each element's config (e.g.,
body: { themes: { dark: { ... } } }) - Centralized themes: Defined on the preset config (e.g.,
themes: { dark: { body: { ... } } })
When both exist for the same element and theme, they are merged with centralized themes taking precedence. This lets you keep per-element defaults while overriding specific properties centrally.