Theme
Design your own
On this page (5)
Component Skill — components/survey-question/component-skill.md

Native basis

A <form> holding one <fieldset>: the position (a native <progress>), the question as <legend>, a hint (aria-describedby), the controls and back / next Buttons.

Built from

Progress, Textarea, Button.

Web Platform APIs

<fieldset>:has()<progress>Constraint validation

Classes

.mk-survey-question.mk-survey-question-meta.mk-survey-question-hint.mk-survey-question-option.mk-survey-question-actions.mk-survey-question-scale

Data attributes

data-variant: multiple, scale, text.

§Single choice

A fieldset with its legend, the position as a native <progress>, radio cards (:has(:checked) highlights) and back / next.

§Multiple choice

data-variant='multiple': checkbox cards with a "choose all that apply" hint as the fieldset's description.

§Scale

data-variant='scale': five steps from strongly disagree to strongly agree - each option's label is its full meaning.

§Written answer

data-variant='text': a Textarea with the expected length stated.

§CSS view file

/* -- Survey Question (website · Account & States) -------------------------
   Presents one question with its response controls - a single choice as cards, several choices, an agreement scale, or a written answer. */
@layer components {
  /* every box in the block measures border-box - the same on any page */
  :where(.mk-survey-question, .mk-survey-question *, .mk-survey-question ::before, .mk-survey-question ::after) {
    box-sizing: border-box;
  }
  .mk-survey-question {
    display: grid;
    gap: 1.25rem;
    width: 100%;
    max-width: 36rem;
    padding: 1.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    background: var(--card);
    color: var(--card-foreground);
    & fieldset {
      display: grid;
      gap: 0.625rem;
      margin: 0;
      padding: 0;
      border: 0;
      min-width: 0;
    }
    & legend {
      margin-block-end: 0.375rem;
      padding: 0;
      font-size: 1.25rem;
      font-weight: 600;
      letter-spacing: -0.01em;
      text-wrap: balance;
    }
  }
  .mk-survey-question-meta {
    display: grid;
    gap: 0.5rem;
    color: var(--muted-foreground);
    font-size: 0.8125rem;
    font-weight: 500;
    & progress {
      width: 100%;
      height: 0.375rem;
    }
  }
  .mk-survey-question-hint {
    margin: 0 0 0.375rem;
    color: var(--muted-foreground);
    font-size: 0.875rem;
  }
  .mk-survey-question-option {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    font-size: 0.9375rem;
    cursor: pointer;
    & input {
      flex: none;
      accent-color: var(--primary);
    }
    &:hover {
      border-color: color-mix(in oklch, var(--foreground) 30%, var(--border));
    }
    &:has(:checked) {
      border-color: var(--primary);
      background: color-mix(in oklch, var(--primary) 6%, transparent);
    }
  }
  .mk-survey-question-actions {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
  }
  .mk-survey-question[data-variant="scale"] {
    & .mk-survey-question-scale {
      display: grid;
      grid-template-columns: repeat(5, minmax(0, 1fr));
      gap: 0.375rem;
    }
    & .mk-survey-question-option {
      flex-direction: column;
      justify-content: center;
      gap: 0.375rem;
      padding: 0.75rem 0.25rem;
      font-size: 0.75rem;
      line-height: 1.25;
      text-align: center;
    }
  }
  .mk-survey-question[data-variant="text"] .textarea {
    min-height: 6rem;
  }
  /* -- Accessibility ------------------------------------------- */
  @media (forced-colors: active) {
    .mk-survey-question-option:has(:checked) {
      border-color: Highlight;
    }
  }
}

Comments, ideas or improvements? Edit this page's source on GitHub