Design guides

Compare a CSS Outline with an Independent Border

·

Use the same sample fill for an outline and a border. Move a translucent stroke across the edge, then press Tab to test it on the focus target without changing the size of the button.

Outline Generator

Compare the outside outline with the border

Set Outline width to 4 px, Outline style to Solid, Outline color to rgba(0, 0, 0, .5), and Control fill to White. Enter 4 px for Outline offset and 0 px for Corner radius.

The outline sits away from the left sample. The comparison border wraps the right sample directly. Adjust Comparison border width to 6 px to see the border add to the preview’s content box.

CSS Basic User Interface Level 4 outline propertiesCSS Backgrounds and Borders Level 3 border properties

Move the stroke inward and compare the measured colors

Change Outline offset to −6 px. The 4 px stroke now falls inside the sample edge. The background showing through the translucent stroke is the button’s fill.

The preview reports approximately 3.89:1 against the surrounding fill and 3.98:1 against white. These values describe solid color blending. A thin, curved or anti-aliased stroke and a busy background need an additional visual check.

Move the stroke inward and compare the measured colors
OffsetStroke positionSurface under the solid stroke
4 pxOutside with a gapSurrounding pale green
−6 pxInside the edgeWhite control fill

CSS Basic User Interface Level 4 outline propertiesWCAG 2.2 relative luminance and contrast ratio

Test the keyboard-only rule by tabbing

Select Keyboard focus under Outline activation. Focus Start here and press Tab. Try focus receives the ring. Tab away and check that the selected outline disappears.

Copy the stylesheet and use the outlined-control class on a real interactive element. Check that the ring is visible in each destination theme and stays clear of nearby or clipped content.

CSS Basic User Interface Level 4 outline propertiesW3C Understanding Focus Visible

Measure a 3 px inset ring on a 90 × 30 px button

Choose Focus indicator tester and reset its example. Focus Start focus test and press Tab. The black 3 px stroke sits inside the white 90 × 30 px button at offset −6 px. The ring changes 612 square CSS pixels at 21:1. The 2 px reference perimeter for this rectangle is 480 square CSS pixels.

Change Outline width to 1 px and Outline offset to zero. The contrast stays high against white, but the ring changes only 244 square CSS pixels on the surrounding canvas. Compare adjacent colors and changed pixels separately. Preview or open the exported CSS on a real box and check where the indicator might be clipped.

W3C Understanding 2.4.13 Focus AppearanceW3C Understanding 1.4.11 Non-text Contrast

Common questions

Does changing an outline resize the button?

No. An outline is painted without changing the box layout. A border can add to the measured width and height under content-box sizing.

Which declarations come from the comparison border?

The border comparison is a preview control. The downloaded stylesheet styles the outline and its sample background and radius. Use Border Generator for matching border declarations.

Why does a dark outline miss the focus area check?

The focus appearance check needs enough area to change by at least 3:1 compared with those same pixels before focus. A thin outline can have high contrast and cover too little area.

Sources

Put it into practice.

Related guides