---
title: Ranking Question
product: Form Library
description: Let your respondents prioritize a list of choices in order of preference, priority, importance, or other criteria. Create a form and run it in your JavaScript app with SurveyJS in minutes.
framework: React
source: https://surveyjs.io/form-library/examples/add-ranking-question-to-form/reactjs
index: https://surveyjs.io/form-library/examples/overview.md
---

# Ranking Question (React)

A Ranking survey question, or a rank order question, is a type of survey or research question that is used to determine people's opinions, attitudes, and priorities towards several characteristics of a certain subject or towards multiple related options. This question asks respondents to arrange a set of choices in order of preference, importance, or other criteria, or assign a numerical value to each choice based on their relative rank. For example, a survey ranking question might ask respondents to rank a set of job benefits in order of importance, or assign the highest value to the most important job benefit, and the lowest value to the least important one. This way an employer can get a solid understanding of overall ranking of several job benefits they are considering to offer, identify which of them employees prefer or value most, and act accordingly.

## Create a Ranking Question

To add a Ranking question to a form, define an object with the `type` property set to `"ranking"` and add it to the [`elements`](https://surveyjs.io/form-library/documentation/api-reference/pagemodel#elements) array. Use the [`choices`](https://surveyjs.io/form-library/documentation/api-reference/ranking-question-model#choices) array to configure ranking items. Each object in this array should have the following structure:

```js
{
  "value": any, // A unique value to be saved in the survey results.
  "text": string // A display text. When `text` is undefined, `value` is used as display text.
}
```

If you need to specify only the `value` property, you can set the `choices` property to an array of primitive values as shown in this demo. These values are both saved in survey results and used as display text.

You can also load choice values from a RESTful service. In this case, use the [`choicesByUrl`](https://surveyjs.io/form-library/documentation/api-reference/ranking-question-model#choicesByUrl) property instead of the `choices` array. Refer to the [ChoicesRestful](https://surveyjs.io/form-library/documentation/api-reference/choicesrestful) object for information on how to configure this property. The demo on this page defines local `choices`.

## Set the Initial Sort Order

Ranking items are sorted according to the `choices` array. If you want to sort them in ascending or descending alphabetical order, assign `"asc"` or `"desc"` to the [`choicesOrder`](https://surveyjs.io/form-library/documentation/api-reference/ranking-question-model#choicesOrder) property. Alternatively, you can set this property to `"random"`. In this case, choices appear in random order each time your survey is displayed.

## Drag a Ranking Item by the Icon

The entire ranking item area responds to drag gestures. If you want to limit the area and use only the drag icon as a drag handle, assign `"icon"` to the [`settings.rankingDragHandleArea`](https://surveyjs.io/form-library/documentation/api-reference/settings#rankingDragHandleArea) property. This setting affects all Ranking questions in your application.

## Carry Forward Responses

You can use the Ranking question to implement the Carry Forward Responses feature. This feature allows you to copy choices from one question to another. For example, you can ask respondents to select choices in a Checkboxes question and then rank the selected choices in a Ranking question. Refer to the following demo for more information: [Carry Forward Responses](https://surveyjs.io/form-library/examples/survey-carry-forward/).

## See Also

[Conditionally Display Choice Options](/form-library/examples/how-to-conditionally-display-choice-options/ (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": "ranking",
      "name": "smartphone-features",
      "title": "Please rank the following smartphone features from the most important to the least",
      "isRequired": true,
      "choices": [
        "Long battery life",
        "Plenty of storage capacity",
        "High-quality camera",
        "Powerful CPU",
        "Large screen size",
        "High durability",
        "Low price"
      ]
    }
  ]
};
```

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