You are looking at the documentation of the work in progress Hope UI 1.0, examples and information may be broken or outdated.

Styles

Style props

Define a component's style simply by passing props.

Reference table

The following table shows all available style props and the CSS properties they map to.

Margin and padding

tsx
import { Box } from "@hope-ui/core";
// refers to the value of `theme.vars.space["2"]`
<Box m={2}>Tomato</Box>
// you can also use custom values
<Box maxW="960px" mx="auto" />
// applies an `8px`` margin to all viewports and a `12px` margin from the first breakpoint upwards.
<Box m={[2, 3]} />
tsx
import { Box } from "@hope-ui/core";
// refers to the value of `theme.vars.space["2"]`
<Box m={2}>Tomato</Box>
// you can also use custom values
<Box maxW="960px" mx="auto" />
// applies an `8px`` margin to all viewports and a `12px` margin from the first breakpoint upwards.
<Box m={[2, 3]} />
PropCSS PropertyTheme scale
m, marginmarginspace
mt, marginTopmargin-topspace
mr, marginRightmargin-rightspace
me, marginEndmargin-inline-endspace
mb, marginBottommargin-bottomspace
ml, marginLeftmargin-leftspace
ms, marginStartmargin-inline-startspace
mx, marginXmargin-inline-start + margin-inline-endspace
my, marginYmargin-top + margin-bottomspace
p, paddingpaddingspace
pt, paddingToppadding-topspace
pr, paddingRightpadding-rightspace
pe, paddingEndpadding-inline-endspace
pb, paddingBottompadding-bottomspace
pl, paddingLeftpadding-leftspace
ps, paddingStartpadding-inline-startspace
px, paddingXpadding-inline-start + padding-inline-endspace
py, paddingYpadding-top + padding-bottomspace

Color

tsx
import { Box } from "@hope-ui/core";
// refers to the value of `theme.vars.colors.neutral["50"]`
<Box color="neutral.50" />
// use raw CSS color value
<Box color="#f00" />
// background colors
<Box backgroundColor="tomato" />
// shorthand prop
<Box bgColor="tomato" />
tsx
import { Box } from "@hope-ui/core";
// refers to the value of `theme.vars.colors.neutral["50"]`
<Box color="neutral.50" />
// use raw CSS color value
<Box color="#f00" />
// background colors
<Box backgroundColor="tomato" />
// shorthand prop
<Box bgColor="tomato" />
PropCSS PropertyTheme scale
colorcolorcolors
bg, backgroundbackgroundcolors
bgColor, backgroundColorbackground-colorcolors
opacityopacitynone

Typography

tsx
import { Text } from "@hope-ui/core";
// refers to the value of `theme.vars.fontSizes.base`
<Text fontSize="base" />
// font-size `32px`
<Text fontSize={32} />
// font-size `"2em"`
<Text fontSize="2em" />
// applies text-align `left` on all viewports and text-align `center` from the first breakpoint and upwards
<Text textAlign={[ "left", "center" ]} />
tsx
import { Text } from "@hope-ui/core";
// refers to the value of `theme.vars.fontSizes.base`
<Text fontSize="base" />
// font-size `32px`
<Text fontSize={32} />
// font-size `"2em"`
<Text fontSize="2em" />
// applies text-align `left` on all viewports and text-align `center` from the first breakpoint and upwards
<Text textAlign={[ "left", "center" ]} />
PropCSS PropertyTheme scale
fontFamilyfont-familyfonts
fontSizefont-sizefontSizes
fontWeightfont-weightfontWeights
lineHeightline-heightlineHeights
letterSpacingletter-spacingletterSpacings
textAligntext-alignnone
fontStylefont-stylenone
textTransformtext-transformnone
textDecorationtext-decorationnone

Layout

tsx
import { Box } from "@hope-ui/core";
// verbose
<Box display="flex" />
// shorthand
<Box d="flex" />
tsx
import { Box } from "@hope-ui/core";
// verbose
<Box display="flex" />
// shorthand
<Box d="flex" />
PropCSS PropertyTheme scale
d, displaydisplaynone
verticalAlignvertical-alignnone
overflowoverflownone
overflowXoverflow-xnone
overflowYoverflow-ynone

Size

tsx
import { Box } from "@hope-ui/core";
// verbose
<Box width="100%" height={32} />
// shorthand
<Box w="100%" h="32px" />
// refers to `theme.vars.sizes.sm`
<Box boxSize="sm" />
// width `256px`
<Box w={256} />
// width `"40px"`
<Box w="40px" />
tsx
import { Box } from "@hope-ui/core";
// verbose
<Box width="100%" height={32} />
// shorthand
<Box w="100%" h="32px" />
// refers to `theme.vars.sizes.sm`
<Box boxSize="sm" />
// width `256px`
<Box w={256} />
// width `"40px"`
<Box w="40px" />
PropCSS PropertyTheme scale
w, widthwidthsizes
h, heightheightsizes
minW, minWidthmin-widthsizes
maxW, maxWidthmax-widthsizes
minH, minHeightmin-heightsizes
maxH, maxHeightmax-heightsizes
boxSizewidth, heightsizes

