---
title: Dynamic Appearance Customization
product: Survey Creator
description: Explore theme customization capabilities of Survey Creator, an extensible JavaScript form builder. Learn how to apply predefined themes like Light, Dark, Contrast, and Survey Creator 2020, or create your own theme by overriding the CSS variables of the available themes. Save and persist customizations in localStorage for easy restoration on future visits.
framework: React
source: https://surveyjs.io/survey-creator/examples/dynamic-ui-customization/reactjs
index: https://surveyjs.io/survey-creator/examples/overview.md
---

# Dynamic Appearance Customization (React)

Survey Creator allows users to dynamically customize the colors and sizes of its UI elements. These customizations can be saved as a theme and reapplied on subsequent visits. Survey Creator comes with four predefined themes to kick-start the customization process: Light, Dark, Contrast, and Survey Creator 2020. By default, this demo uses the Contrast theme. You can choose a different theme, adjust colors and sizes, and click "Persist the UI theme" to save your customizations. The theme will be stored in the browser's `localStorage` and automatically restored when you reload the page.

## Add Predefined Themes to Survey Creator

By default, users can customize only the Light theme. To make other predefined themes available for customization, import an object with predefined theme configurations or reference a script with it and pass the object to the static `registerCreatorTheme()` method:

**Modular applications**

```js
import SurveyCreatorTheme from "survey-creator-core/themes";
import { registerCreatorTheme } from "survey-creator-core";

registerCreatorTheme(SurveyCreatorTheme);
```

**Classic script applications**

```html
<head>
    <!-- ... -->
    <script src="https://unpkg.com/survey-creator-core/themes/index.min.js"></script>
    <!-- ... -->
</head>
<body>
    <script>
        SurveyCreatorCore.registerCreatorTheme(SurveyCreatorTheme);
    </script>
</body>
```

If you want to add only specific predefined themes, use the following code:

**Modular applications**

```js
import {
    SC2020,
    DefaultDark,
    DefaultContrast
} from "survey-creator-core/themes";
import { registerCreatorTheme } from "survey-creator-core";

registerCreatorTheme(SC2020, DefaultDark, DefaultContrast);
```

**Classic script applications**

```html
<head>
    <!-- ... -->
    <script src="https://unpkg.com/survey-creator-core/themes/sc2020.min.js"></script>
    <script src="https://unpkg.com/survey-creator-core/themes/default-dark.min.js"></script>
    <script src="https://unpkg.com/survey-creator-core/themes/default-contrast.min.js"></script>
    <!-- ... -->
</head>
<body>
    <script>
        SurveyCreatorCore.registerCreatorTheme(
            SurveyCreatorTheme.SC2020,
            SurveyCreatorTheme.DefaultDark,
            SurveyCreatorTheme.DefaultContrast
        );
    </script>
</body>
```  

## Apply a Predefined Theme in Code

