Skip to main content
Login

Sign in to access your account

User Feedback - National Design System

A widget at the end of a page that asks the visitor what they think, then opens a short form and confirms the answer

Overview

User feedback is a widget at the end of a page. It asks the visitor what they think, in three steps: a question, a follow-up form, and a success message. The Survey structure asks a Yes or No question about the page. The Rating structure asks for a star score for a service. The widget sits in a form, which it validates and sends on Submit.

Pick another component when:

  • the user gives a star score inside a form or a card: Rating
  • the user reports a problem or sends a request: a form built from Forms

Markup

Preview
<section id="user-feedback" class="nds-user-feedback-section nds-content-section"> <div class="nds-section-body"> <form class="nds-form"> <div class="nds-user-feedback"> <div class="nds-user-feedback-overview"> <span class="nds-user-feedback-question">Was this page useful?</span> <!-- The script writes the success or error message here --> <span class="nds-user-feedback-status" hidden></span> <div class="nds-user-feedback-answer-btn"> <button type="button" class="nds-btn nds-primary nds-md" data-answer="Yes"> <span class="nds-label">Yes</span> </button> <button type="button" class="nds-btn nds-primary nds-md" data-answer="No"> <span class="nds-label">No</span> </button> </div> <span class="nds-user-feedback-statistic">60% of users said Yes from 2843 Feedbacks</span> <button type="button" class="nds-user-feedback-close nds-btn nds-secondary-outline nds-md" aria-label="Close feedback" hidden> <span class="nds-label">Close</span> <i class="nds-icon nds-hgi-cancel-01" aria-hidden="true"></i> </button> </div> <div class="nds-user-feedback-details" hidden> <div class="nds-user-feedback-options"> <fieldset class="nds-form-group nds-checkbox-group nds-why-yes" data-min-checked="2" aria-describedby="feedback-yes-hint"> <legend> <span class="nds-label">Please tell us why</span> </legend> <span class="nds-note" id="feedback-yes-hint">(you can select multiple options)</span> <div class="nds-form-container nds-checkbox"> <div class="nds-form-header"> <label for="feedback-yes-relevant"><span class="nds-label">Content is relevant</span></label> </div> <div class="nds-form-control"> <input type="checkbox" id="feedback-yes-relevant" name="why-yes" value="relevant" class="nds-checkbox-input"> </div> </div> <div class="nds-form-container nds-checkbox"> <div class="nds-form-header"> <label for="feedback-yes-written"><span class="nds-label">It was well written</span></label> </div> <div class="nds-form-control"> <input type="checkbox" id="feedback-yes-written" name="why-yes" value="well-written" class="nds-checkbox-input"> </div> </div> <div class="nds-form-container nds-checkbox"> <div class="nds-form-header"> <label for="feedback-yes-layout"><span class="nds-label">The layout made it easy to read</span></label> </div> <div class="nds-form-control"> <input type="checkbox" id="feedback-yes-layout" name="why-yes" value="easy-layout" class="nds-checkbox-input"> </div> </div> <div class="nds-form-container nds-checkbox"> <div class="nds-form-header"> <label for="feedback-yes-other"><span class="nds-label">Something else</span></label> </div> <div class="nds-form-control"> <input type="checkbox" id="feedback-yes-other" name="why-yes" value="other" class="nds-checkbox-input"> </div> </div> <div class="nds-form-footer" data-feedback-target hidden></div> </fieldset> <fieldset class="nds-form-group nds-checkbox-group nds-why-no" data-required aria-describedby="feedback-no-hint"> <legend> <span class="nds-label">Please tell us why</span> </legend> <span class="nds-note" id="feedback-no-hint">(you can select multiple options)</span> <div class="nds-form-container nds-checkbox"> <div class="nds-form-header"> <label for="feedback-no-irrelevant"><span class="nds-label">Content is not relevant</span></label> </div> <div class="nds-form-control"> <input type="checkbox" id="feedback-no-irrelevant" name="why-no" value="not-relevant" class="nds-checkbox-input"> </div> </div> <div class="nds-form-container nds-checkbox"> <div class="nds-form-header"> <label for="feedback-no-inaccurate"><span class="nds-label">Content is not accurate</span></label> </div> <div class="nds-form-control"> <input type="checkbox" id="feedback-no-inaccurate" name="why-no" value="not-accurate" class="nds-checkbox-input"> </div> </div> <div class="nds-form-container nds-checkbox"> <div class="nds-form-header"> <label for="feedback-no-long"><span class="nds-label">Content is too long</span></label> </div> <div class="nds-form-control"> <input type="checkbox" id="feedback-no-long" name="why-no" value="too-long" class="nds-checkbox-input"> </div> </div> <div class="nds-form-container nds-checkbox"> <div class="nds-form-header"> <label for="feedback-no-other"><span class="nds-label">Something else</span></label> </div> <div class="nds-form-control"> <input type="checkbox" id="feedback-no-other" name="why-no" value="other" class="nds-checkbox-input"> </div> </div> <div class="nds-form-footer" data-feedback-target hidden></div> </fieldset> <fieldset class="nds-form-group nds-radio-group nds-horizontal nds-gender" data-required> <legend class="nds-label">I'm</legend> <div class="nds-form-container nds-radio"> <div class="nds-form-header"> <label for="feedback-gender-male"><span class="nds-label">Male</span></label> </div> <div class="nds-form-control"> <input type="radio" id="feedback-gender-male" name="gender" value="male" class="nds-radio-input"> </div> </div> <div class="nds-form-container nds-radio"> <div class="nds-form-header"> <label for="feedback-gender-female"><span class="nds-label">Female</span></label> </div> <div class="nds-form-control"> <input type="radio" id="feedback-gender-female" name="gender" value="female" class="nds-radio-input"> </div> </div> <div class="nds-form-footer" data-feedback-target hidden></div> </fieldset> </div> <div class="nds-user-feedback-comment"> <div class="nds-form-container nds-textarea"> <div class="nds-form-header"> <label for="feedback-comment"><span class="nds-label">Feedback</span></label> </div> <div class="nds-form-control"> <textarea id="feedback-comment" name="comment" class="nds-textarea" placeholder="Enter your message..." rows="4"></textarea> </div> <div class="nds-form-footer" data-feedback-target hidden></div> </div> </div> </div> <div class="nds-user-feedback-submit" hidden> <span class="nds-user-feedback-agreement">For more information you may review <a href="#">e-participation statement</a> and <a href="#">rules of engagement.</a></span> <button class="nds-user-feedback-submit-btn nds-btn nds-primary"> <span class="nds-label">Submit</span> </button> </div> </div> </form> </div> </section>

