Structure
Horizontal Rule Element
Style horizontal rule elements with configurable border color, width, style, and margin using the useHrElement composable.
Part of the Global Preset:
useHrElement is included in the Global Preset (useGlobalPreset) and you can configure it through the preset's hr option. For most projects, applying it via the preset is the recommended approach.Overview
The useHrElement composable styles the hr element as a top-border-only divider with configurable border properties and vertical margin. It zeroes out the right, bottom, and left borders for a clean single-line separator.
useHrElement
function useHrElement(
s: Styleframe,
options?: WithThemes<HrElementConfig>
): HrElementResult
styleframe.config.ts
import { styleframe } from 'styleframe';
import { useHrElement } from '@styleframe/theme';
const s = styleframe();
const {
hrBorderColor,
hrBorderWidth,
hrBorderStyle,
hrMargin,
} = useHrElement(s);
export default s;
styleframe/index.css
:root {
--hr--border-color: var(--color--gray-200);
--hr--border-width: var(--border-width);
--hr--border-style: solid;
--hr--margin: var(--spacing--lg);
}
hr {
border-top-width: var(--hr--border-width);
border-top-style: var(--hr--border-style);
border-top-color: var(--hr--border-color);
border-right-width: 0;
border-bottom-width: 0;
border-left-width: 0;
margin-top: var(--hr--margin);
margin-bottom: var(--hr--margin);
margin-left: 0;
margin-right: 0;
}
Default Values
| Option | Default | Variable | Export |
|---|---|---|---|
borderColor | "@color.gray-200" | --hr--border-color | hrBorderColor |
borderWidth | "@border-width" | --hr--border-width | hrBorderWidth |
borderStyle | "solid" | --hr--border-style | hrBorderStyle |
margin | "@spacing.lg" | --hr--margin | hrMargin |
The margin variable controls both margin-top and margin-bottom. Horizontal margins are fixed at 0.
Custom Values
styleframe.config.ts
import { styleframe } from 'styleframe';
import { useHrElement } from '@styleframe/theme';
const s = styleframe();
const { hrBorderColor, hrMargin } = useHrElement(s, {
borderColor: '@color.gray-300',
borderStyle: 'dashed',
margin: '@spacing.xl',
});
export default s;
styleframe.config.ts
import { styleframe } from 'styleframe';
import { useGlobalPreset } from '@styleframe/theme';
const s = styleframe();
const { hr } = useGlobalPreset(s, {
hr: {
borderColor: '@color.gray-300',
borderStyle: 'dashed',
margin: '@spacing.xl',
},
});
export default s;
styleframe/index.css
:root {
--hr--border-color: var(--color--gray-300);
--hr--border-width: var(--border-width);
--hr--border-style: dashed;
--hr--margin: var(--spacing--xl);
}
hr {
border-top-width: var(--hr--border-width);
border-top-style: var(--hr--border-style);
border-top-color: var(--hr--border-color);
border-right-width: 0;
border-bottom-width: 0;
border-left-width: 0;
margin-top: var(--hr--margin);
margin-bottom: var(--hr--margin);
margin-left: 0;
margin-right: 0;
}
Best Practices
- Use light border colors: The default
@color.gray-200provides a subtle divider that does not dominate the visual hierarchy. - Customize border color per-theme: Use theme overrides to adjust the border color for dark mode (e.g.,
@color.gray-700). - Use spacing tokens for margin: Reference
@spacing.lgor@spacing.xlto keep divider spacing consistent with your layout system.