The Light theme is applied with the `survey-creator-core.css` style sheet. All other themes are defined as JSON objects that contain a unique theme identifier and a nested object with CSS variables that override the corresponding variables in the Light theme. To apply the Dark, Contrast, or Survey Creator 2020 theme, import or reference it and pass the theme JSON object to the [`applyCreatorTheme(theme)`](/survey-creator/documentation/api-reference/survey-creator#applyCreatorTheme) method on a `SurveyCreatorModel` instance:

**Modular applications**

```js
// Option 1: Import an individual theme
import { SC2020 } from "survey-creator-core/themes";
// import { DefaultDark } from "survey-creator-core/themes";
// import { DefaultContrast } from "survey-creator-core/themes";

const creatorOptions = { /* ... */ };
const creator = new SurveyCreatorModel(creatorOptions);
creator.applyCreatorTheme(SC2020);
```

```js
// Option 2: Import all themes
import SurveyCreatorTheme from "survey-creator-core/themes";

const creatorOptions = { /* ... */ };
const creator = new SurveyCreatorModel(creatorOptions);
creator.applyCreatorTheme(SurveyCreatorTheme.SC2020);
// creator.applyCreatorTheme(SurveyCreatorTheme.DefaultDark);
// creator.applyCreatorTheme(SurveyCreatorTheme.DefaultContrast);
```

**Classic script applications**

```html
<head>
    <!-- ... -->
    <!-- Option 1: Reference an individual theme -->
    <script src="https://unpkg.com/survey-creator-core/themes/sc2020.min.js"></script>
    <!-- <script src="https://unpkg.com/survey-creator-core/themes/default-dark.min.js"></script> -->
    <!-- <script src="https://unpkg.com/survey-creator-core/themes/default-contrast.min.js"></script> -->

    <!-- Option 2: Reference all themes -->
    <script src="https://unpkg.com/survey-creator-core/themes/index.min.js"></script>
    <!-- ... -->
</head>
<body>
    <script>
        const creatorOptions = { /* ... */ };
        const creator = new SurveyCreatorModel(creatorOptions);
        creator.applyCreatorTheme(SurveyCreatorTheme.SC2020);
        // creator.applyCreatorTheme(SurveyCreatorTheme.DefaultDark);
        // creator.applyCreatorTheme(SurveyCreatorTheme.DefaultContrast);
    </script>
</body>
```

## Save and Restore User-Made Customizations

You can save theme customizations made by a user in the browser's `localStorage` and restore them next time the user opens Survey Creator. To access the theme JSON object, use the `SurveyCreatorModel`'s [`creatorTheme`](/survey-creator/documentation/api-reference/survey-creator#creatorTheme) property. Convert this object to string and save the result to the `localStorage`.

In this demo, a custom theme is saved when users click the "Persist the UI theme" toolbar button. To configure it, define an [`IAction`](https://surveyjs.io/form-library/documentation/api-reference/iaction) object and pass it to the `Action` constructor. Refer to the Code tab for a code listing.

As an alternative, a custom theme can be saved automatically when a user changes it. To implement this functionality, handle the [`onCreatorThemePropertyChanged`](/survey-creator/documentation/api-reference/survey-creator#onCreatorThemePropertyChanged) event as follows:

```js
creator.onCreatorThemePropertyChanged.add(() => {
    const themeStr = JSON.stringify(creator.creatorTheme);
    localStorage.setItem(localStorageKey, themeStr);
});
```

## Disable Theme Customization

If you want to disable the ability for users to customize the Survey Creator UI, set the [`showCreatorThemeSettings`](/survey-creator/documentation/api-reference/icreatoroptions#showCreatorThemeSettings) property to `false`:

```js
// Option 1: Disable theme customization before instantiating Survey Creator
const creatorOptions = {
    // ...
    showCreatorThemeSettings: false
}
const creator = new SurveyCreatorModel(creatorOptions);

// Option 2: Disable theme customization at runtime
creator.showCreatorThemeSettings = false;
```

## Files

### `public/index.html`

```html
<!-- Uncomment the following lines to enable Ace Editor in the JSON Editor tab -->
<!-- 
<script src="https://unpkg.com/ace-builds/src-min-noconflict/ace.js"></script>
<script src="https://unpkg.com/ace-builds/src-min-noconflict/ext-searchbox.js"></script>
<script src="https://unpkg.com/ace-builds/src-min-noconflict/theme-clouds_midnight.js"></script>
-->

<div id="surveyCreatorContainer" style="position: absolute; height: 100%; width: 100%"></div>
```

### `src/SurveyCreatorComponent.jsx`

```js
import React from "react";
import { SurveyCreator, SurveyCreatorComponent } from "survey-creator-react";
import "survey-core/survey.i18n";
import "survey-creator-core/survey-creator-core.i18n";
import { ComputedUpdater, Action } from "survey-core";
import "survey-core/survey-core.css";
import "survey-creator-core/survey-creator-core.css";
import "./index.css";

import SurveyTheme from "survey-core/themes";
import { registerCreatorTheme } from "survey-creator-core";

registerCreatorTheme(SurveyTheme); // Add predefined Survey Creator UI themes

function SurveyCreatorRenderComponent() {
    const creator = new SurveyCreator();
    const localStorageKey = "userSurveyCreatorTheme";
    const savedTheme = localStorage.getItem(localStorageKey);
    creator.applyCreatorTheme(savedTheme ? JSON.parse(savedTheme) : SurveyTheme.DefaultContrast);
    
    const saveTheme = () => {
        const themeStr = JSON.stringify(creator.creatorTheme);
        localStorage.setItem(localStorageKey, themeStr);
    };
    
    const saveThemeAction = new Action({
        id: "svd-save-theme-settings",
        iconName: "icon-save-24x24",
        iconSize: "auto",
        tooltip: "Persist the UI theme",
        visible: new ComputedUpdater(() => {
            return creator.activeTab === "designer" && creator.propertyGridNavigationMode === "buttons" && creator.showCreatorThemeSettings;
        }),
        enabled: true,
        action: saveTheme
    });
    
    const resetTheme = () => {
        window.localStorage.setItem(localStorageKey, "");
        location.reload();
    };
    
    const resetThemeAction = new Action({
        id: "svd-reset-theme",
        iconName: "icon-restore-24x24",
        iconSize: "auto",
        tooltip: "Reset the UI theme",
        visible: new ComputedUpdater(() => {
            return creator.activeTab === "designer" && creator.propertyGridNavigationMode === "buttons" && creator.showCreatorThemeSettings;
        }),
        enabled: true,
        action: resetTheme
    });
    
    creator.toolbar.actions.push(resetThemeAction);
    
    creator.toolbar.actions.push(saveThemeAction);
    
    creator.showSidebar = false;
    setTimeout(() => {
        creator.openCreatorThemeSettings();
    }, 400);
    return (<SurveyCreatorComponent creator={creator} />);
}

export default SurveyCreatorRenderComponent;
```

### `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 SurveyCreatorRenderComponent from "./SurveyCreatorComponent";

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

### `package.json`

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

## Other Frameworks

- [Angular](https://surveyjs.io/survey-creator/examples/dynamic-ui-customization/angular.md)
- [Vue 3](https://surveyjs.io/survey-creator/examples/dynamic-ui-customization/vue3js.md)
- [jQuery](https://surveyjs.io/survey-creator/examples/dynamic-ui-customization/jquery.md)
- [Vanilla JS](https://surveyjs.io/survey-creator/examples/dynamic-ui-customization/vanillajs.md)
