--- title: 'Object Styles' --- Writing styles with objects is a powerful pattern built directly into the core of emotion. Instead of writing css properties in `kebab-case` like regular css, you write them in `camelCase`, for example `background-color` would be `backgroundColor`. Object styles are especially useful with the css prop because you don't need a css call like with string styles but object styles can also be used with styled. ### Examples #### With the css prop ```jsx // @live render(
This is darkorchid.
) ``` #### With `styled` ```jsx // @live import styled from '@emotion/styled' const Button = styled.button( { color: 'darkorchid' }, props => ({ fontSize: props.fontSize }) ) render() ``` ### Child Selectors ```jsx // @live render(
This is darkorchid.
This is orange
) ``` ### Media Queries ```jsx // @live render(
This is orange on a big screen and darkorchid on a small screen.
) ``` ### Numbers When numbers are the value of a css property, `px` is appended to the number unless it is a css property that is unitless. ```jsx // @live render(
This has 8px of padding and a z-index of 200.
) ``` ### Arrays Nested arrays are flattened. ```jsx // @live render(
This is darkorchid with a hotpink background and 8px of padding.
) ``` ### Fallbacks Define fallback values for browsers that don't support features with arrays. ```jsx // @live render(
This has a gradient background in browsers that support gradients and is red in browsers that don't support gradients
) ``` ### With `css` You can also use `css` with object styles. ```jsx // @live import { css } from '@emotion/react' const hotpink = css({ color: 'hotpink' }) render(

This is hotpink

) ``` ### Composition [Learn more composition in Emotion](/docs/composition.mdx). ```jsx // @live import { css } from '@emotion/react' const hotpink = css({ color: 'hotpink' }) const hotpinkHoverOrFocus = css({ '&:hover,&:focus': hotpink }) const hotpinkWithBlackBackground = css( { backgroundColor: 'black', color: 'green' }, hotpink ) render(

This is hotpink

This has a black background and is hotpink. Try moving where hotpink is in the css call and see if the color changes.

) ```