---
title: 'The css Prop'
---
The primary way to style elements with emotion is the `css` prop. It provides a concise and flexible API to style your components.
## Get Started
There are 2 ways to get started with the `css` prop.
- [Babel Preset](#babel-preset)
- [JSX Pragma](#jsx-pragma)
Both methods result in the same compiled code.
After adding the preset or setting the pragma as a comment, compiled jsx code will use emotion's `jsx` function instead of `React.createElement`.
| | Input | Output |
| ------ | -------------------------- | --------------------------------------------------- |
| Before | `
` | `React.createElement('img', { src: 'avatar.png' })` |
| After | `
` | `jsx('img', { src: 'avatar.png' })` |
#### Babel Preset
This method will **not** work with [Create React App](https://github.com/facebook/create-react-app) or other projects that do not allow custom Babel configurations.
Use the [JSX Pragma](#jsx-pragma) method instead.
**.babelrc**
```json
{
"presets": ["@emotion/babel-preset-css-prop"]
}
```
> [Full `@emotion/babel-preset-css-prop` documentation](https://emotion.sh/docs/@emotion/babel-preset-css-prop)
If you are using the compatible React version (`>=16.14.0`) then you can opt into using [the new JSX runtimes](https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html) by using such configuration:
**.babelrc**
```json
{
"presets": [
[
"@babel/preset-react",
{ "runtime": "automatic", "importSource": "@emotion/react" }
]
],
"plugins": ["@emotion/babel-plugin"]
}
```
In case you want to use the new JSX runtimes with [Next.js](https://nextjs.org/) and you are using their [`next/babel`](https://nextjs.org/docs/advanced-features/customizing-babel-config) preset then the configuration should look like this:
**.babelrc**
```json
{
"presets": [
[
"next/babel",
{
"preset-react": {
"runtime": "automatic",
"importSource": "@emotion/react"
}
}
]
],
"plugins": ["@emotion/babel-plugin"]
}
```
#### JSX Pragma
Set the jsx pragma at the top of your source file that uses the `css` prop.
This option works best for testing out the `css` prop feature or in projects where the babel configuration is not configurable (create-react-app, codesandbox, etc.).
```js
/** @jsx jsx */
```
Similar to a comment containing linter configuration, this configures the [jsx babel plugin](https://babeljs.io/docs/en/babel-plugin-transform-react-jsx) to use the `jsx` function instead of `React.createElement`.
If you are using a zero-config tool with automatic detection of which runtime (classic vs. automatic) should be used and you are already using a React version that has [the new JSX runtimes](https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html) (hence `runtime: 'automatic'` being configured automatically for you) such as Create React App 4 then `/** @jsx jsx */` pragma might not work and you should use `/** @jsxImportSource @emotion/react */` instead.
> [JSX Pragma Babel Documentation](https://babeljs.io/docs/en/babel-plugin-transform-react-jsx#pragma)
#### Import the `jsx` function from `@emotion/react`
```js
/** @jsx jsx */
import { jsx } from '@emotion/react'
```
Note that excluding this will cause your css to render as `[Object Object]`.
#### Use the `css` prop
Any component or element that accepts a `className` prop can also use the `css` prop. The styles supplied to the `css` prop are evaluated and the computed class name is applied to the `className` prop.
## Object Styles
The `css` prop accepts object styles directly and does not require an additional import.
```jsx
// @live
render(