How to remove outline border from input button

CssButton

Css Problem Overview


When I click somewhere else the border disappears, I tried to use onfocus: none, but that didn't help. How to make this ugly button border disappear when I click on it?

input[type=button] {
  width: 120px;
  height: 60px;
  margin-left: 35px;
  display: block;
  background-color: gray;
  color: white;
  border: none;
}

<input type="button" value="Example Button">

Css Solutions


Solution 1 - Css

Using outline: none; you can remove that border in chrome.

<style>
input[type=button] {
	width: 120px;
	height: 60px;
	margin-left: 35px;
	display: block;
	background-color: gray;
	color: white;
	border: none;
	outline: none;
}
</style>

Solution 2 - Css

Focus outline in Chrome and FF:

Remove Chrome button outline in CSS Remove Firefox button outline in CSS

removed button focus outline:

Button without outline in CSS

input[type=button] {
  outline:none;
}
input[type=button]::-moz-focus-inner {
  border: 0;
}

/*
  Accessibility (A11Y)
  Don't forget! User accessibility is important
*/
input[type=button]:focus {
  /* your custom focused styles here */
} 

Solution 3 - Css

It works for me simply :)

*:focus {
    outline: 0 !important;
}

Solution 4 - Css

This one worked for me

button:focus {
    border: none;
    outline: none;
}

Solution 5 - Css

Set both the outline and the box-shadow properties of the button to none and make them important.

input[type=button] {
    outline: none !important;
    box-shadow: none !important;
} 


The reason for setting the values to important is that, if you are using other CSS libraries or frameworks like Bootstrap, it might get overridden.

Solution 6 - Css

The outline property is what you need. It's shorthand for setting each of the following properties in a single declaration:

  • outline-style
  • outline-width
  • outline-color

You could use outline: none;, which is suggested in the accepted answer. You could also be more specific if you wanted:

button {
    outline-style: none;
}

Solution 7 - Css

button:focus{outline:none !important;}

add !important if it is used in Bootstrap

Solution 8 - Css

To avoid the problem caused when you change the outline property on a focus, is to give a visual effect when the user Tab on the input button or click on it.

In this case is a submit type, but you can apply to a type="button" too.

input[type=submit]:focus {
    outline: none !important;
    background-color: rgb(208, 192, 74);
}

Solution 9 - Css

Given the html below:

<button class="btn-without-border"> Submit </button>

In the css style do the following:

.btn-without-border:focus {
    border: none;
    outline: none;
}

This code will remove button border and will disable button border focus when the button is clicked.

Solution 10 - Css

As many others have mentioned, selector:focus {outline: none;} will remove that border but that border is a key accessibility feature that allows for keyboard users to find the button and shouldn't be removed.

Since your concern seems to be an aesthetic one, you should know that you can change the color, style, and width of the outline, making it fit into your site styling better.

selector:focus {
  outline-width: 1px;
  outline-style: dashed;
  outline-color: red;
}

Shorthand:

selector:focus {
  outline: 1px dashed red;
}

Solution 11 - Css

It's greatly simple than you think. When the button is focussed, apply the outline property, like this:

button:focus {
    outline: 0 !important;
}

But when I use none value, it doesn't work for me.

Solution 12 - Css

Removing nessorry accessible event not a good idea in up to standard web developments. either way if you looking for a solution removing just the outline doesn't solve the problem. you also have to remove the blue color shadow. for specific scenarios use a separate class name to isolate the this special style to your button.

.btn.focus, .btn:focus {
    outline: 0;
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, .25);
}

Better do this

.remove-border.focus, .remove-border:focus {
        outline: 0;
        box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, .25);
 }

Solution 13 - Css

Removing the outline is an accessibility nightmare. People tabbing using keyboards will never know what item they're on.

Best to leave it, as most clicked buttons will take you somewhere anyway, or if you HAVE to remove the outline then isolate it a specific class name.

.no-outline {
  outline: none;
}

Then you can apply that class whenever you need to.

Solution 14 - Css

Another alternative to restore outline when using the keyboard is to use :focus-visible. However, this doesn't work on IE :https://caniuse.com/?search=focus-visible.

Solution 15 - Css

It's also good note that outline: none can be applied to both <button> tags and input[type=button] to remove the browser-applied border on click.

Solution 16 - Css

Since Chrome and Mozilla added this line not only around buttons but also around linked text, I use on my site this:

a:focus {outline: none;
}

Works for both browsers, links, and buttons.

Btw, this did not (27.4.2021):

input[type=button]{
   outline:none;
}
input[type=button]::-moz-focus-inner {
   border: 0;
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionCindy TurlingtonView Question on Stackoverflow
Solution 1 - CssAnkit AgrawalView Answer on Stackoverflow
Solution 2 - CssRoko C. BuljanView Answer on Stackoverflow
Solution 3 - CssX-CoderView Answer on Stackoverflow
Solution 4 - Cssmnis.pView Answer on Stackoverflow
Solution 5 - CssEyoabView Answer on Stackoverflow
Solution 6 - CsshenrywrightView Answer on Stackoverflow
Solution 7 - Cssuser11173874View Answer on Stackoverflow
Solution 8 - CssA.PeraltaView Answer on Stackoverflow
Solution 9 - CssMwizaView Answer on Stackoverflow
Solution 10 - CssdaveView Answer on Stackoverflow
Solution 11 - CssGouravView Answer on Stackoverflow
Solution 12 - CssasithView Answer on Stackoverflow
Solution 13 - CssmartinedwardsView Answer on Stackoverflow
Solution 14 - CssmykView Answer on Stackoverflow
Solution 15 - CssNick AlicoView Answer on Stackoverflow
Solution 16 - CssMartinView Answer on Stackoverflow