Flexbox

tsx
import { Box, Flex } from "@hope-ui/core";
// verbose
<Box display="flex" alignItems="center" justifyContent="space-between">
Box with Flex props
</Box>
// shorthand using the `Flex` component
<Flex align="center" justify="center">
Flex Container
</Flex>
tsx
import { Box, Flex } from "@hope-ui/core";
// verbose
<Box display="flex" alignItems="center" justifyContent="space-between">
Box with Flex props
</Box>
// shorthand using the `Flex` component
<Flex align="center" justify="center">
Flex Container
</Flex>

Props marked with an * will only work if you use the Flex or Stack components.

PropCSS PropertyTheme scale
alignContentalign-contentnone
justifyItemsjustify-itemsnone
alignItems, *alignalign-itemsnone
justifyContent, *justifyjustify-contentnone
flexDirection, *directionflex-directionnone
flexWrap, *wrapflex-wrapnone
flexflexnone
flexGrowflex-grownone
flexShrinkflex-shrinknone
flexBasisflex-basisnone
justifySelfjustify-selfnone
alignSelfalign-selfnone
orderordernone

Grid Layout

tsx
import { Box, Grid } from "@hope-ui/core";
// verbose
<Box display="grid" gap={2} gridAutoFlow="row dense">
Grid
</Box>
// shorthand using the `Grid` component
<Grid gap={2} autoFlow="row dense">
Grid
</Grid>
tsx
import { Box, Grid } from "@hope-ui/core";
// verbose
<Box display="grid" gap={2} gridAutoFlow="row dense">
Grid
</Box>
// shorthand using the `Grid` component
<Grid gap={2} autoFlow="row dense">
Grid
</Grid>

Props marked with an * will only work if you use the Grid and GridItem components.

PropCSS PropertyTheme scale
gapgrid-gapspace
rowGapgrid-row-gapspace
columnGapgrid-column-gapspace
gridTemplategrid-templatenone
gridTemplateColumns, *templateColumnsgrid-template-columnsnone
gridTemplateRows, *templateRowsgrid-template-rowsnone
gridTemplateAreas, *templateAreasgrid-template-areasnone
gridArea, *areagrid-areanone
gridColumngrid-columnnone
gridColumnStart, *colStartgrid-column-startnone
gridColumnEnd, *colEndgrid-column-endnone
gridRowgrid-rownone
gridRowStart, *rowStartgrid-row-startnone
gridRowEnd, *rowEndgrid-row-endnone
gridAutoFlow, *autoFlowgrid-auto-flownone
gridAutoColumns, *autoColumnsgrid-auto-columnsnone
gridAutoRows, *autoRowsgrid-auto-rowsnone
placeItemsplace-itemsnone
placeContentplace-contentnone
placeSelfplace-selfnone

Border

tsx
import { Box } from "@hope-ui/core";
<Box border="1px" borderColor="neutral.200">
Card
</Box>;
tsx
import { Box } from "@hope-ui/core";
<Box border="1px" borderColor="neutral.200">
Card
</Box>;
PropCSS PropertyTheme scale
borderborderborders
borderWidthborder-widthborderWidths
borderStyleborder-styleborderStyles
borderColorborder-colorcolors
borderTopborder-topborders
borderTopWidthborder-top-widthborderWidths
borderTopStyleborder-top-styleborderStyles
borderTopColorborder-top-colorcolors
borderRightborder-rightborders
borderRightWidthborder-right-widthborderWidths
borderRightStyleborder-right-styleborderStyles
borderRightColorborder-right-colorcolors
borderBottomborder-bottomborders
borderBottomWidthborder-bottom-widthborderWidths
borderBottomStyleborder-bottom-styleborderStyles
borderBottomColorborder-bottom-colorcolors
borderLeftborder-leftborders
borderLeftWidthborder-left-widthborderWidths
borderLeftStyleborder-left-styleborderStyles
borderLeftColorborder-left-colorcolors
borderXborder-left , border-rightborders
borderYborder-top , border-bottomborders

Border Radius

