---
title: Customize Surveys with CSS
product: Form Library
description: A free demo for JavaScript that shows how to easily customize your SurveyJS surveys or forms with custom CSS. Create a unique survey design that matches your brand's look and feel.
framework: Vue 3
source: https://surveyjs.io/form-library/examples/customize-survey-with-css/vue3js
index: https://surveyjs.io/form-library/examples/overview.md
---

# Customize Surveys with CSS (Vue 3)

SurveyJS Form Library enables you to customize the appearance of your survey using CSS. Applied CSS classes are stored in a [JSON object](https://github.com/surveyjs/survey-library/blob/master/packages/survey-core/src/defaultCss/defaultCss.ts#L13). To override a CSS class, assign a substitute class to a corresponding JSON object property. In this demo, the `customCss` object is used to override CSS classes for question content, answered questions, and titles of required questions. Assign this object to `SurveyModel`'s [`css`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#css) property.

You can also override styles dynamically based on a condition. Depending on the survey element whose classes you want to override, handle the following events:

- [`onUpdateQuestionCssClasses`](https://surveyjs.io/form-library/documentation/surveymodel#onUpdateQuestionCssClasses)
- [`onUpdatePanelCssClasses`](https://surveyjs.io/form-library/documentation/surveymodel#onUpdatePanelCssClasses)
- [`onUpdatePageCssClasses`](https://surveyjs.io/form-library/documentation/surveymodel#onUpdatePageCssClasses)
- [`onUpdateChoiceItemCss`](https://surveyjs.io/form-library/documentation/api-reference/survey-data-model#onUpdateChoiceItemCss)

The event handlers accept an object with useful properties as the second `options` parameter. Redefine individual properties in the `options.cssClasses` object to override required CSS classes. For example, this demo shows how to handle the `onUpdateQuestionCssClasses` event to override styles for Checkboxes questions only.

## Files

### `public/index.html`

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

### `src/App.vue`

```html
<script lang="ts">


const customCss = {
    "question": {
        "content": "question-content",
        "answered": "question-answered",
        "titleRequired": "question-title-required"
    }
};
</script>
<template>
    <SurveyComponent :model="survey" />
</template>
<script setup lang="ts">
    import { Model } from "survey-core";
    import { SurveyComponent } from "survey-vue3-ui";
    import "survey-core/survey-core.min.css";
    import "./index.css";
    import { json } from "./json";

    const survey = new Model(json);
    survey.onComplete.add((sender, options) => {
        console.log(JSON.stringify(sender.data, null, 3));
    });
    survey.css = customCss;
    
    survey.onUpdateQuestionCssClasses.add(function(_, options) {
        const classes = options.cssClasses;
        classes.root = "question-root";
        if (options.question.getType() === "checkbox") {
            classes.root += " question-root-checkboxes";
        }
    });
    
</script>
```

### `src/index.css`

```css
.question-answered {
  background-color: rgba(25, 179, 148, 0.05);
}

.question-content .question-root {
  border: 1px solid lightgray;
  border-radius: 5px;
  border-left: 4px solid #18a689;
  padding: 20px;
  margin: 10px 0;
}

.question-content .question-root-checkboxes {
  border-left: 4px solid orange;
}

.question-title-required {
  color: #e60a3e;
}
```

### `src/json.ts`

```ts
export const json = {
  "elements": [
    {
      "type": "radiogroup",
      "name": "radio-button-group",
      "title": "Radio Button Group",
      "choices": [ "Yes", "No" ]
    },
    {
      "type": "checkbox",
      "name": "checkboxes",
      "title": "Checkboxes",
      "choices": [ "Item 1", "Item 2", "Item 3" ]
    },
    {
      "type": "radiogroup",
      "name": "required-radio-button-group",
      "title": "Required Question",
      "isRequired": true,
      "choices": [ "Yes", "No" ]
    }
  ]
};
```

### `src/main.ts`

```ts
import { createApp } from "vue";
import App from "./App.vue";

const app = createApp(App);
app.mount("#app");
```

### `src/shims-vue.d.ts`

```ts
/* eslint-disable */
declare module "*.vue" {
    import type { DefineComponent } from "vue"
    const component: DefineComponent<{}, {}, any>
    export default component
}
```

### `src/theme.ts`

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

### `.eslintrc.js`

```js
module.exports = {
    root: true,
    env: {
        node: true
    },
    extends: [
        "plugin:vue/vue3-essential",
        "eslint:recommended",
        "@vue/typescript/recommended",
        "@vue/prettier",
        "@vue/prettier/@typescript-eslint"
    ],
    parserOptions: {
        ecmaVersion: 2020
    },
    rules: {
        "no-console": process.env.NODE_ENV === "production" ? "warn" : "off",
        "no-debugger": process.env.NODE_ENV === "production" ? "warn" : "off"
    },
    overrides: [
        {
            files: [
                "**/__tests__/*.{j,t}s?(x)",
                "**/tests/unit/**/*.spec.{j,t}s?(x)"
            ],
            env: {
                jest: true
            }
        }
    ]
};
```

### `babel.config.js`

```js
module.exports = {
  presets: ["@vue/cli-plugin-babel/preset"]
};
```

### `package.json`

```json
{
  "name": "surveyjs-library-vue3",
  "version": "0.1.0",
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint"
  },
  "dependencies": {
    "core-js": "^3.6.5",
    "tslib": "2.6.1",
    "vue": "^3.4.1",
    "survey-core": "latest",
    "survey-vue3-ui": "latest",
    "vue-router": "^4.0.0-0",
    "vuex": "^4.0.0-0"
  },
  "devDependencies": {
    "@typescript-eslint/eslint-plugin": "^2.33.0",
    "@typescript-eslint/parser": "^2.33.0",
    "@vue/cli-plugin-babel": "~4.5.0",
    "@vue/cli-plugin-eslint": "~4.5.0",
    "@vue/cli-plugin-pwa": "~4.5.0",
    "@vue/cli-plugin-router": "~4.5.0",
    "@vue/cli-plugin-typescript": "~4.5.0",
    "@vue/cli-plugin-vuex": "~4.5.0",
    "@vue/cli-service": "~4.5.0",
    "@vue/compiler-sfc": "^3.0.0",
    "@vue/eslint-config-prettier": "^6.0.0",
    "@vue/eslint-config-typescript": "^5.0.2",
    "@vue/test-utils": "^2.0.0-0",
    "eslint": "^6.7.2",
    "eslint-plugin-prettier": "^3.1.3",
    "eslint-plugin-vue": "^7.0.0-0",
    "node-sass": "^4.12.0",
    "prettier": "^1.19.1",
    "sass-loader": "^8.0.2",
    "typescript": "~3.9.3"
  }
}
```

### `tsconfig.json`

```json
{
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "strict": true,
    "jsx": "preserve",
    "importHelpers": true,
    "moduleResolution": "node",
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "sourceMap": true,
    "baseUrl": ".",
    "types": [
      "webpack-env",
      "jest"
    ],
    "paths": {
      "@/*": [
        "src/*"
      ]
    },
    "lib": [
      "esnext",
      "dom",
      "dom.iterable",
      "scripthost"
    ]
  },
  "include": [
    "src/**/*.ts",
    "src/**/*.tsx",
    "src/**/*.vue",
    "tests/**/*.ts",
    "tests/**/*.tsx"
  ],
  "exclude": [
    "node_modules"
  ]
}
```

## Other Frameworks

- [Angular](https://surveyjs.io/form-library/examples/customize-survey-with-css/angular.md)
- [React](https://surveyjs.io/form-library/examples/customize-survey-with-css/reactjs.md)
- [jQuery](https://surveyjs.io/form-library/examples/customize-survey-with-css/jquery.md)
- [Vanilla JS](https://surveyjs.io/form-library/examples/customize-survey-with-css/vanillajs.md)
