Style Props Style props are a way to alter the style of a component by simply passing props
to it. It helps to save time by providing helpful shorthand ways to style
components.
Chakra UI uses Styled System to achieve this. We
extend styled-system's utilities to provide other helpful shorthands.
The following table shows a list of every style prop and the properties within
each group. To learn more about it, you can also check the
Styled System docs :
import { Box } from "@chakra-ui/core" ;
< Box m = { 2 } > Tomato </ Box > ;
< Box maxW = " 960px " mx = " auto " /> ;
< Box m = { [ 2 , 3 ] } /> ;
Prop CSS Property Theme Key m, marginmarginspacemt, marginTopmargin-topspacemr, marginRightmargin-rightspacemb, marginBottommargin-bottomspaceml, marginLeftmargin-leftspacemxmargin-left and margin-rightspacemymargin-top and margin-bottomspacep, paddingpaddingspacept, paddingToppadding-topspacepr, paddingRightpadding-rightspacepb, paddingBottompadding-bottomspacepl, paddingLeftpadding-leftspacepxpadding-left and padding-rightspacepypadding-top and padding-bottomspace
Color & background color
# import { Box } from "@chakra-ui/core" ;
< Box color = ' gray.50 ' />
< Box color = ' #f00 ' />
< Box bg = ' tomato ' />
< Box backgroundColor = ' tomato ' />
Prop CSS Property Theme Key colorcolorcolorsbg, backgroundColorbackground-colorcolorsopacityopacitynone
import { Text } from "@chakra-ui/core" ;
< Text fontSize = " md " />
< Text fontSize = { 32 } />
< Text fontSize = ' 2em ' />
< Text textAlign = { [ 'left' , 'center' ] } />
Prop CSS Property Theme Key fontFamilyfont-familyfontsfontSizefont-sizefontSizesfontWeightfont-weightfontWeightslineHeightline-heightlineHeightsletterSpacingletter-spacingletterSpacingstextAligntext-alignnone fontStylefont-stylenone textTransformtext-transformnone textDecorationtext-decorationnone
Layout, width and height
# import { Box } from "@chakra-ui/core" ;
< Box width = " 100% " height = { 32 } /> ;
< Box w = " 100% " h = " 32px " /> ;
< Box w = { 1 / 2 } />
< Box w = { 256 } />
< Box w = ' 40px ' />
Prop CSS Property Theme Key w, widthwidthsizesh, heightheightsizesminW, minWidthmin-widthsizesmaxW, maxWidthmax-widthsizesminH, minHeightmin-heightsizesmaxH, maxHeightmax-heightsizesd, displaydisplaynone sizewidth heightsizesverticalAlignvertical-alignnone overflowoverflownone overflowXoverflowXnone overflowYoverflowYnone
import { Box , Flex } from "@chakra-ui/core" ;
< Box display = " flex " alignItems = " center " justifyContent = " space-between " >
Box with Flex props
</ Box > ;
< Flex align = " center " justify = " center " >
Flex Container
</ Flex > ;
Note: Props in * will only work if you use the Flex component.
Prop CSS Property Theme Key alignItems, *alignalign-itemsnone alignContentalign-contentnone justifyItemsjustify-itemsnone justifyContent, *justifyjustify-contentnone flexWrap, *wrapflex-wrapnone flexDirection, flexDir, *directionflex-directionnone flexflex (shorthand)none flexGrowflex-grownone flexShrinkflex-shrinknone flexBasisflex-basisnone justifySelfjustify-selfnone alignSelfalign-selfnone orderordernone
import { Box , Grid } from "@chakra-ui/core" ;
< Box display = " grid " gridGap = { 2 } gridAutoFlow = " row dense " >
Grid
</ Box > ;
< Grid gap = { 2 } autoFlow = " row dense " >
Grid
</ Grid > ;
Note: Props in * will only work if you use the Grid component.
Prop CSS Property Theme Key gridGap, *gapgrid-gapspacegridRowGap, *rowGapgrid-row-gapspacegridColumnGap, *columnGapgrid-column-gapspacegridColumn, *columngrid-columnnone gridRow, *rowgrid-rownone gridArea, *areagrid-areanone gridAutoFlow, *autoFlowgrid-auto-flownone gridAutoRows, *autoRowsgrid-auto-rowsnone gridAutoColumns, *autoColumnsgrid-auto-columnsnone gridTemplateRows, *templateRowsgrid-template-rowsnone gridTemplateColumns, *templateColumnsgrid-template-columnsnone gridTemplateAreas, *templateAreasgrid-template-areasnone
import { Box } from "@chakra-ui/core" ;
< Box
backgroundImage = " url('/images/kyuubi.png') "
backgroundPosition = " center "
backgroundRepeat = " no-repeat "
/> ;
< Box bgImage = " url('/images/gaara.png') " bgPos = " center " bgRepeat = " no-repeat " /> ;
Prop CSS Property Theme Key backgroundbackgroundnone bgImage, backgroundImagebackground-imagenone bgSize, backgroundSizebackground-sizenone bgPos,backgroundPositionbackground-positionnone bgRepeat,backgroundRepeatbackground-repeatnone bgAttachment,backgroundAttachmentbackground-attachmentnone
import { Box } from "@chakra-ui/core" ;
< Box border = " 1px " borderRadius = " md " borderColor = " gray.200 " >
Card
</ Box > ;
Prop CSS Property Theme Field borderborderbordersborderWidthborder-widthborderWidthsborderStyleborder-styleborderStylesborderColorborder-colorcolorsborderTopborder-topbordersborderTopWidthborder-top-widthborderWidthsborderTopStyleborder-top-styleborderStylesborderTopColorborder-top-colorcolorsborderRightborder-rightbordersborderRightWidthborder-right-widthborderWidthsborderRightStyleborder-right-styleborderStylesborderRightColorborder-right-colorcolorsborderBottomborder-bottombordersborderBottomWidthborder-bottom-widthborderWidthsborderBottomStyleborder-bottom-styleborderStylesborderBottomColorborder-bottom-colorcolorsborderLeftborder-leftbordersborderLeftWidthborder-left-widthborderWidthsborderLeftStyleborder-left-styleborderStylesborderLeftColorborder-left-colorcolorsborderXborder-left & border-rightbordersborderYborder-top & border-bottomborders
import { Button } from "@chakra-ui/core" ;
< Button roundedRight = " 0 " > Button 1 </ Button > ;
< Button roundedLeft = " 0 " > Button 2 </ Button > ;
< Button roundedTop = " md " > Button 2 </ Button > ;
Prop CSS Property Theme Field rounded, borderRadiusborder-radiusradiiroundedTopLeft, borderTopLeftRadiusborder-top-left-radiusradiiroundedTopRight, borderTopRightRadiusborder-top-right-radiusradiiroundedBottomRight, borderBottomRightRadiusborder-bottom-right-radiusradiiroundedBottomLeft, borderBottomLeftRadiusborder-bottom-left-radiusradiiroundedTopborder-top-left-radius & border-top-right-radiusradiiroundedRightborder-top-right-radius & border-bottom-right-radiusradiiroundedBottomborder-bottom-left-radius & border-bottom-right-radiusradiiroundedLeftborder-top-left-radius & border-bottom-left-radiusradii
import { Box } from "@chakra-ui/core" ;
< Box position = " absolute " > Cover </ Box > ;
< 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 > ;
Prop CSS Property Theme Field pos,positionpositionnone zIndexz-indexzIndicestoptopspacerightrightspacebottombottomspaceleftleftspace
import { Box , Text } from "@chakra-ui/core" ;
< Box textShadow = " sm " boxShadow = " md " /> ;
< Text textShadow = " 2px 2px #ff0000 " boxShadow = " 5px 10px #888888 " >
Text with shadows
</ Text > ;
Prop CSS Property Theme Field textShadowtext-shadowshadowsshadow,boxShadowbox-shadowshadows
Asides all the common style props listed above, all component will accept the
following props:
Prop CSS Property Theme Field animationanimationnone appearanceappearancenone transformtransformnone transformOrigintransform-originnone visibilityvisibilitynone whiteSpacewhite-spacenone userSelectuser-selectnone pointerEventspointer-eventsnone wordBreakword-breaknone overflowWrapoverflow-wrapnone textOverflowtext-overflownone boxSizingbox-sizingnone cursorcursornone resizeresizenone transitiontransitionnone objectFitobject-fitnone objectPositionobject-positionnone objectPositionobject-positionnone fillfillcolorsstrokestrokecolorsoutlineoutlinenone
The as prop is a feature that all of our components get from
@emotion/styled. It allows you to pass a HTML tag or another component to a
Chakra component to be rendered as the base tag of that component along with all
it's styles and props.
For example, say you are using a Button component, and you need to make it a
link instead. You can compose a and Button like this:
< Button as = " a " target = " _blank " variant = " outline " href = " https://chakra-ui.com " >
Hello
</ Button >
copy Editable Example
This allows you to use all of the Button props and all of the <a> props
without having to wrap the Button in an a component.
Proudly made in 🇳🇬
Released under the MIT License.
Copyright © 2019 Segun Adebayo