Keycloak Login Page Accessibility: WCAG for Custom Themes

Guilliano MolaireGuilliano Molaire13 min read

A Keycloak login page meets WCAG 2.2 AA when your theme keeps visible labels and focus rings, holds 4.5:1 contrast for text and 3:1 for controls, shows errors as text tied to the field and announced to screen readers (never by color alone), stops motion under prefers-reduced-motion, and lets password managers and passkeys work, as Accessible Authentication asks.

The stock keycloak.v2 login theme already does much of this, so most of the work is keeping it intact while you add your brand, and closing one or two small gaps. This post walks through the sign-in form, its error state, the one-time code page and the moment after you press Sign In, and maps each one to the success criterion an auditor will check, with CSS and FreeMarker you can copy into your theme. Everything here follows the Keycloak 26.8.2 theme source, so line numbers may move on other 26.x releases.

Which WCAG 2.2 criteria apply to a Keycloak login page?

WCAG 2.2 has dozens of success criteria, but a sign-in form only touches a handful of them. A success criterion is one testable rule, and its level (A, AA or AAA) says how strict it is. A procurement form that asks for “WCAG 2.2 AA” means every A and AA criterion. This table lists the ones that apply to each part of a Keycloak login page:

Part of the login page Success criterion Level What it asks of your theme
Username and password fields 3.3.2 Labels or Instructions A A visible label on every field, not a placeholder that disappears
Error state 1.4.1 Use of Color A The error shows by more than a red border
Error state 3.3.1 Error Identification A The field in error is identified and the error is described in text
Text, links and buttons 1.4.3 Contrast (Minimum) AA 4.5:1 for normal text, 3:1 for large text
Field borders, icons, focus ring 1.4.11 Non-text Contrast AA 3:1 against the colors next to them
Keyboard use 2.4.7 Focus Visible AA A visible focus indicator on every control
Show password button 2.5.8 Target Size (Minimum) AA At least 24 by 24 CSS pixels, or enough space around it
Loading and progress text 4.1.3 Status Messages AA Screen readers hear the status without it taking focus
Spinners and other motion 2.2.2 Pause, Stop, Hide and 2.3.3 Animation from Interactions A and AAA No long-running motion beside the form, and motion off for users who ask
Password, OTP and passkey 1.3.5 Identify Input Purpose and 3.3.8 Accessible Authentication (Minimum) AA autocomplete values, password managers and paste all keep working

Note that 2.3.3 is a AAA criterion, so it is not part of an AA claim. We still include reduced motion below, because it costs a few lines of CSS and, as the Understanding page notes, some users experience distraction or nausea from animated content.

What does the default keycloak.v2 theme already give you?

Before you change anything, it helps to know what you would be breaking. In the 26.8.2 templates, every field is drawn by the macros in field.ftl, and they do several things right:

The macros leave one gap, though: the input carries aria-invalid, but the input and password macros in the 26.8.2 field.ftl do not set aria-describedby, so the input is not linked to the text that explains its error. A screen reader user who tabs back into the field hears that it is invalid but not why. We fix that in the error section below.

The input macro in Keycloak 26.8.2’s field.ftl on GitHub, with the lines that set aria-invalid and no aria-describedby highlighted

Set up a theme that extends keycloak.v2

If you already have a custom theme, skip ahead. If you are starting one, create a login folder in your theme’s directory and a theme.properties that extends keycloak.v2. The Keycloak theme guide shows that once you set styles, only the stylesheets you list are applied, and that your stylesheet must be listed last to override the parent styles, so list the parent’s css/styles.css first and your own file last:

parent=keycloak.v2
import=common/keycloak
styles=css/styles.css css/a11y.css

Put the CSS from the sections below in login/resources/css/a11y.css. The keycloak.v2 login theme also sets darkMode=true in its theme.properties, so every contrast check below needs doing twice, once in light and once in dark.

Keep visible labels on every field

Placeholder-only fields are the most common accessibility regression in custom login themes. A designer removes the label to make the card look cleaner and puts “Email” inside the field as a placeholder, but the placeholder disappears as soon as the user types, and its light gray text rarely reaches 4.5:1. 3.3.2 Labels or Instructions asks that “labels or instructions are provided when content requires user input”, so keep the label from field.ftl visible above the field.

If what you really want is different wording, change the text rather than hiding the label, as in how to change the username label on the Keycloak login page.

Hold 4.5:1 for text and 3:1 for borders and icons

Brand colors are where contrast usually breaks. A light brand blue might look fine as a button background, but white text on it can fall below 4.5:1 for normal text, and the same goes for gray helper text, the “Forgot password?” link and the footer links. Large text (at least 18 point, or 14 point bold) only needs 3:1, and logotypes have no requirement.

Text is only half of it. 1.4.11 Non-text Contrast asks for 3:1 “against adjacent color(s)” for the “visual information required to identify user interface components and states”. On a login page that means the field borders that show where to type, the error icon, the focus ring and the eye icon on the show password button. A pale gray input border on a white card is the usual failure.

Check each pair with a contrast checker, in both light and dark mode, and set your values in a11y.css:

/* Field borders at 3:1 or better against the card (1.4.11) */
.pf-v5-c-form-control {
  --pf-v5-c-form-control--before--BorderTopColor: #64748b;
  --pf-v5-c-form-control--before--BorderRightColor: #64748b;
  --pf-v5-c-form-control--before--BorderBottomColor: #64748b;
  --pf-v5-c-form-control--before--BorderLeftColor: #64748b;
  --pf-v5-c-form-control--after--BorderBottomColor: #64748b;
}

/* Links in the form at 4.5:1 or better (1.4.3) */
.pf-v5-c-login__main a {
  color: #1e40af;
  text-decoration: underline;
}

The underline on links matters for 1.4.1 Use of Color too: a link that differs from the text around it by color alone needs another cue, and an underline is the simplest one.

Keep a visible focus ring

Keyboard users, and many screen reader users, move through the form with Tab, so 2.4.7 Focus Visible asks that “any keyboard operable user interface has a mode of operation where the keyboard focus indicator is visible”. Custom themes break this with a global outline: none added because the browser’s ring did not match the brand. If you want your own ring, replace the outline rather than remove it:

/* A focus ring that keyboard users can see (2.4.7) at 3:1 (1.4.11) */
.pf-v5-c-login__main a:focus-visible,
.pf-v5-c-login__main button:focus-visible,
.pf-v5-c-form-control:focus-within {
  outline: 3px solid #1e40af;
  outline-offset: 2px;
}

/* The show password button is at least 24 by 24 CSS pixels (2.5.8) */
.pf-v5-c-button.pf-m-control {
  min-width: 24px;
  min-height: 24px;
}

Use outline rather than box-shadow for the ring. In forced colors mode, such as Windows High Contrast, MDN notes that box-shadow is forced to none, so a ring drawn only with a shadow disappears for exactly the users who need it most.

Show errors with color, a shape and text

The default messages file words the error for bad credentials as “Invalid username or password.”, and it appears under the username field because login.ftl passes the first error of either field to the username field. The stock theme shows that error three ways at once: a red border, an error icon and the text. Each cue covers a different user. Someone with a red-green color vision deficiency may miss the border but sees the icon, and someone using a screen reader gets neither but hears the text. That combination is what 1.4.1 Use of Color and 3.3.1 Error Identification ask for, since 3.3.1 says “the item that is in error is identified and the error is described to the user in text”.

A Keycloak login field going into its error state: a red border, then an error icon, then the error text, then the aria attributes a screen reader uses

After a wrong password, the username field gets a red border (color), an error icon (shape) and the message under it (text), and with the fix below the input also carries aria-invalid and aria-describedby, so a screen reader reads the message with the field.

Custom themes often keep the red border and drop the rest, for instance by hiding the helper text to keep the card short. Keep all three. Then close the gap from earlier by linking the input to its message. Copy field.ftl from your Keycloak release into your theme’s login folder, since the theme guide says you can override individual templates, and change the input in both the input and password macros. The stock line writes aria-invalid with an empty value on a field with no error, which our login accessibility checker reports, so the version below writes aria-invalid and aria-describedby only when the field has an error:

<input id="${name}" name="${name}" value="${value}" type="text" autocomplete="${autocomplete}" <#if autofocus>autofocus</#if>
        <#if autocomplete == "one-time-code">inputmode="numeric"</#if>
        <#if error?has_content>aria-invalid="true" aria-describedby="input-error-${name}"</#if>/>

The id input-error-${name} is the one the group macro already gives the error text, so nothing else changes. Because you copied a template, check it against the new release’s field.ftl when you upgrade, since the theme guide warns that you may need to update a custom template when upgrading to a new release.

The banner messages at the top of the form, such as “Your login attempt timed out.”, come from template.ftl, which pairs an icon per message type with the message text, so the same rule holds there: if you restyle the alert, keep the icon and the text. See also Keycloak authentication error handling and how to show the password policy on the reset page.

Somewhere to run this that stays patched

Everything above works the same on Skycloak, because it is real upstream Keycloak rather than a fork. What changes is who handles the upgrades, backups and security patches afterwards.

Announce loading and status changes politely

Status messages need care because of how Keycloak pages work. When the user submits the form, the browser loads a new page, and the Status Messages Understanding page lists “going to a new page” among changes of context, which are not status messages. The error that comes back is therefore covered by 3.3.1 above, and the field’s text, label and aria-invalid are what the screen reader reads when the user reaches it.

4.1.3 Status Messages applies to what changes on the page without a reload, and a login theme usually adds exactly that: a “Signing in” state on the button, or a spinner. The stock login.ftl only disables the button on submit. If your theme shows more, put the text in a region with role="status", which has an implicit aria-live value of polite, so screen readers announce it after what they are reading instead of interrupting. Add the region, empty, to your overridden login.ftl, because MDN advises you to start with an empty live region and update it later:

<div id="kc-sign-in-status" class="kc-visually-hidden" role="status"></div>

Then set its text from a script that you list in the theme’s scripts property, described in the theme guide:

document.getElementById('kc-form-login')?.addEventListener('submit', () => {
  const status = document.getElementById('kc-sign-in-status');
  if (status) status.textContent = 'Signing in';
});
.kc-visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

Announce one short message per state change and do not update it on a timer, because a region that repeats “still signing in” every second floods the screen reader. If the text should be translated, take it from the theme’s messages with msg in the template and pass it to the script in a data attribute.

Stop spinners and transitions under reduced motion

Users can turn on a setting on their device to minimize non-essential motion, and CSS detects it with prefers-reduced-motion. Honoring it is what 2.3.3 Animation from Interactions asks, which is AAA, while the AA-relevant rule is 2.2.2 Pause, Stop, Hide for motion that starts by itself, lasts more than five seconds and sits beside other content, such as an animated background behind the login card.

Turning motion off must not turn off the signal. A spinner that stops spinning looks like a frozen page, so pair it with the “Signing in” text from the previous section, and keep the button disabled so the user can see that the form is busy:

@media (prefers-reduced-motion: reduce) {
  .pf-v5-c-login *,
  .pf-v5-c-login *::before,
  .pf-v5-c-login *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

With this rule a spinner shows as a static ring next to the text, a card that slid in simply appears, and an animated background stays still.

Let password managers, one-time codes and passkeys work

3.3.8 Accessible Authentication (Minimum) is new in WCAG 2.2 and is the criterion most specific to a login page. It says a cognitive function test, “such as remembering a password or solving a puzzle”, is not required for any step unless a mechanism helps, and the Understanding page names “password entry by password managers” and “copy and paste” as such mechanisms. It also says a page fails if “password managers are actively blocked from filling in the fields” or users “are prevented from copy and paste operations”.

The stock theme passes because of the autocomplete values listed earlier, which also satisfy 1.3.5 Identify Input Purpose for the username and password. Custom themes break it in three ways that are easy to avoid:

  • Blocking paste on the password field with a script, often added in the belief that it improves security. Remove it.
  • Changing autocomplete to off or to a made-up value when overriding login.ftl. Keep username and current-password, and keep username webauthn when it is there.
  • Splitting the one-time code into six boxes. The Understanding page gives this as a failing example, because trying to paste the entire code “only fills in one digit in the first input”. Keep the single field from login-otp.ftl.

Passkeys help here too: the Examples section of the same page gives the example of a website that “uses WebAuthn so the user can authenticate with their device instead of username/password”, because the user does not have to remember or type anything. For the Keycloak side, see our Keycloak passkeys and WebAuthn guide.

Regressions custom themes commonly introduce

Because keycloak.v2 handles the basics, start with what your theme changed. Check it for these regressions before an audit does:

  • outline: none on inputs or buttons without a replacement focus ring
  • Brand colors on buttons and links that fall below 4.5:1, often only in dark mode
  • Labels hidden and replaced by placeholders
  • A red border as the only sign of an error, with the helper text hidden
  • An error icon or field border below 3:1 against the card
  • A tiny show password icon with no padding
  • Pasting blocked, autocomplete removed, or the code split into several boxes
  • A background video or animation that keeps moving under reduced motion

If you build your theme with a framework, such as the approach in customizing Keycloak themes with Keycloakify in Skycloak, the same checks apply to whatever markup your theme renders.

How to test your Keycloak login page

Run this pass on the sign-in page, the error state (submit a wrong password), the one-time code page and the password reset page, in light and dark mode:

  1. Keyboard only. Unplug the mouse or leave it alone. Tab through every field, link and button, and check that the focus ring is always visible and the order follows the page.
  2. Grayscale. In Chrome DevTools, open the Rendering tab and emulate achromatopsia, the absence of color vision. The error state must still be obvious from the icon and the text.
  3. Forced colors. In the same tab, emulate forced-colors: active. Field borders, the focus ring and the error text must all stay visible.
  4. Reduced motion. Emulate prefers-reduced-motion: reduce and submit the form. Nothing should move, and the “Signing in” text should still appear.
  5. Screen reader. With NVDA, JAWS or VoiceOver, sign in with a wrong password. Each field should be read with its label, the username field should be read as invalid with its message, and the “Signing in” status should be announced once.
  6. Contrast. Check each text color, border, icon and focus ring against what sits next to it, using the 4.5:1 and 3:1 figures above.

The first steps of this pass are quick to automate. Our free login page accessibility checker takes the URL of your login page and reports WCAG 2.1 A and AA findings, which catches most of the contrast, label and autocomplete problems before you sit down with a screen reader. It checks against WCAG 2.1, so add the 2.2 criteria from this post, 2.5.8 and 3.3.8, to your manual pass.

FAQ

Is the default Keycloak login theme WCAG compliant?

No theme is compliant by itself, because conformance is claimed for your pages with your content and colors. The keycloak.v2 theme in 26.8.2 gives you a strong start, with labelled fields, aria-invalid, text errors and correct autocomplete values. Its field.ftl macros do not link inputs to their error text with aria-describedby, and they write an empty aria-invalid on fields with no error, which the checker flags, so fix both in your theme and then test the result.

Does WCAG 2.2 AA require prefers-reduced-motion support?

Not directly. 2.3.3 Animation from Interactions is level AAA. At AA, 2.2.2 Pause, Stop, Hide covers motion that starts on its own and runs longer than five seconds beside other content. Supporting reduced motion is still the simplest way to meet both and takes one media query.

Do one-time codes and CAPTCHAs fail Accessible Authentication?

A one-time code passes as long as users can paste it or let the browser fill it in, which the single one-time-code field allows. A puzzle that asks users to transcribe or solve something fails 3.3.8 unless there is an alternative, although recognizing objects is an allowed exception at this level.

Next steps

Run your login page through the free login accessibility checker, fix what it flags in your theme with the CSS and field.ftl change above, and then do the manual test pass. For what else is worth changing on the page, read the benefits of a custom login page for better UX.

On Skycloak, you can upload a complete Keycloak theme package on Business plans and up and assign it to your realm. If you want to ship your accessible theme without running the cluster yourself, try managed Keycloak hosting on Skycloak.

Somewhere to run this that stays patched

Everything above works the same on Skycloak, because it is real upstream Keycloak rather than a fork. What changes is who handles the upgrades, backups and security patches afterwards.

Guilliano Molaire
Written by
Founder, Skycloak

Guilliano is the founder of Skycloak and a cloud infrastructure specialist with deep expertise in product development and scaling SaaS products. He discovered Keycloak while consulting on enterprise IAM and built Skycloak to make managed Keycloak accessible to teams of every size.

© 2026 Skycloak. All Rights Reserved. Design by Yasser SolimanKeycloak™ is a trademark of the Linux Foundation. Skycloak is not affiliated with the Keycloak project.