How to remove focus border (outline) around text/input boxes? (Chrome) [duplicate]

Asked 2023-12-11 15:31:38 View 154,354

Can anyone explain how to remove the orange or blue border (outline) around text/input boxes? I think it only happens on Chrome to show that the input box is active. Here's the input CSS I'm using:

input {
    background-color: transparent;
    border: 0px solid;
    height: 20px;
    width: 160px;
    color: #CCC;
}

Text box with blue outline and "Example" written in it

  • note that oulines also appear in different cases: in IE9 you can see little dots around a button if you select it using tab (ie. you click inside a field before the button & go to the next fields using Tab until you reach the button [going to previous field is Shift + Tab]) - anyone
  • ...And in case someone needs to remove it from select elements in firefox: notes.jerzygangi.com/… - anyone
  • Use border-style: none; background-color: white; font-size: 13px; font-weight: bold; color: black; - anyone
  • As @Torkil-Johnsen mentioned in a comment below, you might want to give a different style to make it more obvious, but to just remove it is very bad for accessibility (e.g. people who only use a keyboard or other assistive device to tab through elements). - anyone
  • try this css, it work for me textarea:focus, input:focus{ border: none; } - anyone

Answers

This border is used to show that the element is focused (i.e. you can type in the input or press the button with Enter). You can remove it with outline property, though:

textarea:focus, input:focus{
    outline: none;
}

You may want to add some other way for users to know what element has keyboard focus though for usability.

Chrome will also apply highlighting to other elements such as DIV's used as modals. To prevent the highlight on those and all other elements as well, you can do:

*:focus {
    outline: none;
}


⚠️ Accessibility warning

Please notice that removing outline from input is an accessibility bad practice. Users using screen readers will not be able to see where their pointer is focused at. More info at a11yproject

Answered   2023-12-11 15:31:38

  • This is not working for me. I am using Chrome, latest update. I put input:focus {outline: 0;} in the CSS, but when I type, the blue Mac outline is still there. - anyone
  • Use outline: none - anyone
  • outline-style: none works well with Chromium (version 34) and Firefox (version 30) - anyone
  • It's bad for accessibility to remove this outline that is default on :focus. This means that users using the keyboard to navigate will have a hard time seeing which link/item is highlighted when they hit tab. If anything, the highlighting of the element should be enhanced to make it more obvious which item has focus. - anyone
  • @TorkilJohnsen, While I agree 100% that the element should be visibly focused the default blue/orange ring behaviour is not always the right strategy. As long as some strategy is adopted (and adopted consistently across a design system) then CSS should be authored to support that decision. - anyone

The current answer didn't work for me with Bootstrap 3.1.1. Here's what I had to override:

.form-control:focus {
  border-color: inherit;
  -webkit-box-shadow: none;
  box-shadow: none;
}

Answered   2023-12-11 15:31:38

  • box-shadow: none; did the trick for me. When I put in on the element without :focus it also removes a very subtle shadow that Chrome puts on border-less and input boxes. - anyone
  • This worked for me. For some reason input:focus { outline:none;} did not work. - anyone
  • This worked for me. I am using FF latest browser and outline: none is not working. - anyone
  • This solution also works for bootstrap v4. - anyone
  • On bootstrap 4, if the outline you want to remove is round the hamburger mobile menu, you can just use: <button class="navbar-toggler" style="outline:none;" ...> - anyone
input:focus {
    outline:none;
}

This will do. Orange outline won't show up anymore.

Answered   2023-12-11 15:31:38

  • Instead of input:focus{ outline: 0; } -> outline:none; Works - anyone
  • Don't do it unless you provide some other styling, it's important for accesability. see outlinenone.com - anyone
  • Actually, this CSS isn't enough. For example, if you're using JQueryUI tabs, the ugly blue border appears after you click on a tab, if you just use your CSS. You do need to add a:focus or li:focus, to prevent the border. - anyone
  • this is bad for accessibility and shouldn't be done. - anyone
  • I am working with npmjs.com/package/react-phone-number-input And this solution worked just fine. THanks - anyone
<input style="border:none" >

Worked well for me. Wished to have it fixed in html itself ... :)

Answered   2023-12-11 15:31:38

  • <input style="border:0px" > also works, as well. - anyone
  • you can triple that: input { border: 0 none transparent } - anyone
  • When I add border:none to a css class, its still showing the border for the input field. where as the inline css style="border:none" is working - anyone
  • @arun8 sounds like your CSS selector isn't the highest 'priority' (forgot the word but its like, the importance of your selector e.g p > span.class is more important than just span.class so it will use the code in p > span.class - anyone
  • @arun8 you can try using "!important" in your css class - anyone

I've found the solution.
I used: outline:none; in the CSS and it seems to have worked. Thanks for the help anyway. :)

Answered   2023-12-11 15:31:38

  • That's the focus outline you are removing. It's there for a reason: Usability. Especially keyboard users will hate it if you remove it. - anyone
  • @RoToRa what if he crafts a better one using shadows CSS 3 ? - anyone

this remove orange frame in chrome from all and any element no matter what and where is it

*:focus {
    outline: none;
}

Answered   2023-12-11 15:31:38

Solution

*:focus {
    outline: 0;
}

PS: Use outline:0 instead of outline:none on focus. It's valid and better practice.

Answered   2023-12-11 15:31:38

  • nope, not working on Chrome - anyone
  • How is it better practice? You need to explain why, not just say so. It's definitely not better practice. - anyone

Please use the following syntax to remove the border of text box and remove the highlighted border of browser style.

input {
    background-color:transparent;
    border: 0px solid;
    height:30px;
    width:260px;
}
input:focus {
    outline:none;
}

Answered   2023-12-11 15:31:38

  • Be careful with the transparent definition on the background-color attribute. You don't need that and you probably will have a big problem when you need to write something (you won't find the inputs!). By the way, personally, I would change the transparent background to select a color. For example, if my container has a red color, I would use a white background on the input. - anyone
  • For me just outline:none; won't work. But solid 0px solved for me. - anyone

Set

input:focus{
    outline: 0 none;
}

"!important" is just in case. That's not necessary. [And now it's gone. –Ed.]

Answered   2023-12-11 15:31:38

  • Don't use !important unless you REALLY MUST use it. - anyone
  • @Mackelito You must use !important to work with Bootstrap - anyone

This will definitely work. Orange outline will not show anymore.. Common for all tags:

*:focus {
    outline: none;
}

Specific to some tag, ex: input tag

input:focus {
   outline:none;
}

Answered   2023-12-11 15:31:38

I found out that you can also use:

input:focus{
   border: transparent;
}

Answered   2023-12-11 15:31:38

  • The question may have "border" in the title, but the OP is actually asking about the default outline - anyone