Style questions with CSS
Fonts, colours and the logo of the whole survey are set in the theme options. To change more, add your own CSS to a theme of your own: extend a core theme in the theme editor (see Core themes cannot be edited: extend them) and edit its custom.css (see Adding your own CSS and JavaScript).
All examples in this section go into your theme's custom.css file.
Theme options change fonts and colours for the whole survey. To style single questions, question types or parts of a question, add CSS to custom.css of your own theme. The theme loads custom.css last, so your rules override the rules of the theme.
Find the question ID
Every question sits in a container with the ID question plus the question ID, for example #question105. To find the question ID:
- New editor: select the question. Its ID appears in the address bar of your browser, after
question=. - Classic editor: open the question. Its ID appears after ID: next to the question code at the top of the page, and in the address bar after
qid.
To style one question without looking up its ID, enter a class name in the question setting CSS class(es) and use that class in custom.css (see below).
Common classes
.question-container: every question. A second class names the question type, for example.list-radiofor List (radio) and.array-flexible-rowfor Array (see the table below)..question-title-containerand.question-text: the question text..question-help-container: the help text of the question..question-valid-container: the tips below the question text, for example "Choose one of the following answers"..answer-container: the answers. Each answer option or input is an.answer-item..group-title: the title of a question group..progress-bar: the progress bar.#ls-button-submit: the Next button, which becomes Submit on the last page.
To find the class of any other element, open the survey preview, right-click the element and use the Inspect function of your browser.
Examples
/* The text of question 105 in bold */
#question105 .question-text { font-weight: bold; }
/* A gray background for the answers of all List (radio) questions */
.list-radio .answer-container { background-color: #f5f5f5; }
/* A green Next and Submit button */
#ls-button-submit { background-color: #2e7d32; }
In the theme editor, the rules go into custom.css:
- Your rules, below the comment at the top of the file.
- Save: saves the file. In a theme that doesn't have its own custom.css yet, the button is Copy to local theme and save changes.
Page classes
The <html> and <body> elements carry classes you can use to style whole pages:
- html: The language code (for example
en) and the text direction (dir-ltrordir-rtl). - body: The name of the theme and of each parent theme (for example
fruity_twentythree), the font (for examplefont-ibm-sans), the language (for examplelang-en), andbrand-logowhen the logo is shown.
Question container classes
Each question is wrapped in an element with the class question-container. It also carries:
- The class of the question type (see the table below).
mandatory: The question is mandatory or soft mandatory.input-error: The answer did not pass the validation, or a mandatory question was not answered.missing: The question still has unanswered parts and the participant has already moved past it.ls-hiddenandls-irrelevant: The question is hidden by its condition.ls-hidden-attribute: The question is hidden by its "Always hide this question" setting.- Any classes entered in the question's CSS class(es) setting (under Display). Use this to style single questions.
For example, a mandatory List (radio) question that was not answered:
<div id="question123" class="row list-radio mandatory input-error question-container">
...
</div>
Question type classes
| Question type | Class | Type code |
|---|---|---|
| 5 point choice | .choice-5-pt-radio | 5 |
| Array | .array-flexible-row | F |
| Array (5 point choice) | .array-5-pt | A |
| Array (10 point choice) | .array-10-pt | B |
| Array (Increase/Same/Decrease) | .array-increase-same-decrease | E |
| Array (Numbers) | .array-multi-flexi | : |
| Array (Texts) | .array-multi-flexi-text | ; |
| Array (Yes/Uncertain/No) | .array-yes-uncertain-no | C |
| Array by column | .array-flexible-column | H |
| Array dual scale | .array-flexible-dual-scale | 1 |
| Date/Time | .date | D |
| Equation | .equation | * |
| File upload | .upload-files | | |
| Gender | .gender | G |
| Huge free text | .text-huge | U |
| Language switch | .language | I |
| List (dropdown) | .list-dropdown | ! |
| List (radio) | .list-radio | L |
| List with comment | .list-with-comment | O |
| Long free text | .text-long | T |
| Multiple choice | .multiple-opt | M |
| Multiple choice with comments | .multiple-opt-comments | P |
| Multiple numerical input | .numeric-multi | K |
| Multiple short text | .multiple-short-txt | Q |
| Numerical input | .numeric | N |
| Ranking | .ranking | R |
| Short free text | .text-short | S |
| Text display | .boilerplate | X |
| Yes/No | .yes-no | Y |
Classes for the parts of a question
Inside the question container, the answer area uses these classes. Some depend on the question's display settings: for example, Array (Numbers) uses different classes when it shows checkboxes instead of dropdowns.
| Class | Used for | Used by (examples) |
|---|---|---|
| .ls-answers | The element that holds all answer options | All question types |
| .answers-list | A list or row of answer options | List (radio), Multiple choice, Ranking, rows of most arrays |
| .subquestion-list, .questions-list | A list or table of subquestions | Arrays, Multiple short text, Multiple numerical input |
| .answer-item | One answer option or input | Almost all question types |
| .noanswer-item | The "No answer" option | Arrays, 5 point choice, List with comment |
| .question-item | A subquestion that is also an answer | Multiple choice, Multiple short text, Multiple numerical input |
| .radio-list | A list or row of radio buttons | List (radio), 5 point choice, List with comment, rows of radio arrays |
| .radio-array | A table of radio buttons | Array, Array (5 point choice), Array (10 point choice), Array (Increase/Same/Decrease), Array (Yes/Uncertain/No) |
| .radio-item | One radio button with its label | List (radio), 5 point choice, List with comment, radio arrays |
| .checkbox-list | A list of checkboxes | Multiple choice, Multiple choice with comments |
| .checkbox-array | A table of checkboxes | Array (Numbers) with checkbox layout |
| .checkbox-item | One checkbox with its label | Multiple choice, Multiple choice with comments, Array (Numbers) with checkbox layout |
| .checkbox-text-item | A checkbox with a text field | Multiple choice with comments |
| .comment-item | The comment field next to a checkbox | Multiple choice with comments |
| .text-list | A list of text inputs | Multiple short text, Multiple numerical input |
| .text-item | One text input | Short, long and huge free text, Multiple short text, Array (Texts) |
| .number-list, .numeric-item | Numeric inputs | Multiple numerical input, Numerical input |
| .number-array | A table of numeric inputs | Array (Numbers), Array (Texts) |
| .text-array | A table of text inputs | Array (Texts), Array (Numbers) |
| .dropdown-array, .dropdown-list, .dropdown-item | Tables, rows and cells with dropdowns | Array (Numbers), Array dual scale with dropdowns |
| .date-item | The date input | Date/Time |
| .upload-item | The file upload area | File upload |
| .answertext | The subquestion text in an array row | Arrays |
| .col-answers | The column of subquestion texts | Arrays |
| .ls-heading | The header row with the answer options | Arrays |
| .ls-odd, .ls-even | Alternating rows | Arrays |
| .ls-label-xs-visibility | A label that is only visible on small screens and to screen readers | Cells of arrays |
| .ls-input-group-extra | The prefix or suffix of an input | Short free text, Numerical input, Multiple short text, Multiple numerical input |
| .ls-js-hidden | Hidden when JavaScript is active | Array dual scale, List (radio) |
| .ls-no-js-hidden | Hidden when JavaScript is not active | Ranking |
| .ls-js-hidden-sr | Hidden when JavaScript is active, but still read by screen readers | Ranking |
no-anwser-item (with this spelling) instead of noanswer-item.For example, this is the HTML of a List (radio) question's answers:
<ul class="ls-answers answers-list radio-list list-unstyled" role="radiogroup">
<li id="javatbdQ123_S456" class="answer-item radio-item">
<input type="radio" value="A" name="Q123" id="answerQ123A">
<label for="answerQ123A" class="control-label radio-label">Option A</label>
</li>
...
</ul>
Validation and tip classes
Validation tips (such as "Choose one of the following answers" or "Please enter a number between 1 and 10") always have the class ls-em-tip. While the participant answers, LimeSurvey adds ls-em-success when the tip's rule is met and ls-em-error when it is not, so you can style the two states differently. Tips hidden with the question's Hide tip setting get the class hide-tip.
Each tip also has a class for its type:
| Class | Tip |
|---|---|
| .em_default | The default tip of the question type (for example "Choose one of the following answers") |
| .em_num_answers | Minimum or maximum number of answers |
| .em_value_range | Minimum or maximum value |
| .em_sum_range | Minimum or maximum sum of the values |
| .em_sum_equals | The values must add up to a given total |
| .em_value_integer | Only whole numbers are allowed |
| .em_numbers_only | Only numbers are allowed |
| .em_other_numbers_only | Only numbers are allowed in the "Other" field |
| .em_other_comment_mandatory | The "Other" option is selected but its text field is empty |
| .em_regex_validation | The answer must match the validation pattern |
| .em_q_fn_validation | The question validation equation |
| .em_sq_fn_validation | The subquestion validation equation |
Right-to-left (RTL) languages
For right-to-left languages, the <html> element has the class dir-rtl and the core themes load an RTL version of their main CSS file. Use .dir-rtl in your CSS for rules that only apply to right-to-left languages.
Tips & tricks
These recipes go into custom.css (or a Twig file, where noted) of a theme you extended from a core theme. In the examples, replace #c0392b with your own colour.
Change the colour of radio buttons and checkboxes
To use one of the colours that come with Fruity TwentyThree, select a Theme color in the theme options. The theme options also let you choose a different Check icon.
For any other colour, add CSS to custom.css. The core themes draw their own radio buttons and checkboxes instead of the browser's default ones, so changing the colour means changing these drawn elements.
Fruity TwentyThree:
.radio-item input[type=radio]:checked + label::before,
.checkbox-item input[type=checkbox]:checked + label::before {
border-color: #c0392b;
}
.radio-item input[type=radio]:checked + label::after {
background-color: #c0392b;
}
.checkbox-item input[type=checkbox]:checked + label::after {
color: #c0392b;
}
/* The text of the selected answer */
.radio-item input[type=radio]:checked + label,
.checkbox-item input[type=checkbox]:checked + label {
color: #c0392b;
}
Bootstrap Vanilla, Fruity and Bootswatch:
.radio-item input[type=radio]:checked + label::after {
background-color: #c0392b;
}
.checkbox-item input[type=checkbox]:checked + label::after {
background-color: #c0392b;
border-color: #c0392b;
color: #ffffff;
}
Keep enough contrast between the colour and the background, so that participants with low vision can still see which answers are selected.
Make radio buttons and checkboxes bigger
Bigger radio buttons and checkboxes are easier to tap on phones and tablets. This works in all core themes:
.radio-item label::before,
.radio-item label::after,
.checkbox-item label::before,
.checkbox-item label::after {
scale: 1.3;
}
In Fruity TwentyThree, also add some space between the radio buttons and the answer text:
.radio-item label {
padding-left: 14px;
}
Values up to about 1.4 work without further changes. With bigger values, the controls start to overlap the answer text and the edges of array rows on small screens, so you also need to add more space around them.
Change the colour of the progress bar
.progress-bar {
background-color: #c0392b;
}
Show content only in one language
The <body> element has a class with the current language, such as lang-en or lang-fr. You can use it to show different content per language, for example a help line in the footer. Add the text for each language to a Twig file of your theme, such as subviews/footer/footer.twig:
<div class="help-fr" lang="fr">Pour de l'aide, appelez le 000000</div>
<div class="help-en" lang="en">For help, please call 000000</div>
Then hide the text of the other languages in custom.css:
body:not(.lang-fr) .help-fr,
body:not(.lang-en) .help-en {
display: none;
}
Use a different logo per survey
You do not need a separate theme for each logo. Theme options can be set for a single survey: open the survey and select a different Logo file in its theme options. In the new editor, click Presentation in the left toolbar, then Theme options. In the classic editor, click Theme options in the Settings menu. See Theme options.
Display a custom favicon
A favicon is the small icon shown in the browser tab and in bookmarks. The core themes show the file files/favicon.ico of the theme. To use your own icon, name it favicon.ico and upload it in the Other files panel of your extended theme. It replaces the icon of the parent theme.
Centre the logo in Fruity TwentyThree
Turn on the Logo in the theme options, then add this to custom.css:
#survey-nav .container-fluid {
position: relative;
}
#survey-nav .logo-container {
position: absolute;
left: 50%;
transform: translateX(-50%);
}
Add your own logo to the public survey list
The public survey list shows the LimeSurvey logo by default. To show your own logo:
- Extend Fruity TwentyThree and open your theme in the theme editor.
- Upload your logo in the Other files panel.
- Select the Survey list screen and open
layout_survey_list.twig. - Find the
<div>that contains{{ include('./ls_logo_svg.twig') }}. Replace this whole<div>, including the include line, with the code shown below these steps. - Click Copy to local theme and save changes.
- Go to Configuration > Global settings > General and select your theme as Theme for public survey list and error pages.
Use the name of your uploaded file, and your organisation's name as the alternative text:
{{ image('./files/mylogo.png', 'Name of your organisation', {"class": "img-fluid mx-auto d-block"}) }}
Change the file upload popup
(New in 7.6.0 ) The popup that opens when a participant uploads files in a file upload question is built from the Twig file survey/questions/answer/file_upload/modal-container.twig. The theme editor does not list this file. To change the popup, for example to add a help text, copy the file from application/views/ of your LimeSurvey installation into the views/ folder of your theme on the server (or into the ZIP file of your theme before you import it), keeping the folder structure: views/survey/questions/answer/file_upload/modal-container.twig. Then edit the copy. A question theme for the file upload question can contain its own copy as well. Keep the hidden input fields and the IDs in the file, since the upload script needs them.
Add a separator line to dual scale arrays
To draw a vertical line between the two scales of an Array dual scale question:
.array-flexible-dual-scale .header_separator,
.array-flexible-dual-scale .dual_scale_separator {
border-right: 1px solid #00a8e1;
}
Use your own font
The Fonts theme option offers a list of fonts. To use another font, add it in custom.css. A Google font can be loaded with an @import line at the top of custom.css, for example @import url("https://fonts.googleapis.com/css2?family=Lato:wght@400;700&display=swap");. For better privacy, host the font yourself: upload the font files (woff2, woff, ttf or otf) in the theme editor, so they are stored in the files/ folder of your theme, and declare them in custom.css:
@font-face {
font-family: 'MyFont';
font-weight: 400;
font-style: normal;
src: url('../files/MyFont-Regular.woff2') format('woff2');
}
body[class*="font-"] {
font-family: 'MyFont', sans-serif;
}
The selector body[class*="font-"] is needed because the Fonts option sets the font with a class on the body element, for example font-ibm-sans.
FAQ
How do I hide the asterisk of mandatory questions?
In Fruity TwentyThree, mandatory questions show an asterisk and the word "Required" above the question text. To hide both, add this line to custom.css of your theme: .asterisk, .ls-question-mandatory { display: none; }. The questions stay mandatory. Say in the question text that an answer is required, so participants still know.
I changed a CSS or JavaScript file, but the survey doesn't show the change. Why?
LimeSurvey copies the CSS and JavaScript files of a theme into a folder in tmp/assets/ and the browser loads them from there. When you save a file in the theme editor, LimeSurvey makes a new copy, so the change shows right away. If you change a file in another way, for example directly on the server, the old copy is still used. Click Clear now at Clear frontend cache in Global settings (tab General) to make new copies. While debug mode is on in config.php, the files are loaded directly from the theme folder. Your browser may also keep an old copy: reload the page without the cache (for example with Ctrl+F5).