Components
A number of built-in UI components are available for layouts, grids, buttons, form elements, and more. Components can be used as an alternative to the JSX pragma for using Theme UI features, or in parallel to provide specific UI components.
Variants
Theme UI components can be customized by adding styles to your theme.
Each component accepts a variant
prop to quickly
change custom stylistic variations that you define.
{// ...base theme...// After the base theme, define the variants:buttons: {secondary: {fontWeight: 'bold',color: 'white',bg: 'primary','&:hover': {bg: 'dark',},},},text: {caps: {textTransform: 'uppercase',letterSpacing: '.2em',},heading: {fontFamily: 'heading',fontWeight: 'heading',lineHeight: 'heading',},display: {// extends the text.heading stylesvariant: 'text.heading',fontSize: [6, 7, 8],fontWeight: 'display',},},cards: {primary: {padding: 2,borderRadius: 4,boxShadow: '0 0 4px 1px rgba(0, 0, 0, 0.5)',},},}
Props
All Theme UI components include the following props.
Name | Type | Description |
---|---|---|
sx | Object | Theme-aware styles |
variant | String | Applies a theme variant style |
as | String | Changes the underlying HTML element |
Style Props
Each Theme UI component includes shorthand props for applying margin, padding, and color styles.
These props work the same as properties within the sx
prop, but allow for a more terse syntax for readability.
Name | Description |
---|---|
color | Foreground color |
bg | Background color |
margin , m | Margin |
marginTop , mt | Margin Top |
marginRight , mr | Margin Right |
marginBottom , mb | Margin Bottom |
marginLeft , ml | Margin Left |
marginX , mx | Margin Left & Right |
marginY , my | Margin Top & Bottom |
padding , p | Padding |
paddingTop , pt | Padding Top |
paddingRight , pr | Padding Right |
paddingBottom , pb | Padding Bottom |
paddingLeft , pl | Padding Left |
paddingX , px | Padding Left & Right |
paddingY , py | Padding Top & Bottom |