How to remove outline border from input button
Asked Answered
M

17

219

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">
Moresque answered 10/11, 2013 at 6:8 Comment(3)
looks fine on my mozilla browserPhilanthropic
The focus rectangle is supposed to help the user observe that the click was effective and thereby prevent him from accidentally clicking twice. So are you sure you are solving a problem and not creating one?Erikerika
A good read a11yproject.com/posts/never-remove-css-outlinesBulgar
A
316

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>
Aedes answered 10/11, 2013 at 6:14 Comment(2)
On Chrome, I had to add outline: none; rule to input[type="button"]:focus rather than input[type="button"].Minimus
Works in Microsoft Edge tooEmmery
E
103

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

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

/*
  Accessibility (A11Y)
  Don't forget! User accessibility is important
*/
button:focus,
input[type=button]:focus {
  /* your custom focused styles here */
} 
Eisler answered 10/11, 2013 at 6:17 Comment(0)
B
93

It works for me simply :)

*:focus {
    outline: 0 !important;
}
Bokbokhara answered 1/12, 2014 at 9:29 Comment(4)
This is the only answer that worked for me, but how would you do it without !important? I've heard from a lot of sources that you should only use it only if absolutely necessary.Athey
I did this button styling for whole application in external css. If u want ignore it u can do it with #id in css using that in each button: #button-tyle{ outline: 0; } or use same style for all buttons without #id in each button, here is a demo link: input[type="button"] { width:70px; height:30px; margin-left:72px; margin-top:15px; display:block; background-color:gray; color:white; border: none; outline: 0; }Bokbokhara
To remove blue background color onclick i added -> *{ -webkit-tap-highlight-color: transparent !important; }Lawler
This worked first time perfectly - Thanks!Immolation
B
39

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.
Bathsheeb answered 13/6, 2020 at 15:11 Comment(1)
The box-shadow works for me on Edge, nice : )Monck
D
34

This one worked for me

button:focus {
    border: none;
    outline: none;
}
Decumbent answered 8/6, 2017 at 20:27 Comment(0)
P
18

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;
}
Preconize answered 28/4, 2016 at 10:34 Comment(0)
D
11
button:focus{outline:none !important;}

add !important if it is used in Bootstrap

Dunston answered 9/3, 2019 at 2:30 Comment(1)
I think the asker already tried this, after all, the question says tried onfocus none, but didn't help.Resuscitator
M
6

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);
}
Morganmorgana answered 4/10, 2019 at 17:38 Comment(0)
D
3

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.

Devaney answered 4/6, 2018 at 7:8 Comment(0)
F
3

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;
}
Fraze answered 7/2, 2019 at 16:51 Comment(0)
E
3

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.

Expressway answered 11/3, 2019 at 13:21 Comment(0)
V
3

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);
 }
Venatic answered 23/12, 2019 at 5:59 Comment(0)
W
2

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.

Whelm answered 27/4, 2018 at 14:29 Comment(0)
S
2

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.

Semipostal answered 8/11, 2020 at 10:51 Comment(0)
T
0

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;
}
Terribly answered 27/4, 2021 at 15:18 Comment(0)
N
-1

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.

Nepil answered 21/2, 2021 at 16:50 Comment(0)
G
-1

Use the below css:

.btn {
  border: none !important;
  background-color: white;
}

Try with this, you have to make

border: none !important
Gillard answered 10/9, 2023 at 16:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.