Composables
Paragraph Element
Style paragraph elements with configurable top and bottom margins using the useParagraphElement composable.
Overview
The useParagraphElement composable styles p elements with configurable top and bottom margins. By default, it removes the top margin and sets the bottom margin to your base spacing token.
useParagraphElement
function useParagraphElement(
s: Styleframe,
options?: WithThemes<ParagraphElementConfig>
): ParagraphElementResult
styleframe.config.ts
import { styleframe } from 'styleframe';
import { useParagraphElement } from '@styleframe/theme';
const s = styleframe();
const { paragraphMarginTop, paragraphMarginBottom } = useParagraphElement(s);
export default s;
styleframe/index.css
:root {
--paragraph--margin-top: 0;
--paragraph--margin-bottom: var(--spacing);
}
p {
margin-top: var(--paragraph--margin-top);
margin-bottom: var(--paragraph--margin-bottom);
}
Default Values
| Option | Default | Variable | Export |
|---|---|---|---|
marginTop | "0" | --paragraph--margin-top | paragraphMarginTop |
marginBottom | "@spacing" | --paragraph--margin-bottom | paragraphMarginBottom |
Custom Values
styleframe.config.ts
import { styleframe } from 'styleframe';
import { useParagraphElement } from '@styleframe/theme';
const s = styleframe();
const { paragraphMarginBottom } = useParagraphElement(s, {
marginTop: '0',
marginBottom: '@spacing.lg',
});
export default s;
styleframe/index.css
:root {
--paragraph--margin-top: 0;
--paragraph--margin-bottom: var(--spacing--lg);
}
p {
margin-top: var(--paragraph--margin-top);
margin-bottom: var(--paragraph--margin-bottom);
}
Best Practices
- Zero the top margin: The default
marginTop: "0"follows the single-direction margin pattern, preventing margin collapse issues between adjacent elements. - Use spacing tokens: Reference
@spacingor@spacing.lgfor bottom margin to stay consistent with your layout system. - Keep paragraphs spaced apart: The bottom margin creates visual separation between paragraphs without requiring manual spacing.