---
title: Color Input Type
product: Form Library
description: Let your respondents answer questions that require specifying a color, either with a visual color picker interface or by entering the color in RGB, HSL, or HEX format. View a free demo for JavaScript.
framework: React
source: https://surveyjs.io/form-library/examples/color-input-question/reactjs
index: https://surveyjs.io/form-library/examples/overview.md
---

# Color Input Type (React)

A color input form field is useful when respondents are asked to specify a color. They can enter a color in RGB, HSL, and HEX formats or select it with a visual interface. This demo shows how to add a color input question to a survey in your React, Vue, jQuery, Angular, or Vanilla JavaScript application.

To create a color input form field, configure a regular text entry question first: define an object with the `type` property set to `"text"` and add it to the [`elements`](https://surveyjs.io/form-library/documentation/pagemodel#elements) array. Within this object, specify the question's [`title`](https://surveyjs.io/form-library/documentation/questiontextmodel#title) and a unique [`name`](https://surveyjs.io/form-library/documentation/questiontextmodel#name) that identifies the question. To transform the text entry form field into a color input question, set the [`inputType`](https://surveyjs.io/form-library/documentation/api-reference/questiontextmodel#inputType) property to `"color"`.

## 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": [{
    "name": "color",
    "type": "text",
    "title": "Select a color",
    "inputType": "color",
    "defaultValue": "#19b394"
  }]
};
```

### `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/color-input-question/angular.md)
- [Vue 3](https://surveyjs.io/form-library/examples/color-input-question/vue3js.md)
- [jQuery](https://surveyjs.io/form-library/examples/color-input-question/jquery.md)
- [Vanilla JS](https://surveyjs.io/form-library/examples/color-input-question/vanillajs.md)
