---
title: JavaScript in JSX with Curly Braces
---
JSX lets you write HTML-like markup inside a JavaScript file, keeping rendering logic and content in the same place. Sometimes you will want to add a little JavaScript logic or reference a dynamic property inside that markup. In this situation, you can use curly braces in your JSX to open a window to JavaScript.
* How to pass strings with quotes
* How to reference a JavaScript variable inside JSX with curly braces
* How to call a JavaScript function inside JSX with curly braces
* How to use a JavaScript object inside JSX with curly braces
## Passing strings with quotes {/*passing-strings-with-quotes*/}
When you want to pass a string attribute to JSX, you put it in single or double quotes:
```js
export default function Avatar() {
return (
);
}
```
```css
.avatar { border-radius: 50%; height: 90px; }
```
Here, `"https://react.dev/images/docs/scientists/7vQD0fPs.jpg"` and `"Gregorio Y. Zara"` are being passed as strings.
But what if you want to dynamically specify the `src` or `alt` text? You could **use a value from JavaScript by replacing `"` and `"` with `{` and `}`**:
```js
export default function Avatar() {
const avatar = 'https://react.dev/images/docs/scientists/7vQD0fPs.jpg';
const description = 'Gregorio Y. Zara';
return (
);
}
```
```css
.avatar { border-radius: 50%; height: 90px; }
```
Notice the difference between `className="avatar"`, which specifies an `"avatar"` CSS class name that makes the image round, and `src={avatar}` that reads the value of the JavaScript variable called `avatar`. That's because curly braces let you work with JavaScript right there in your markup!
## Using curly braces: A window into the JavaScript world {/*using-curly-braces-a-window-into-the-javascript-world*/}
JSX is a special way of writing JavaScript. That means it’s possible to use JavaScript inside it—with curly braces `{ }`. The example below first declares a name for the scientist, `name`, then embeds it with curly braces inside the `
`:
```js
export default function TodoList() {
const name = 'Gregorio Y. Zara';
return (
{name}'s To Do List
);
}
```
Try changing the `name`'s value from `'Gregorio Y. Zara'` to `'Hedy Lamarr'`. See how the list title changes?
Any JavaScript expression will work between curly braces, including function calls like `formatDate()`:
```js
const today = new Date();
function formatDate(date) {
return new Intl.DateTimeFormat(
'en-US',
{ weekday: 'long' }
).format(date);
}
export default function TodoList() {
return (
To Do List for {formatDate(today)}
);
}
```
### Where to use curly braces {/*where-to-use-curly-braces*/}
You can only use curly braces in two ways inside JSX:
1. **As text** directly inside a JSX tag: `{name}'s To Do List
` works, but `<{tag}>Gregorio Y. Zara's To Do List{tag}>` will not.
2. **As attributes** immediately following the `=` sign: `src={avatar}` will read the `avatar` variable, but `src="{avatar}"` will pass the string `"{avatar}"`.
## Using "double curlies": CSS and other objects in JSX {/*using-double-curlies-css-and-other-objects-in-jsx*/}
In addition to strings, numbers, and other JavaScript expressions, you can even pass objects in JSX. Objects are also denoted with curly braces, like `{ name: "Hedy Lamarr", inventions: 5 }`. Therefore, to pass a JS object in JSX, you must wrap the object in another pair of curly braces: `person={{ name: "Hedy Lamarr", inventions: 5 }}`.
You may see this with inline CSS styles in JSX. React does not require you to use inline styles (CSS classes work great for most cases). But when you need an inline style, you pass an object to the `style` attribute:
```js
export default function TodoList() {
return (
- Improve the videophone
- Prepare aeronautics lectures
- Work on the alcohol-fuelled engine
);
}
```
```css
body { padding: 0; margin: 0 }
ul { padding: 20px 20px 20px 40px; margin: 0; }
```
Try changing the values of `backgroundColor` and `color`.
You can really see the JavaScript object inside the curly braces when you write it like this:
```js {2-5}