---
title: Image Picker
product: Form Library
description: A free example of an image picker (also image chooser) survey question for JavaScript. It's a type of simple choice-based questions that asks a respondent to pick a picture that is the most relevant to their answer.
framework: React
source: https://surveyjs.io/form-library/examples/image-picker-question/reactjs
index: https://surveyjs.io/form-library/examples/overview.md
---

# Image Picker (React)

Image picker (image chooser) is a question type that displays multiple images or videos and allows users to select one or more items. This demo shows how to configure an image chooser survey question in your JavaScript framework.

## Create an Image Picker Question

To create an image chooser question, define an object with the `type` property set to `"imagepicker"` and add it to the [`elements`](https://surveyjs.io/Documentation/Library?id=pagemodel#elements) array. Use the [`choices`](https://surveyjs.io/Documentation/Library?id=questionimagepickermodel#choices) array to specify choice values. Each object in this array should have the following structure:

```js
{
  "value": any, // A value to be saved in the survey results
  "text": string, // A display text (label). When `text` is undefined, `value` is used. 
  "imageLink": string // A link to the image or video that represents this choice value.
}
```

If you want to load choice values from a RESTful service, use the [`choicesByUrl`](https://surveyjs.io/Documentation/Library?id=questionimagepickermodel#choicesByUrl) property instead. Refer to the [ChoicesRestful](https://surveyjs.io/Documentation/Library?id=choicesrestful) object for information on how to configure this property. The demo on this page defines local `choices`.

## Display Image Labels

Image picker questions can display explanatory labels under images. Label texts are taken from the `text` property of choice objects or from the `value` property if `text` is undefined. To display image labels, enable the [`showLabel`](https://surveyjs.io/Documentation/Library?id=questionimagepickermodel#showLabel) property.

## Enable Multiple Image Selection

This demo allows you to select more than one image. To enable this behavior in your application, set the [`multiSelect`](https://surveyjs.io/Documentation/Library?id=questionimagepickermodel#multiSelect) property to `true`. With this setting, the question value contains an array of selected choice values instead of a single value.

## Enable the Video Picker Mode

You can also use the image chooser question as a video picker. Set the [`contentMode`](https://surveyjs.io/Documentation/Library?id=questionimagepickermodel#contentMode) property to `"video"` to display videos instead of static images. This example does not demonstrate the video picker mode.

## Add Input Fields to Images

Image Picker questions can be used to build a layout in which selectable images have input fields attached to them. This layout allows survey creators to request additional information about a product or service illustrated by the selected image. For more information about this use case, refer to the following demo:

[View "Calculator Forms for E-commerce" Demo](/form-library/examples/how-to-create-calculator-form/ (linkStyle))

## Files

### `public/index.html`

```html
<div id="surveyElement" style="position: absolute; top: 0; left: 0; right: 0; bottom: 0; min-height: 100%; height:100%"></div>
```

### `src/SurveyComponent.jsx`

```js
import React from "react";
import { Model } from "survey-core";
import { Survey } from "survey-react-ui";
import "survey-core/survey-core.min.css";
import "./index.css";
import { json } from "./json";

function SurveyComponent() {
    const survey = new Model(json);
    survey.onComplete.add((sender, options) => {
        console.log(JSON.stringify(sender.data, null, 3));
    });
    return (<Survey model={survey} />);
}

export default SurveyComponent;
```

### `src/index.css`

```css
/* You can add your custom CSS here. */
```

### `src/index.js`

```js
import React from "react";
import { createRoot } from "react-dom/client";
import SurveyComponent from "./SurveyComponent";

const root = createRoot(document.getElementById("surveyElement"));
root.render(<SurveyComponent />);
```

### `src/json.js`

```js
export const json = {
   "elements": [
      {
        "type": "imagepicker",
        "name": "animals",
        "title": "Which animals would you like to see in real life?",
        "description": "Please select all that apply.",
        "isRequired": true,
        "choices": [
          {
            "value": "lion",
            "imageLink": "https://surveyjs.io/Content/Images/examples/image-picker/lion.jpg",
            "text": "Lion"
          },
          {
            "value": "giraffe",
            "imageLink": "https://surveyjs.io/Content/Images/examples/image-picker/giraffe.jpg",
            "text": "Giraffe"
          },
          {
            "value": "red-panda",
            "imageLink": "https://surveyjs.io/Content/Images/examples/image-picker/panda.jpg",
            "text": "Red panda"
          },
          {
            "value": "camel",
            "imageLink": "https://surveyjs.io/Content/Images/examples/image-picker/camel.jpg",
            "text": "Camel"
          }
        ],
        "showLabel": true,
        "multiSelect": true
      }
   ]
};
```

### `src/theme.js`

```js
export const themeJson = {};
```

### `package.json`

```json
{
  "dependencies": {
    "react": "latest",
    "react-dom": "latest",
    "survey-core": "latest",
    "survey-react-ui": "latest"
  },
  "devDependencies": {
    "react-scripts": "latest"
  }
}
```

## Other Frameworks

- [Angular](https://surveyjs.io/form-library/examples/image-picker-question/angular.md)
- [Vue 3](https://surveyjs.io/form-library/examples/image-picker-question/vue3js.md)
- [jQuery](https://surveyjs.io/form-library/examples/image-picker-question/jquery.md)
- [Vanilla JS](https://surveyjs.io/form-library/examples/image-picker-question/vanillajs.md)
