Is swapping out a form input's outline with box-shadow considered a violation of any WCAG guidelines?

Query

Are there any accessibility drawbacks to removing the outline CSS property and using box-shadow instead to highlight an active input? Does this approach violate WCAG guidelines?

Context

By default, user agents highlight an active element's outline when it is in focus. While customizing this highlighting using the :focus selector works well for rectangular inputs, it can cause issues with rounded inputs where the outline appears as a square. To address this, some developers replace the outline with a box-shadow which matches the shape of the input better but has raised concerns about accessibility.

Illustration

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">

Answer №1

Answer Summary

If you don't need to support IE8, using box-shadow and outline is fine with some considerations on color contrast. The current example meets guidelines, but increasing color contrast is recommended.

Detailed Answer

The key consideration is color contrast, ensuring a 3:1 ratio between border and background. Prepare for WCAG 2.2 effective from June/July 2021, which requires adequate contrast and thickness for compliance.

WCAG 2.2 Compliance

To meet upcoming regulations, the focus indicator must have sufficient contrast (3:1) against adjacent colors or be at least 2px thick. Additional rules apply to indicate focus effectively.

For more details on WCAG 2.2+ guidelines, refer to the official documentation here.

IE Compatibility

Consider compatibility with Internet Explorer (IE). If supporting IE8, avoid using box-shadow and outline. Implement a separate stylesheet for older IE versions for better design and functionality.

Limited support for IE9 and above is advisable to prevent compatibility issues and keep up with modern web standards.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Adjust the Column Alignment Without Affecting the Entire Row or Table

My inquiry revolves around altering the sort direction of a particular column within a Telerik RadGrid. Utilizing Firebug, it is possible to identify and modify the sorting direction of a table (either master or detail). However, there seems to be no desig ...

What is the best way to store a range object obtained from getSelection in order to recreate it on a separate page load?

My goal is to develop a web application that enables users to highlight selected text on a webpage with the click of a button. I want these highlights to persist even when the user returns to the page. So far, I have achieved: var selectedRange = documen ...

I am experiencing an issue where the HTTPS images are not appearing on my localhost, but when I click on the

While browsing a website, my browser is authenticated for the current session. I am utilizing their API to retrieve images from the site and displaying them on my webpage. Interestingly, directly visiting the image's URL displays the image without a ...

Incorporating docsify CSS styling into Markdown within the VScode environment

When it comes to building my blog, I've decided to go with docsify and manage my markdown files using VScode. I wanted a preview of my blog, and after noticing that <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/docsify@4/lib/t ...

Using Javscript to navigate an HTML webpage

My combo-box is set up to redirect users to a specific page. However, when using window.location.href = ..., it redirects them again when they hit the back button. On the other hand, using window.location.replace (...) prevents users from going back becaus ...

After reloading the page, VueJS and Nuxt.js cause page breaks

I've encountered a strange issue with my application. I have multiple pages and everything seems fine initially: https://i.sstatic.net/xYxxy.png However, upon reloading the page, this is what happens: https://i.sstatic.net/Jo3tz.png Upon pressing C ...

Stop all other forms from submitting

I am dealing with a situation where I have a form that contains another form inside of it. Whenever I try to submit the inner form, the outer form gets submitted as well. I am looking for a solution to submit only the inner form via ajax. Below is my twi ...

It seems that CSS shadows are working perfectly on Firefox and Chrome, but unfortunately, they are not displaying on

I have encountered an issue where CSS shadows appear fine on Firefox and Chrome, but do not display in Internet Explorer. Below is the code I am using: -moz-box-shadow: 0 0 20px #000; Can anyone provide a solution for this compatibility problem? Thank ...

Creating personalized styles for my React components with the help of styled-components

Exploring the power of styled-components for custom styling on child components has been an interesting journey for me. For instance, I recently crafted a unique card component named myCard. Take a look at how it's structured: import React from "rea ...

div element's default input border displays in a distinct manner

When I create an input box without any styles (<input>) and then inspect the computed CSS in devtools, it shows a border of 2px inset rgb(238, 238, 238). However, if I create a div with the same border properties, it looks noticeably different: ...

Issue Encountered While Attempting to Show a Div Element within a Function

Check out this HTML code snippet: <div class="div1" id ="div1" onclick="onStepClicked()" style ="text-align:center">Step 1</div> And here is the corresponding Script: function onStepClicked() { var elem = document.getElementById(&apo ...

Can JavaScript values be passed into CSS styles?

I am currently working on dynamically updating the width of a CSS line based on a JavaScript value (a percentage). The line is currently set at 30%, but I would like to replace that hard-coded value with my JavaScript variable (c2_percent) to make it mor ...

Struggling to navigate to a specific div element using a hash in an Angular application

I came across some information here and here stating that a page can be scrolled to a specific element using just a hash selector and an id attribute. However, I am facing difficulties implementing this in my Angular application. Could this be because of ...

Ways to incorporate CSS design into Django input pop-up when the input is invalid

Looking to enhance the error message styling for a Django Form CharField when an incorrect length is entered, using CSS (Bootstrap classes preferred). I have successfully styled the text input itself (check the attrs section in the code), but I am unsure ...

Encountering a DJANGO KeyError while utilizing request.session in conjunction with form.cleaned_data

I'm currently working on a project that involves two view functions. The first function is responsible for taking form data and storing it in the request session, while the second function retrieves this data to filter a search query. Additionally, I ...

Customize HTML Textbox Styles

I am currently working on customizing the appearance of textboxes and labels by applying color themes to them. My goal is to achieve a visual effect like this: https://i.sstatic.net/JdjnU.png Do you know of any tools or methods that can help me accom ...

Increasing the height of list items

I'm currently working on creating a scale using list items, and I want the height of each item to increase incrementally. So far, I haven't been able to find a solution other than adding a class to each item. Here's a fiddle demonstrating t ...

Ensuring sleek alignment in CSS flexbox by eliminating additional horizontal space caused by multi-line text

Incorporating bootstrap 4.6 and flexbox into my design, I am facing an issue with a horizontal line not filling the space between two other div elements. When the text is short, everything aligns as expected. However, when the text extends to two lines, t ...

Is there a way to modify the background color of ::before when hovering over it?

I have a ul-li list and when i hover last li ::before element looks white and not so good. I want to change it when i hover the last li element. How can I achieve this? Here are my codes: <div className="dropup-content"> <ul> & ...

What could be the reason for the fluctuating HTML output?

Exploring the world of CSS and HTML, I noticed a curious change in the output when text is added inside a div tag. First: div.bar { display: inline-block; width: 20px; height: 75px; /* We'll override height later */ background-co ...