WCAG: Firefox and Edge don't show outline on focussed input elements when styles are applied

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



WCAG: Firefox and Edge don't show outline on focussed input elements when styles are applied



I'm creating a form, that is following some WCAG guidelines. One of those is:



G165: Using the default focus indicator for the platform so that high visibility default focus indicators will carry over.



The summary of this rule is:



Operating systems have a native indication of focus, which is available in many user agents. The default rendering of the focus indicator isn't always highly visible and may even be difficult to see against certain backgrounds. However, many platforms allow the user to customize the rendering of this focus indicator. Assistive technology can also change the appearance of the native focus indicator. If you use the native focus indicator, any system-wide settings for its visibility will carry over to the Web page. If you draw your own focus indicator, for example by coloring sections of the page in response to user action, these settings will not carry over, and AT will not usually be able to find your focus indicator.



(emphasis mine)



In order to comply with this rule, I want to keep the OS' default focus indicator for form elements.



However, I'm facing different problems here.



In Firefox on macOS:



As soon as the I change the style of the element (e.g. by changing the border settings), the default focus gets lost1.



This is strange as border and outline are different style attributes.


border


outline



In Firefox and Edge on Windows:



The browsers show a focus indicator that is only a differently colored border, when entering a form element – as long as it's unstyled. Chrome on the other hand does have an indicator as an outline – like on macOS2.



Here's a snippet to demonstrate the behaviour (alternatively try this fiddle):




.b
border: 1px solid red;


<form>
<input class="a" type="text">
<input class="b" type="text">
</form>



As a sidenote: There is no difference in the behaviour if label-elements are present or not.


label



My questions are:



With these issues, I wonder whether this rule is even possible to achieve. In the end maybe I must manually set outline on focus to get the same behaviour in all browsers and skip this rule.


outline


focus



1 Here's a screenshot showing the problem on macOS:





2 Here's a screenshot showing the problem on Windows:







What version of Firefox are you using? Even unstyled textboxes don't look like that when focused.
– TylerH
Aug 3 at 14:23





@TylerH The screenshot is from Firefox 61 on macOS 10.13. I re-checked this on Firefox on a PC with Windows 10 and it really does look differently. It seems that Firefox and Edge don't show an outline at all on Windows even with default styles. Maybe I need to rephrase my question to address that issue.
– lampshade
Aug 6 at 9:29





"Why are there no focus indicators in Firefox and Edge on Windows by default?" There are, even in the snippet you've provided. Firefox activates it only on keyboard focus, and Edge's is very subtle.
– BoltClock
Aug 6 at 11:07






@BoltClock Ok, now I see what the WCAG says in the second sentence "The default rendering of the focus indicator isn't always highly visible […]". I didn't really notice the change on focus at first - I blame my VM. :D I've updated the question accordingly. Thanks very much for pointing that out.
– lampshade
Aug 6 at 12:15





@TylerH: I mean, there is more to this than just Firefox and Edge displaying default focus indicators...
– BoltClock
Aug 6 at 14:12




3 Answers
3



Each browser has its own properties. As I searched you should code like below:


input.b
border: 1px solid #f00;
-webkit-appearance: none;
-moz-appearance: none;


input.b:focus
outline: none;
box-shadow: 0 0 1px 1px #0a0;



If you wanna read more about this concept, See MDN Docs to understand.



Hope, my answer helps you.





Thank you. This is basically the same answer as two other people wrote already. How to style forms and how to use CSS is not what the question is about. The actual question is: “How to comply to G165 but still be able to style form elements individually throughout different OS’ and browsers?” If your answer is a solution to this question, then please add an explanation why.
– lampshade
Aug 13 at 7:56





@lampshade, I can not understand your comment's meaning, Actually, every browser has its own realization about HTML and CSS codes. All the more interesting is that each browser has different behavior in the different OS. Definitely for UI development you should use CSS reset. this reset makes a consistent User Interface for all browsers in all OSes, So, your code will be see consistent. there is it. nothing else.
– AmerllicA
Aug 13 at 9:52


HTML


CSS


UI


CSS reset





I'm trying to follow: "If you draw your own focus indicator, for example by coloring sections of the page in response to user action, these settings will not carry over, and AT will not usually be able to find your focus indicator." Which I interprete as: Leave the browser's default indicator so that a custom OS indicator is shown in the browser as well. - in other words: If you reset the CSS for the indicator, the custom one is not shown. If all browser use different properties for their default indicator, how can I leave it but be able to style the element (especially the border)?
– lampshade
Aug 13 at 10:02



As you've notced already, appearance and behaviour of form elements are implementation-based and differs from browser to browser.



Every form element has its browser-default appearance -- a set of styles such as border, background etc.


border


background



When you're trying to change default styles, browser may override them rule-by-rule (as Chrome does) or discard the default appearance at all (as Firefox does).



So if you want to have the same appearance in "all" browsers you have to set it explicitly.



E.g.:




.b
border: 1px solid red;
-moz-appearance: none;
-webkit-appearance: none;


.b:focus
outline: none;
box-shadow: 0 0 2px 2px lime


<input class="a" type="text">
<input class="b" type="text">



Read more here.





Thanks for your answer. I don't understand what specs Firefox is following here as the focus should be set by outline and not border - at least as far as I understand it. Could you back this up with some source to understand the behaviour? Your solution will display an unstyled element as soon as it gets the focus, which unfortunately doesn't seem practicable - but nice idea anyway.
– lampshade
Aug 6 at 10:11



outline


border





@lampshade, thank you, I've updated my answer.
– Kosh Very
Aug 6 at 16:24





Thanks for your update and effort. While all of your answer is true, my issue is different. I don't need to have the same look across all browsers for the focus indicator - only for the element itself. In fact I want it to be the default one because I want to follow the recommendation by the WCAG guideline. But it seems not to be possible cross browser because some seem to use the border instead of the outline for displaying it.
– lampshade
Aug 8 at 8:05





@lampshade, each and every browser have it's own methodology render DOM element. we can override default CSS.
– hardik solanki
Aug 8 at 12:42





@lampshade, thank you for your note. As I can see Firefox, Opera, Safari, Chrome use outline, IE and Edge use border. But could you please clarify where in the WCAG spec they say outline CSS property must be used (I cannot find it)?
– Kosh Very
Aug 8 at 15:11



The CSS outline property does exist and you can use it like this:


outline




.b
border: 1px solid red;
-moz-appearance: none;
-webkit-appearance: none;


input:focus
outline: 2px solid #2772DB;


<input class="a" type="text">
<input class="b" type="text">



If its not working or showing up, that may mean there is another style overlapping it so you can override it by adding !important


!important





Thanks for your answer. This is basically the same as Kosh has written. The question is not about how CSS works or what outline and border properties are. The question is basically: How to keep the default focus indicator of the browser while styling an input element, so that a custom focus indicator of the OS can be inheritet. Maybe the answer is, that a custom focus indicator is inheritet no matter what or that it's not possible to achieve this cross OS and cross browser - but I'm still hoping. :)
– lampshade
Aug 9 at 9:26



outline


border






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard