Composables
Headings Element
Style heading elements h1 through h6 with configurable font family, weight, line height, color, and per-level sizes using the useHeadingElement composable.
Overview
The useHeadingElement composable styles all heading levels (h1 through h6) with shared typography properties and individual font sizes per level. It creates CSS variables for the font family, weight, line height, color, and each heading level's size.
useHeadingElement
function useHeadingElement(
s: Styleframe,
options?: WithThemes<HeadingElementConfig>
): HeadingElementResult
styleframe.config.ts
import { styleframe } from 'styleframe';
import { useHeadingElement } from '@styleframe/theme';
const s = styleframe();
const {
headingColor,
headingFontFamily,
headingFontWeight,
headingLineHeight,
headingH1FontSize,
headingH2FontSize,
headingH3FontSize,
headingH4FontSize,
headingH5FontSize,
headingH6FontSize,
} = useHeadingElement(s);
export default s;
styleframe/index.css
:root {
--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--font-size: var(--font-size--3xl);
--heading--h3--font-size: var(--font-size--2xl);
--heading--h4--font-size: var(--font-size--xl);
--heading--h5--font-size: var(--font-size--lg);
--heading--h6--font-size: var(--font-size--md);
}
h1, h2, h3, h4, h5, h6 {
font-family: var(--heading--font-family);
font-weight: var(--heading--font-weight);
line-height: var(--heading--line-height);
color: var(--heading--color);
}
h1 { font-size: var(--heading--h1--font-size); }
h2 { font-size: var(--heading--h2--font-size); }
h3 { font-size: var(--heading--h3--font-size); }
h4 { font-size: var(--heading--h4--font-size); }
h5 { font-size: var(--heading--h5--font-size); }
h6 { font-size: var(--heading--h6--font-size); }
Default Values
Shared Properties
| Option | Default | Variable | Export |
|---|---|---|---|
color | "inherit" | --heading--color | headingColor |
fontFamily | "inherit" | --heading--font-family | headingFontFamily |
fontWeight | "@font-weight.bold" | --heading--font-weight | headingFontWeight |
lineHeight | "@line-height.tight" | --heading--line-height | headingLineHeight |
Heading Sizes
| Level | Default | Variable | Export |
|---|---|---|---|
h1 | "@font-size.4xl" | --heading--h1--font-size | headingH1FontSize |
h2 | "@font-size.3xl" | --heading--h2--font-size | headingH2FontSize |
h3 | "@font-size.2xl" | --heading--h3--font-size | headingH3FontSize |
h4 | "@font-size.xl" | --heading--h4--font-size | headingH4FontSize |
h5 | "@font-size.lg" | --heading--h5--font-size | headingH5FontSize |
h6 | "@font-size.md" | --heading--h6--font-size | headingH6FontSize |
The default size configuration is also available as a standalone export: defaultHeadingSizeConfig.
Custom Values
styleframe.config.ts
import { styleframe } from 'styleframe';
import { useHeadingElement } from '@styleframe/theme';
const s = styleframe();
const { headingH1FontSize, headingH2FontSize } = useHeadingElement(s, {
fontFamily: '"Playfair Display", serif',
fontWeight: '700',
lineHeight: '1.3',
sizes: {
h1: '3rem',
h2: '2.25rem',
},
});
export default s;
styleframe/index.css
:root {
--heading--color: inherit;
--heading--font-family: "Playfair Display", serif;
--heading--font-weight: 700;
--heading--line-height: 1.3;
--heading--h1--font-size: 3rem;
--heading--h2--font-size: 2.25rem;
--heading--h3--font-size: var(--font-size--2xl);
--heading--h4--font-size: var(--font-size--xl);
--heading--h5--font-size: var(--font-size--lg);
--heading--h6--font-size: var(--font-size--md);
}
h1, h2, h3, h4, h5, h6 {
font-family: var(--heading--font-family);
font-weight: var(--heading--font-weight);
line-height: var(--heading--line-height);
color: var(--heading--color);
}
h1 { font-size: var(--heading--h1--font-size); }
h2 { font-size: var(--heading--h2--font-size); }
h3 { font-size: var(--heading--h3--font-size); }
h4 { font-size: var(--heading--h4--font-size); }
h5 { font-size: var(--heading--h5--font-size); }
h6 { font-size: var(--heading--h6--font-size); }
The sizes option is partially applied — only the levels you specify are overridden. Unspecified levels keep their defaults from defaultHeadingSizeConfig.
Best Practices
- Reference font-size tokens: Use
@font-size.4xlthrough@font-size.mdto keep heading sizes consistent with your type scale. - Use a tight line height: The default
@line-height.tight(1.2) keeps headings compact. Increase it for long, multi-line headings. - Override only the sizes you need: The
sizesoption merges with defaults, so you only need to specify the levels you want to change. - Inherit color by default: Using
"inherit"for color lets headings match their parent context without additional overrides.