Question
What accessibility downsides are there to set outline
to none
and instead use box-shadow
to highlight an active input? Does it violate WCAG at all?
Background
User agent style sheets highlight an active element's outline
on focus. To customize this highlighting we can use the :focus
selector. This works well for rectangular shaped input elements, but doesn't look good on rounded inputs. A mismatching square is displayed. See below example where the red outline is square even though the input has rounded corners.
As outline
is rectangular, to better match a rounded element, an alternative way to style is to replace outline
with box-shadow
. This require setting outline: none
, which seems controversial from an accessibility perspective.
Example
input {
border-radius: 999em;
padding: 10px;
}
.outline:focus {
outline: solid 15px red;
}
.box-shadow:focus {
outline: none;
box-shadow: 0 0 0 15px red;
}
<label for="with-outline">Outline</label>
<input name="with-outline" id="with-outline" class="outline">
<hr>
<label for="with-box-shadow">Box Shadow</label>
<input name="with-box-shadow" id="with-box-shadow" class="box-shadow">