skip to content

What does Angular Material 22's `mat.strong-focus-indicators()` mixin change about keyboard focus, and how do you adjust its outline?

level: seniorimportance: should knowfreq 24%

answer

  1. default focus is only a tint
  2. outline drawn on :focus-visible
  3. secondary color by default
  4. border color, style, width, radius
  5. contrast fix per container

basics

~20 s

Most Angular Material components show focus only as a faint background tint by default. mat.strong-focus-indicators() turns on a visible keyboard-focus outline, 3px solid in the theme's secondary color by default; a config map and strong-focus-indicators-theme adjust it.

solid answer

~40 s

Interactive Material components such as buttons, checkboxes, radios, chips, tabs, list and menu items render a focus-indicator element whose outline is hidden by default, because the Material Design default is a state-layer tint. Including `mat.strong-focus-indicators()` in the theme file sets CSS variables that display that outline, drawn as a border on a pseudo-element when the element matches `:focus-visible`, so it appears for keyboard focus and usually not for a mouse click. With no config it is 3px solid with a 4px radius in `var(--mat-sys-secondary)`. Pass a map with `border-color`, `border-style`, `border-width` and `border-radius` to restyle it, and include `mat.strong-focus-indicators-theme($color)` under a selector where the default color lacks contrast, such as a dark banner. In high-contrast mode the indicator is shown even without the mixin.

code

scss · 15 lines
scss
@use '@angular/material' as mat;

html {
  color-scheme: light dark;
  @include mat.theme((color: mat.$azure-palette, typography: Roboto));
  @include mat.strong-focus-indicators((
    border-width: 2px,
    border-radius: 6px,
  ));
}

// The dark brand header needs a lighter outline
.portal-header {
  @include mat.strong-focus-indicators-theme(white);
}

go deeper

for a junior

Recall that Material's default focus is a subtle tint and that mat.strong-focus-indicators() turns on a visible outline.

for a middle

Explain the hidden focus-indicator element, the :focus-visible trigger, the default 3px secondary-color outline and the four border keys.

for a senior

Fix contrast by region with strong-focus-indicators-theme, know which components carry the indicator, and plan focus styles for custom components alongside it.

for a principal

Decide whether strong focus indicators are on by default across the product's apps, weighing visual noise against an accessibility requirement the team must meet everywhere.

## The default focus treatment Material Design shows keyboard focus on most components by changing the component's **state layer**, a translucent tint over its background. On a pale surface that change can be subtle, and it can fall short of what an accessibility review expects from a visible focus indicator. Angular Material therefore ships an opt-in alternative: **strong focus indicators**, an outline drawn around the focused element. ## How it works Interactive components render a dedicated element with the class `mat-focus-indicator`. In the source this includes buttons, button toggles, checkboxes, radios, slide toggles, sliders, chips, tabs and tab links, list items, menu items, options, expansion panel headers, sort headers, stepper headers and datepicker cells. Cards and other non-interactive components do not have one. The indicator is a pseudo-element on that element, styled from CSS variables: - `--mat-focus-indicator-display` defaults to `none`, so nothing shows; - border width, style, color and radius each have their own variable with defaults of 3px, solid, transparent and 4px; - the outline is drawn only while the component matches `:focus-visible`, the browser's heuristic for focus that should be shown, which usually means keyboard focus rather than a mouse click. Including the mixin sets those variables: ```scss @use '@angular/material' as mat; html { @include mat.theme((color: mat.$azure-palette)); @include mat.strong-focus-indicators(); } ``` With no config the outline becomes visible, with its color set to `var(--mat-sys-secondary)` (falling back to black when no theme variables exist). Include it once, in the global theme file, next to the theme. ## Customising the outline | Want | Use | |---|---| | A different shape or weight everywhere | `mat.strong-focus-indicators((border-color: ..., border-style: ..., border-width: ..., border-radius: ...))` | | A different color in one region | `mat.strong-focus-indicators-theme($color)` under that region's selector | | A color from a Sass theme object | `mat.strong-focus-indicators-theme($theme)`, which uses the theme's primary color | Only those four border keys are documented for the config map. The theme mixin is the tool for contrast problems: a registration portal whose header is a dark brand color can include `mat.strong-focus-indicators-theme(white)` under `.portal-header`, and the buttons there get a white outline while the rest of the app keeps the secondary color. ## Things to know before turning it on 1. It is global by design. The variables are inherited, so the outline appears on every interactive Material component under the selector; a top-level include lands on `html`. 2. High-contrast mode already shows the indicator. Angular Material enables it inside forced-colors high-contrast mode even when the mixin is absent. 3. It needs room. Because the outline sits on the component's own box, the mixin also makes chip labels overflow-visible so the outline is not clipped; a parent of your own with `overflow: hidden` can still clip it. 4. It is not a focus-management tool. Where focus goes when a dialog opens, or how focus moves through a list, is decided elsewhere; this mixin only changes what focus looks like. ## Checking the result Turning the mixin on is quick; confirming it does the job takes a short routine: 1. Tab through a representative page, such as a registration form with buttons, checkboxes, radios and tabs, and confirm every stop shows the outline. 2. Click the same controls with a mouse and confirm the outline does not appear where the browser does not apply `:focus-visible`. 3. Check the outline against every background it can sit on, including dark headers, colored panels and both color schemes; add `strong-focus-indicators-theme` where it disappears. 4. Emulate forced colors in the browser's developer tools and confirm the indicator still shows. 5. Tab onto your own custom controls; they need their own `:focus-visible` styles, since the mixin does not reach them. ## Common mistakes - Expecting the outline on mouse clicks and treating its absence as a bug. - Writing `outline` rules against internal classes instead of using the config map. - Leaving the default secondary-color outline on a background it does not contrast with. - Assuming custom components get the outline automatically; only elements carrying the focus-indicator element do.

  • Why does a user who clicks a Material button with the mouse not see the strong focus outline?
    The outline is drawn only when the element matches `:focus-visible`, and browsers usually do not apply that state to a button focused by a pointer click. Keyboard focus, such as tabbing, does match it, which is the case the indicator exists for.
  • Does `mat.strong-focus-indicators()` add an outline to your own custom components?
    No. It styles the focus-indicator element that Material's interactive components render. A custom component needs its own `:focus-visible` styles, which can reuse system variables such as `--mat-sys-secondary` to match.

  • Thinks Material components show a strong outline on focus by default.
  • Expects the strong outline to appear on mouse clicks too.
  • Says the default outline color is the theme's primary color.
  • Passes outline-color or outline-width keys to the mixin's config map.
  • Believes the mixin also controls where focus moves in dialogs.