Behavior

Survey

Yes or No opens the follow-up form with the reasons for that answer: .nds-why-yes or .nds-why-no. The other fields, such as the comment, show for both answers. Close clears every field and goes back to the question.

Rating

The widget shows the average score and the review count. The button opens a star rating with a comment. The script writes the chosen score into the hidden data-rating-value input on each pick, so the form sends it. It also writes the score into the recap, which replaces the question.

Submit

After the checks pass, Submit sends the form data to the form’s action with NDS.request. A spinner shows until the reply. A reply from 200 to 299 shows the success message. Any other reply, or no reply, shows the error message and keeps the form open, so the visitor can send it again. With no action, the success message shows at once. The built-in send posts multipart/form-data with no custom headers, and ignores the reply body. For JSON or a header, send the data yourself.

Your Own Request

To send the data another way, listen for nds:user-feedback:submit and call preventDefault(). Send e.detail.data, then call NDS.UserFeedback.setStatus() with 'success' or 'error'. The messages work as they do for an action, but the spinner is yours to show. The example is in the API section.

e.detail.data holds each checked box as its own entry with the same name. For a JSON body, read a group with data.getAll('why-yes'): Object.fromEntries() keeps only the last box.

Built-in Features

  • Auto-initialization

    The loader starts every .nds-user-feedback on the page. No init call is needed.

  • Submission Memory

    After a success, a cookie for the page path is saved for 365 days. On the next visit, the widget shows the success message instead of the question. The cookie is necessary, so it needs no consent.

  • Bilingual Feedback Messages

    The success and error messages follow the page language, Arabic or English.

  • Form Validation

    Submit checks every field rule, such as data-required and data-min-checked, before it sends. Focus moves to the first field that fails.

  • Scroll After Submit

    When the message shows and the widget is hidden under the sticky navigation, the page scrolls the widget back into view.

  • Mobile Layout

    On phones, each row stacks, and Close moves to the top of the widget.

Best Practices

  • Put the widget after the main content, as the last section of the page.
  • Use Survey on content pages, where the question is about the page. Use Rating on service pages, where the visitor judges the service.
  • Set action on the form to your endpoint, or send the data yourself from nds:user-feedback:submit. Without either, nothing is sent.
  • Leave the widget off task pages, such as a checkout, a multi-step form or a confirmation screen. The visitor’s attention belongs on the task.
  • Write reasons that fit the page, four to six in each list.
  • Remove the statistic when you have no real numbers to show. In Rating, write the real average in the question and in data-rating.
  • The gender question and the agreement line are sample content. Keep each one only when it is true for your service, and link the agreement line to your real pages.
  • Keep the .nds-note after the legend, not inside it. The group’s name then stays short, and a screen reader still reads the note through aria-describedby.
  • Do not make the widget the only way to report a problem. Link to a support form too.
  • On a page built with the NDS layouts, the layout adds the Survey. Set feedback_type: rating in the front matter for Rating, or hideFeedback: true for none. rating: true is a different key: the hero’s rating menu.

API

Classes

Class Element Effect
nds-user-feedback-section the page section Primary top border and the default background
nds-why-yes, nds-why-no a fieldset in the details Shows only for the matching answer
nds-user-feedback-statistic a span Hides while the form is open
nds-user-feedback-rating .nds-user-feedback The Rating structure. It shows the prompt while the form is open, and the recap after a success
nds-user-feedback-score the stars and the review count Keeps them on one line. Hides while the form is open

Data Attributes

Attribute Element Effect
data-answer an answer button Yes or No, with a capital letter, opens the matching reasons. Any other value, such as rate, opens the form with no reasons
data-answer .nds-user-feedback Set by the script: yes or no. Close removes it
data-state .nds-user-feedback Set by the script: details while the form is open, status after a success. status hides the question and the answer buttons. There is no value at the question step
data-success-message .nds-user-feedback Replaces the success message, as plain text, in every language. The default is “Your feedback is submitted!” or «تم استلام ملاحظتك!»
data-error-message .nds-user-feedback Replaces the error message, as plain text, in every language. The default is “An error occurred, please try again” or «حدث خطأ، يرجى المحاولة مرة أخرى»
data-no-persist .nds-user-feedback No cookie: the widget never shows a saved success and never saves one
data-rating-value a hidden input Receives the chosen score on each pick. Rating shares it
data-rating-score an element in the recap Shows the chosen score, as (4.0)
action, method the form Where Submit sends the form data. The default method is POST

The field rules (data-required, data-min-checked) and data-feedback-target work as on every field. See Forms.

CSS Custom Properties

Property Default Controls
--userfeedback-scroll-offset 120px Space between the sticky navigation and the widget after the scroll. Set it on .nds-user-feedback

Tokens

It reads these shared tokens. A change to one also changes other components: see Tokens.

Source: the var() reads in _sass/components/_user-feedback.scss.

TokenPreviewValue
--background-default
Read by background

var(--colors-base-white)
Dark mode var(--colors-neutral-800)
--border-primary
Read by border-top
var(--colors-primary-600)
--link-primary
Read by --link-color

var(--text-primary)
Dark mode var(--colors-primary-400)
--link-primary-hovered
Read by --link-hover

var(--colors-primary-700)
Dark mode var(--colors-primary-300)
--link-primary-pressed
Read by --link-pressed

var(--colors-primary-800)
Dark mode var(--colors-primary-200)

JavaScript

The NDS.UserFeedback script loads after the page shows. Until it loads, each call loads it and returns a promise of the result, so await a call whose result you use.

Method Effect
NDS.UserFeedback.init() Starts every .nds-user-feedback that is not started
NDS.UserFeedback.create(el) Starts one widget
NDS.UserFeedback.destroy(el) Removes the widget’s listeners, so create() can start it again
NDS.UserFeedback.setStatus(el, status) Ends a send that your listener took over: 'success' (default) or 'error'
Event Fired on Detail
nds:user-feedback:submit .nds-user-feedback (bubbles, cancelable) { form, data }. data is the form’s FormData. It fires after the form passes its checks
document.addEventListener('nds:user-feedback:submit', function (e) { e.preventDefault(); var widget = e.target; var csrfToken = document.querySelector('meta[name="csrf-token"]').content; NDS.request('/api/feedback', { method: 'POST', body: e.detail.data, headers: { 'X-CSRF-Token': csrfToken } }).then(function () { NDS.UserFeedback.setStatus(widget, 'success'); }, function () { NDS.UserFeedback.setStatus(widget, 'error'); }); });

The full API is in the banner of _js/nds-user-feedback.js.

Last Modified Date: 05/11/2026 - 12:02 PM