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
Explore the properties of style props in NativeBase like margin and padding. Discover how they are used to style components by passing props to them.
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.
Style Props
The following table shows a list of every style prop and the properties within each group.
Margin and padding
importReactfrom"react";import{Box,NativeBaseProvider,Center}from"native-base";constNBBox=(props)=>{return<BoxborderRadius="md"bg="primary.600"{...props}/>;};functionComponent(){return(<>{/* m="2" refers to the value of `theme.space[2]` */}<NBBoxm="2"p="5"/>{/* You can also use custom values */}<NBBoxmx="auto"px="20"py="5"/>{/* sets margin `8px` on all viewports and `16px` from the first breakpoint and up */}<NBBoxm={[2,3]}pt="10"pr="10"/></>);}exportfunctionExample(){return(<NativeBaseProvider><Centerflex={1}><Component/></Center></NativeBaseProvider>);}
Prop
CSS Equivalent
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 and background color
importReactfrom"react";import{Box,NativeBaseProvider,Center,Text}from"native-base";functionNBBox(props){return<Boxp="5"m="2"borderRadius="md"bg="primary.200"{...props}/>;}functionComponent(){return(<>{/* raw CSS color value */}<NBBoxbg="#10b981"/>{/* picks up a nested color value using dot notation */}{/* => `theme.colors.lightBlue[300]` */}<NBBoxbgColor="cyan.100"py="3">{/* using theme colors to set text color */}<Textcolor="cyan.500"fontWeight="bold">{" "}
I love NativeBase
</Text></NBBox>{/* verbose prop */}<NBBoxbackgroundColor="#eab308"/></>);}exportfunctionExample(){return(<NativeBaseProvider><Centerflex={1}><Component/></Center></NativeBaseProvider>);}
Prop
CSS Eqquivalent
Theme Key
color
color
colors
bg, background
background
colors
bgColor
background-color
colors
opacity
opacity
-
:::note
Above props can be written in the format: [color]:alpha.[opacityToken], this gets converted into RGBA color format and the opacityToken is mapped to Opacity
importReactfrom"react";import{Box,Flex,NativeBaseProvider,Center}from"native-base";constNBBox=(props)=>{return<Boxp="5"m="2"borderRadius="md"bg="primary.600"{...props}/>;};functionComponent(){return(<>{/* verbose */}<Boxdisplay="flex"flexDirection="row"justifyContent="space-between"><NBBox/><NBBox/><NBBox/></Box>{/* shorthand using the `Flex` component */}<Flexalign="center"justify="center"><NBBox/><NBBox/></Flex></>);}exportfunctionExample(){return(<NativeBaseProvider><Centerflex={1}><Component/></Center></NativeBaseProvider>);}
importReactfrom"react";import{Box,NativeBaseProvider,Center}from"native-base";constNBBox=(props)=>{return<Boxp="5"m="2"bg="primary.500"{...props}/>;};functionComponent(){return(<>{/* picks up a nested radius value using dot notation */}{/* => `theme.radius.md` */}<NBBoxborderRadius="md"/><NBBoxborderRadius="full"/>{/* partial border radius */}<NBBoxborderLeftRadius="10"/>{/* absolute value prop */}<NBBoxborderRadius="8"/></>);}exportfunctionExample(){return(<NativeBaseProvider><Centerflex={1}><Component/></Center></NativeBaseProvider>);}
Provides a way to pass props to child components inside Composite componets.
importReactfrom"react";import{Button,NativeBaseProvider,Center}from"native-base";functionApp(){return(<Button_text={{// below props will will let you style the text of the buttoncolor: "primary.100",fontSize: "md",fontWeight: "bold",underline: true,}}>
Save
</Button>);}exportfunctionExample(){return(<NativeBaseProvider><Centerflex={1}><App/></Center></NativeBaseProvider>);}
Provides a way to pass props on certain interaction.
importReactfrom"react";import{Button,NativeBaseProvider,Center}from"native-base";functionApp(){return(<ButtoncolorScheme="yellow"_pressed={{// below props will only be applied on button is pressedbg: "yellow.600",_text: {color: "warmGray.50",},}}>
Save
</Button>);}exportfunctionExample(){return(<NativeBaseProvider><Centerflex={1}><App/></Center></NativeBaseProvider>);}
Prop
Type
Description
_disabled
Same as the component
Passed props will be applied on disabled state.
_focus
Same as the component
Passed props will be applied on focused state.
_hover
Same as the component
Passed props will be applied on hovered state.
_invalid
Same as the component
Passed props will be applied on invalid state.
_pressed
Same as the component
Passed props will be applied on pressed state.
Platform Props
Provides a way to pass props bassed on Platform (android, ios or web).
importReactfrom"react";import{Button,NativeBaseProvider,Center}from"native-base";functionApp(){return(<Button_web={{// below props will only be applied on 'web' platformbg: "yellow.400",_text: {color: "coolGray.800",fontWeight: "medium",},_pressed: {// below props will only be applied on button is pressedbg: "yellow.600",_text: {color: "warmGray.50",},},}}>
Save
</Button>);}exportfunctionExample(){return(<NativeBaseProvider><Centerflex={1}><App/></Center></NativeBaseProvider>);}