tsx
import { Button } from "@hope-ui/core";
// this button will have no right borderRadius
<Button borderRightRadius={0}>Button 1</Button>
// this button will have no left borderRadius
<Button borderLeftRadius={0}>Button 2</Button>
// top left and top right radius will be `theme.vars.radii.md`
<Button borderTopRadius="md">Button 2</Button>
tsx
import { Button } from "@hope-ui/core";
// this button will have no right borderRadius
<Button borderRightRadius={0}>Button 1</Button>
// this button will have no left borderRadius
<Button borderLeftRadius={0}>Button 2</Button>
// top left and top right radius will be `theme.vars.radii.md`
<Button borderTopRadius="md">Button 2</Button>
PropCSS PropertyTheme scale
borderRadius, roundedborder-radiusradii
borderTopLeftRadiusborder-top-left-radiusradii
borderTopRightRadiusborder-top-right-radiusradii
borderBottomRightRadiusborder-bottom-right-radiusradii
borderBottomLeftRadiusborder-bottom-left-radiusradii
borderTopRadius, roundedTopborder-top-left-radius + border-top-right-radiusradii
borderRightRadius, roundedRightborder-top-right-radius + border-bottom-right-radiusradii
borderBottomRadius, roundedBottomborder-bottom-left-radius + border-bottom-right-radiusradii
borderLeftRadius, roundedLeftborder-top-left-radius + border-bottom-left-radiusradii

Position

tsx
import { Box } from "@hope-ui/core";
// verbose
<Box position="absolute">Cover</Box>
// shorthand
<Box pos="absolute">Cover</Box>
<Box pos="absolute" top={0} left={0}>
Absolute with top and left
</Box>
<Box pos="fixed" w="100%" zIndex={2}>
Fixed with zIndex
</Box>
tsx
import { Box } from "@hope-ui/core";
// verbose
<Box position="absolute">Cover</Box>
// shorthand
<Box pos="absolute">Cover</Box>
<Box pos="absolute" top={0} left={0}>
Absolute with top and left
</Box>
<Box pos="fixed" w="100%" zIndex={2}>
Fixed with zIndex
</Box>
PropCSS PropertyTheme scale
pos, positionpositionnone
zIndexz-indexzIndices
toptopspace
rightrightspace
bottombottomspace
leftleftspace

Shadow

tsx
import { Box } from "@hope-ui/core";
// refers to `theme.vars.shadows.md`
<Box boxShadow="md">Shadow md</Box>;
tsx
import { Box } from "@hope-ui/core";
// refers to `theme.vars.shadows.md`
<Box boxShadow="md">Shadow md</Box>;
PropCSS PropertyTheme scale
textShadowtext-shadowshadows
shadow, boxShadowbox-shadowshadows

Pseudo selector

