You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Chakra UI adopts a convenient approach to styling its components by using style props.
Style props are a way to alter the style of a component by 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 under the hood. We
extend styled-system's utilities to provide other helpful shorthands.
Style Props Reference
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:
Margin & padding
<template>
<!-- m="2" refers to the value of theme.space.[2] -->
<c-boxm="2">Tomato</c-box>
<!-- You can also make use of custom values -->
<c-boxmax-w="960px"mx="auto">Custom</c-box>
<!-- sets margin `8px` on all viewports and `12px` from the first breakpoint and up -->
<c-box :m="['2', '3']" />
</template>
Prop
CSS Property
Theme Key
m, margin
margin
space
mt, marginTop
margin-top
space
mr, marginRight
margin-right
space
mb, marginBottom
margin-bottom
space
ml, marginLeft
margin-left
space
mx
margin-left and margin-right
space
my
margin-top and margin-bottom
space
p, padding
padding
space
pt, paddingTop
padding-top
space
pr, paddingRight
padding-right
space
pb, paddingBottom
padding-bottom
space
pl, paddingLeft
padding-left
space
px
padding-left and padding-right
space
py
padding-top and padding-bottom
space
Color & background color
<template>
<!-- picks up a nested color value using dot notation -->
<c-boxcolor="gray.50" />
<!-- You can also use raw CSS color values -->
<c-boxcolor="#f00" />
<!-- Sets background color to pink -->
<c-boxbg="pink" />
</template>
Prop
CSS Property
Theme Key
color
color
colors
bg, backgroundColor
background-color
colors
opacity
opacity
none
Typography
<template>
<!-- font-size of `theme.fontSizes.md` -->
<c-textfontSize="md" />
<!-- font-size `32px` -->
<c-textfontSize="32" />
<!-- font-size `'2em'` -->
<c-textfontSize="2em" />
<!-- text-align `left` on all viewports and `center` from the first breakpoint and up -->
<c-text :textAlign="[ 'left', 'center' ]" />
</template>
<template>
<!-- This button will have no right borderRadius -->
<c-buttonroundedRight="0">Button 1</c-button>
<!-- This button will have no left borderRadius*/ -->
<c-buttonroundedLeft="0">Button 2</c-button>
<!-- top left and top right radius will be `theme.radii.md` => 4px -->
<c-buttonroundedTop="md">Button 2</c-button>
</template>
<script>import { CButton } from'@chakra-ui/vue'exportdefault { components: { CButton }}</script>
<template>
<!-- verbose -->
<c-boxposition="absolute">Cover</c-box>
<!-- shorthand -->
<c-boxpos="absolute">Cover</c-box>
<c-boxpos="absolute"top="0"left="0">
Absolute with top and left
</c-box>
<c-boxpos="fixed"w="100%"zIndex="2">
Fixed with zIndex
</c-box>
</template>
<script>import { CBox } from'@chakra-ui/vue'exportdefault { components: { CBox }}</script>
Prop
CSS Property
Theme Field
pos,position
position
none
zIndex
z-index
zIndices
top
top
space
right
right
space
bottom
bottom
space
left
left
space
Shadow
<template>
<!-- verbose --><!-- text-shadow will be `theme.shadows.sm` --><!-- box-shadow will be `theme.shadows.md` -->
<c-boxtextShadow="sm"boxShadow="md" />
<!-- raw CSS values -->
<c-texttextShadow="2px 2px #ff0000"boxShadow="5px 10px #888888">
Text with shadows
</c-text>
</template>
<script>import { CBox, CText } from'@chakra-ui/vue'exportdefault { components: { CBox, CText }}</script>
Prop
CSS Property
Theme Field
textShadow
text-shadow
shadows
shadow,boxShadow
box-shadow
shadows
Other Props
Asides from all the common style props listed above, all components will accept the
following props:
Prop
CSS Property
Theme Field
animation
animation
none
appearance
appearance
none
transform
transform
none
transformOrigin
transform-origin
none
visibility
visibility
none
whiteSpace
white-space
none
userSelect
user-select
none
pointerEvents
pointer-events
none
wordBreak
word-break
none
overflowWrap
overflow-wrap
none
textOverflow
text-overflow
none
boxSizing
box-sizing
none
cursor
cursor
none
resize
resize
none
transition
transition
none
objectFit
object-fit
none
objectPosition
object-position
none
objectPosition
object-position
none
fill
fill
colors
stroke
stroke
colors
outline
outline
none
The as prop
The as prop is a feature that a lot of the components in @chakra-ui/vue will get because
they compose the Box component.
It allows you to pass an 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 router-link and Button like this: