---
canonical: https://amplience.com/developers/docs/apis/media-delivery/media-delivery-reference/variables-and-conditionals/
title: Variables and conditionals
  interactive: true
description: Build adaptive Amplience Dynamic Media image URLs with the Media Delivery API using variables, conditionals, expressions, and the img404 fallback for missing assets.
keywords:
  - Dynamic Media
  - Media Delivery API
  - Dynamic Media variables
  - conditional image URLs
  - img404 fallback
  - URL expressions
audience: Developer
date_published: 2026-07-12
date_modified: 2026-07-27
---

# Variables and conditionals

Build image URLs that resolve when they are requested rather than when they are written. Variables hold values that the rest of the query can reuse, conditionals and expressions choose between them, and `img404` sets what is served when an asset is missing.

> **Note: Base URL pattern**
> The parameters on this page are appended to a Dynamic Media image URL. For the URL pattern and how parameters chain together, see the [Media Delivery API guide](https://amplience.com/developers/docs/apis/media-delivery/media-delivery-reference/).

## `img404` — Missing image fallback {#img404}

Specifies the filename of the fallback image to display when the requested image cannot be found. The fallback must be a published image on the same account. Can be set as a query parameter, in a transformation template, or at the account level.

The example below requests an image that does not exist - the fallback is served instead:

{/* TODO: verify that `blue-roundel` is an appropriate published fallback asset on the ampproduct account, or swap in a dedicated "image not found" asset. */}

```uri
https://cdn.media.amplience.net/i/ampproduct/this-image-does-not-exist?img404=blue-roundel
```

## `${variable}` — Variables {#variables}

User-defined variables can be declared in the query string and referenced throughout the query. Variable names are prefixed with `$`.

In this example, `h=$imageheight` reads its value from the `imageheight` variable - change the variable and the height follows:

```uri
https://cdn.media.amplience.net/i/ampproduct/woman-checked-skirt-striped-bag?imageheight=300&h=$imageheight
```

## Conditionals {#conditionals}

Conditional expressions evaluate a comparison and return one of two values.

Format: `{($variable==value)?trueValue:falseValue}`

Supported operators: `==`, `>`, `<`, `>=`, `<=`, `!=`

Supported types: number, string (must be assigned to a variable first), boolean

In this example the width is `200` when `value1` equals `value2`, and `400` otherwise. Set the two values equal and watch the image shrink:

```uri
https://cdn.media.amplience.net/i/ampproduct/woman-happy-shopping-6567737?w={($value1==$value2)?200:400}&value1=1&value2=5
```

## Expressions {#expressions}

Mathematical expressions can be included in query values, wrapped in `{}`.

Supported operators: `+`, `-`, `*`, `/`.

Variables can be used within expressions, and percentages are also supported - for example, `w={25%}` returns the image at a quarter of its size, and `w={(1/$scalefactor)*100%}` scales by the inverse of a variable.

In this example the width resolves to `$firstValue + $secondValue` - with the defaults, `w=300`:

```uri
https://cdn.media.amplience.net/i/ampproduct/Hero-Banner-720-model2?w={$firstValue+$secondValue}&firstValue=100&secondValue=200
```
