Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What is this CSS checkbox state called, and how can I remove its effects?

Consider this checkbox:

<input type="checkbox" />

When pressing a keyboard button when this checkbox is focused, a solid black outline appears around it. I can get rid of by removing the outline:

input {
  outline: none;
}
<input type="checkbox" />

However, I wish to apply an outline to the actual element, and this method would invalidate it. I was wondering if there was a pseudoclass that could be used to select this checkbox state. If so, what is it called and how do I access it? If not, is there any other viable way (CSS only) to do achieve this? I thought the :focused pseudoclass would work, but this selects the focused state of the checkbox and not whatever this state is, when the checkbox is focused and a key is pressed.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

P.S. when I add an outline to the checkbox, the problem appears in a different format. The outline is somehow "extended", almost as if a padding or border was added to the element (try focusing on the following checkbox and pressing a key):

input {
  outline: solid red 3px;
}
<input type="checkbox" />

>Solution :

I think outline-offset: 0px; under the element state focus-visible is what you’re looking for:

input {
  outline: solid red 3px;
}

input:focus-visible
{
  outline-offset: 0px;
}
<input type="checkbox" />
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading