Check Borders and Focus Rings

Every text color in Bea’s catalogue now passes AA in both themes, with its ratios beside its token. Text isn’t all that people need to see, though. Someone filling in a form has to find each field, and someone who moves through the page with the keyboard has to see which control they’re on.

In this lesson, you’ll decide which contrast rule applies to each part of a page, measure a field’s border and a focus ring in both themes, and fix the ring where it falls short. You’ll also measure one more kind of text: a name printed over a photo. Start with the borrow form that came with the starting site.

Measure a Field’s Border

Bea’s neighbors ask for seeds through the borrow form at the bottom of the catalogue page, part of the starting site you downloaded. Its labels and typed text fall under 1.4.3, but a field’s edge isn’t text, so it falls under a second criterion.

1.4.11 Non-text Contrast, also at Level AA, covers the parts that show what a control is and what state it’s in, such as a field’s border, a checkbox’s tick, or a focus indicator. Each needs at least 3:1 against the colors next to it. So do graphics that people need to understand the content, such as the icon on a button that has no text.

Like 1.4.3, it exempts an inactive control, such as a button with the disabled attribute. Nobody can operate it, so neither its edges nor its text need a minimum ratio. Every control people can use does.

The form’s fields get their edges from this rule in the starting stylesheet’s components layer:

Language: CSS
  .borrow-form input {
    padding: 0.5rem;
    border: 1px solid var(--color-border);
    border-radius: 0.25rem;
    font: inherit;
    color: var(--color-text);
    background-color: var(--color-surface);
  }

Each field’s background uses the page’s --color-surface, so its border meets the same color on both sides, and that’s the pair to measure.

Check Light in the theme switch and scroll down. The form sits under the seed cards, with each field outlined in the strong green:

The light catalogue with three seed cards and, below them, a Borrow Seeds form with three labeled fields outlined in green and a terracotta Send request button.
The Borrow Form Under the Catalogue

The color picker shows a ratio only for a color declaration, measured against the element’s own background. To measure a border, you temporarily apply its color to text. Select the <body> element, whose background is the surface, and in element.style at the top of the Styles pane, add color: var(--color-border). Then open the picker from that declaration’s swatch.

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Become a Member to join the conversation.