Responsive React grid system built with Styled System, with support for Emotion and Styled Components
npm install reflexboxš¦ Ergonomic, responsive React layout and grid system.
The original Box component⢠since 2015
[![Build Status][badge]][travis]
[![Downloads][downloads-badge]][npm]
[![Version][version-badge]][npm]
[![MIT License][license-badge]](LICENSE.md)

[badge]: https://flat.badgen.net/travis/rebassjs/rebass/master
[travis]: https://travis-ci.org/rebassjs/rebass
[downloads-badge]: https://flat.badgen.net/npm/dw/reflexbox
[version-badge]: https://flat.badgen.net/npm/v/reflexbox
[license-badge]: https://flat.badgen.net/badge/license/MIT/blue
[npm]: https://npmjs.com/package/reflexbox
- Primitive styled components for all your layout needs
- Customize styles inline with the sx prop
- Ergonomic responsive array-based values
- Support for component variants
- [Styled System][] props
- Themeable and compatible with the [Theme Specification][]
- Built with [Styled System][]
- Works with [Theme UI][]
- Built with Emotion, with support for Styled Components
``sh`
npm i reflexbox
`jsx
import React from 'react'
import { Flex, Box } from 'reflexbox'
export default props =>
p={3}>
Reflex
p={3}>
Box
`
The Box and Flex components both accept a sx prop that works with no additional setup required.sx
The prop is similar to Emotion's css prop, but allows you to use values derived from the theme object.
Reflexbox follows the [Theme Specification][], which means that any theme created for use with [Theme UI][], [Styled System][], or other similar libraries will work out-of-the-box.
This allows you to share design constraints for typography, color, and layout throughout your application using a theming context.
`jsx`
p: 4,
color: 'primary',
}}
/>
Note: to opt-out of theme-based styles, use the css prop instead, which will not transform values.
Because Reflexbox follows the [Theme Specification][], all themes built for use with [Styled System][], [Theme UI][], or other related libraries are compatible with Reflexbox.
To add a theme to an application, import the ThemeProvider component from emotion-theming and pass a custom theme object in.
`sh`
npm i emotion-theming
`jsx
import React from 'react'
import { ThemeProvider } from 'emotion-theming'
import { Flex, Box } from 'reflexbox'
const theme = {
breakpoints: [
'40em', '52em', '64em',
],
colors: {
text: '#000',
background: '#fff',
primary: '#07c',
},
space: [
0, 4, 8, 16, 32, 64, 128, 256,
],
}
export default props =>
p: 4,
bg: 'primary',
}}>
Hello
`
For use with [Theme UI][], use gatsby-plugin-theme-ui or import the Theme UI ThemeProvider instead.
`js`
import { ThemeProvider } from 'theme-ui'
Reflexbox components also accept a variant prop, which allows you to define commonly used styles,
such as cards, badges, and CSS grid layouts, in your theme object for reuse.
Add a variants object to your theme and include any variants as style objects. These styles can reference other values in your theme such as colors, typographic styles, and more.
`js`
// example theme
export default {
colors: {
text: '#000',
background: '#fff',
primary: '#07c',
},
radii: {
default: 4,
},
shadows: {
card: '0 0 4px rgba(0, 0, 0, .125)',
},
variants: {
card: {
p: 3,
borderRadius: 'default',
bg: 'white',
boxShadow: 'card',
},
badge: {
color: 'white',
bg: 'primary',
p: 1,
borderRadius: 'default',
},
},
}
To apply a variant to your component, pass the name to the variant prop.
`jsx`
Use array values to quickly and ergonomically add mobile-first responsive styles to specific properties.
This works on all style props and the sx prop.
See the [Styled System][] docs for more.
`jsx`
// 100% width at the smallest viewport width
// 50% width at the next breakpoint
// 25% width at the next breakpoint
You can customize the widths used for each breakpoint by defining a theme.breakpoints array in your theme.
Reflexbox conforms to the [Theme Specification][] and includes many common [Styled System][] props.
The Box and Flex components accept the following props:
Prop | Theme Key
---|---
margin, m | spacemarginTop, mt | spacemarginRight, mr | spacemarginBottom, mb | spacemarginLeft, ml | spacemarginX, mx | spacemarginY, my | spacepadding, p | spacepaddingTop, pt | spacepaddingRight, pr | spacepaddingBottom, pb | spacepaddingLeft, pl | spacepaddingX, px | spacepaddingY, py | space
Prop | Theme Key
---|---
width | sizesheight | sizesminWidth | sizesmaxWidth | sizesminHeight | sizesmaxHeight | sizes
Prop | Theme Key
---|---
fontFamily | fontsfontSize | fontSizesfontWeight | fontWeightslineHeight | lineHeightsletterSpacing | letterSpacingsfontStyle | N/AtextAlign | N/A
Prop | Theme Key
---|---
color | colorsbackgroundColor, bg | colorsopacity | N/A
Prop | Theme Key
---|---
alignItems | N/AalignContent | N/AjustifyItems | N/AjustifyContent | N/AflexWrap | N/AflexDirection | N/Aflex | N/AflexGrow | N/AflexShrink | N/AflexBasis | N/AjustifySelf | N/AalignSelf | N/Aorder | N/A
To use Reflexbox with Styled Components, import components from reflexbox/styled-components.
`js``
import { Flex, Box } from 'reflexbox/styled-components'
This library is the result of consolidating APIs and ergonomics from the original Reflexbox library, Grid Styled, and Rebass Grid.
Reflexbox originally appeared with the original version of Rebass in 2015.
[theme specification]: https://github.com/system-ui/theme-specification
[styled system]: https://styled-system.com
[theme ui]: https://theme-ui.com
[emotion]: https://emotion.sh
[styled components]: https://styled-components.com