tsx
import { Box } from "@hope-ui/core";
// :hover style
<Box
_hover={{
background: "white",
color: "primary.500",
}}
>
Hover me
</Box>
// apply :hover over parent element
<Box role="group">
<Box
_hover={{ fontWeight: "semibold" }}
_groupHover={{ color: "tomato" }}
>
Hover me
</Box>
</Box>
// add ::before pseudo-element
// Note: the content value needs an extra set of quotes!
<Box
_before={{
content: "'🙂'",
display: "inline-block",
mr: "5px"
}}
>
A pseudo element
</Box>
tsx
import { Box } from "@hope-ui/core";
// :hover style
<Box
_hover={{
background: "white",
color: "primary.500",
}}
>
Hover me
</Box>
// apply :hover over parent element
<Box role="group">
<Box
_hover={{ fontWeight: "semibold" }}
_groupHover={{ color: "tomato" }}
>
Hover me
</Box>
</Box>
// add ::before pseudo-element
// Note: the content value needs an extra set of quotes!
<Box
_before={{
content: "'🙂'",
display: "inline-block",
mr: "5px"
}}
>
A pseudo element
</Box>
PropCSS PropertyTheme scale
_hover&:hover, &[data-hover]none
_active&:active, &[data-active]none
_focus&:focus, &[data-focus]none
_highlighted&[data-highlighted]none
_focusWithin&:focus-withinnone
_focusVisible&:focus-visiblenone
_disabled&[disabled], &[aria-disabled=true], &[data-disabled]none
_readOnly&[aria-readonly=true], &[readonly], &[data-readonly]none
_before&::beforenone
_after&::afternone
_empty&:emptynone
_expanded&[aria-expanded=true], &[data-expanded]none
_checked&[aria-checked=true], &[data-checked]none
_grabbed&[aria-grabbed=true], &[data-grabbed]none
_pressed&[aria-pressed=true], &[data-pressed]none
_invalid&[aria-invalid=true], &[data-invalid]none
_valid&[data-valid], &[data-state=valid]none
_loading&[data-loading], &[aria-busy=true]none
_selected&[aria-selected=true], &[data-selected]none
_hidden&[hidden], &[data-hidden]none
_autofill&:-webkit-autofillnone
_even&:nth-of-type(even)none
_odd&:nth-of-type(odd)none
_first&:first-childnone
_last&:last-childnone
_notFirst&:not(:first-child)none
_notLast&:not(:last-child)none
_visited&:visitednone
_activeLink&[aria-current=page]none
_activeStep&[aria-current=step]none
_indeterminate&:indeterminate, &[aria-checked=mixed], &[data-indeterminate]none
_groupHover[role=group]:hover &, [role=group][data-hover] &, [data-group]:hover &, [data-group][data-hover] &, .group:hover &, .group[data-hover] &none
_peerHover[data-peer]:hover ~ &, [data-peer][data-hover] ~ &, .peer:hover ~ &, .peer[data-hover] ~ &none
_groupFocus[role=group]:focus &, [role=group][data-focus] &, [data-group]:focus &, [data-group][data-focus] &, .group:focus &, .group[data-focus] &none
_peerFocus[data-peer]:focus ~ &, [data-peer][data-focus] ~ &, .peer:focus ~ &, .peer[data-focus] ~ &none
_groupFocusVisible[role=group]:focus-visible &, [data-group]:focus-visible &, .group:focus-visible &none
_peerFocusVisible[data-peer]:focus-visible ~ &, .peer:focus-visible ~ &none
_groupActive[role=group]:active &, [role=group][data-active] &, [data-group]:active &, [data-group][data-active] &, .group:active &, .group[data-active] &none
_peerActive[data-peer]:active ~ &, [data-peer][data-active] ~ &, .peer:active ~ &, .peer[data-active] ~ &none
_groupDisabled[role=group]:disabled &, [role=group][data-disabled] &, [data-group]:disabled &, [data-group][data-disabled] &, .group:disabled &, .group[data-disabled] &none
_peerDisabled[data-peer]:disabled ~ &, [data-peer][data-disabled] ~ &, .peer:disabled ~ &, .peer[data-disabled] ~ &none
_groupInvalid[role=group]:invalid &, [role=group][data-invalid] &, [data-group]:invalid &, [data-group][data-invalid] &, .group:invalid &, .group[data-invalid] &none
_peerInvalid[data-peer]:invalid ~ &, [data-peer][data-invalid] ~ &, .peer:invalid ~ &, .peer[data-invalid] ~ &none
_groupChecked[role=group]:checked &, [role=group][data-checked] &, [data-group]:checked &, [data-group][data-checked] &, .group:checked &, .group[data-checked] &none
_peerChecked[data-peer]:checked ~ &, [data-peer][data-checked] ~ &, .peer:checked ~ &, .peer[data-checked] ~ &none
_groupFocusWithin[role=group]:focus-within &, [data-group]:focus-within &, .group:focus-within &none
_peerFocusWithin[data-peer]:focus-within ~ &, .peer:focus-within ~ &none
_peerPlaceholderShown[data-peer]:placeholder-shown ~ &, .peer:placeholder-shown ~ &none
_placeholder&::placeholdernone
_placeholderShown&:placeholder-shownnone
_fullScreen&:fullscreennone
_selection&::selectionnone
_rtl[dir=rtl] &, &[dir=rtl]none
_ltr[dir=ltr] &, &[dir=ltr]none
_mediaDark@media (prefers-color-scheme: dark)none
_mediaReduceMotion@media (prefers-reduced-motion: reduce)none
_light.hope-theme-light &, [data-theme=light] &, &[data-theme=light]none
_dark.hope-theme-dark &, [data-theme=dark] &, &[data-theme=dark]none

Others

PropCSS PropertyTheme scale
appearanceappearancenone
userSelectuser-selectnone
pointerEventspointer-eventsnone
resizeresizenone
cursorcursornone
outlineoutlinenone
outlineOffsetoutline-offsetnone
outlineColoroutline-colorcolors
transformtransformnone
transformOrigintransform-originnone
clipPathclip-pathnone
transitiontransitionnone
transitionPropertytransition-propertynone
transitionTimingFunctiontransition-timing-functionnone
transitionDurationtransition-durationnone
transitionDelaytransition-delaynone
animationanimationnone
willChangewill-changenone
objectFitobject-fitnone
objectPositionobject-positionnone

The as prop

All Hope UI components are polymorphic, meaning you can use the as prop to change the rendered element.

For example, say you are using the Button component, and you need to make it a link instead. You can compose a and Button like below:

tsx
<Button as="a" target="_blank" href="https://solidjs.com">
Go to the SolidJS website
</Button>
tsx
<Button as="a" target="_blank" href="https://solidjs.com">
Go to the SolidJS website
</Button>

And it works with SolidJS components too:

tsx
import { Link } from "@solidjs/router";
function App() {
return (
<Button as={Link} href="/">
Back to home
</Button>
);
}
tsx
import { Link } from "@solidjs/router";
function App() {
return (
<Button as={Link} href="/">
Back to home
</Button>
);
}
Previous
Learn the basics