# Code Editor
> Write Widget code, define the schema and preview with examples in the code editor.
The **Code** tab is where you write and edit a Widget by hand. It has two parts: the **main editor** at the top, where you write the Widget's layout, and the **footer panel** at the bottom, where you define the schema and manage example data.

## Main Editor
The main editor is where you write the Widget's layout with the built-in [components](/docs/developer-guides/widgets/components/layout). Its toolbar has:
* **JSON**: switches between **Widget code** (the JSX layout) and **Widget JSON** (the same Widget as its rendered element tree). You can edit either view.
* **Widget images**: upload images and insert their URLs. See [Widget images](#widget-images).
* **Copy code**: copies the editor's contents to your clipboard.
The editor highlights JSX syntax so the structure is easy to read.

> [!TIP]
>
> The [component pages](/docs/developer-guides/widgets/components/layout) list every component with its props and defaults.
## Code Syntax
The code editor uses a JSX-like syntax. These are the main patterns for working with data in a Widget.
### Variables
Use a data field by putting its name in curly braces. Each variable is a field in the schema.
```jsx
```
### Nested Data
Reach into nested objects with dot notation.
```jsx
```
### Loops
Repeat elements for each entry in an array with `.map()`.
```jsx
{items.map((item) => (
))}
```
### String Interpolation
Mix fixed text with data fields using backticks and `${}`.
```jsx
```
### Conditions and Expressions
Show an element only when a value is set with `&&`, choose between two values with a ternary, and compare or calculate with the usual operators. Method calls other than `.map()` aren't supported, so format values such as prices in your data.
```jsx
{trackingUrl && }
```
## Schema
The **Schema** tab in the footer panel defines the data fields the AI agent provides when it shows the Widget. Write it in **Zod**, or switch to **JSON** to write it as a JSON Schema.
Use the **Zod** / **JSON** switch on the right of the footer panel to change format.

> [!NOTE]
>
> The schema tells the AI agent what data to pass into the Widget. Each field in the schema is a variable you can use in the code.
## Default Example
The **Default** tab holds the starting values for every schema field. The preview uses them when the Widget first shows, and visitors see them for any field no other source provides.
```json
{
"orderNumber": "QW-10482",
"status": "Shipped",
"estimatedDelivery": "Mar 9, 2026"
}
```

> [!TIP]
>
> On a Widget attached to a **Call API + show widget** action, the footer offers **Use test response from** followed by the action's name. It replaces Default with the data the action returned in its last successful test.
## Named Examples
Named examples let you preview other sets of data without changing the default values. Use them to see how the Widget looks with, say, 1 item against 5, or an order that's still processing against one that's been delivered.
**1. Add an example**
Click **Add example** (**+**) in the footer panel. The new tab, **Example 1**, starts as a copy of Default.
**2. Edit its values**
Change the values in the example's tab. Each example keeps its own data.
**3. Switch between examples**
Click an example's tab to update the preview with its data. Click the **×** on a tab to close that example.

> [!NOTE]
>
> Named examples are only for previewing in the builder. In conversations, the data comes from the Action. See [Where Widget Data Comes From](/docs/developer-guides/widgets/overview#where-widget-data-comes-from).
## Widget Images
Click **Widget images** in the toolbar to manage the images hosted for this Widget. Upload a PNG, JPEG, WebP or GIF of up to 5 MB, up to 5 images per Widget. Each image has **Copy URL**, **Insert**, which puts its URL into the code, and **Delete image**.

## Next steps
> [card] Functions | /docs/developer-guides/widgets/functions | Decide what each button and form does.
> [card] States | /docs/developer-guides/widgets/states | Show or hide parts of the Widget based on its data.
> [card] Layout components | /docs/developer-guides/widgets/components/layout | Every component you can use in the code.