ChatGPT解决这个技术问题 Extra ChatGPT

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

This question already has answers here: How to remove the border highlight on an input text element (20 answers) Closed 7 years ago.

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;
}

https://i.stack.imgur.com/HSKYf.png

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])
...And in case someone needs to remove it from select elements in firefox: notes.jerzygangi.com/…
Use border-style: none; background-color: white; font-size: 13px; font-weight: bold; color: black;
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).
try this css, it work for me textarea:focus, input:focus{ border: none; }

C
CommonSenseCode

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


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.
Use outline: none
outline-style: none works well with Chromium (version 34) and Firefox (version 30)
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.
@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.
j
johannchopin

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;
}

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.
This worked for me. For some reason input:focus { outline:none;} did not work.
This worked for me. I am using FF latest browser and outline: none is not working.
This solution also works for bootstrap v4.
On bootstrap 4, if the outline you want to remove is round the hamburger mobile menu, you can just use:
j
johannchopin
input:focus {
    outline:none;
}

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


Instead of input:focus{ outline: 0; } -> outline:none; Works
Don't do it unless you provide some other styling, it's important for accesability. see outlinenone.com
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.
this is bad for accessibility and shouldn't be done.
K
Kailas
<input style="border:none" >

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


also works, as well.
you can triple that: input { border: 0 none transparent }
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
@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
@arun8 you can try using "!important" in your css class
J
Joey Morani

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


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.
@RoToRa what if he crafts a better one using shadows CSS 3 ?
j
johannchopin

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

*:focus {
    outline: none;
}

j
johannchopin

Solution

*:focus {
    outline: 0;
}

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


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

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;
}

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.
I
Ivanka Todorova

Set

input:focus{
    outline: 0 none;
}

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


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

I found out that you can also use:

input:focus{
   border: transparent;
}

The question may have "border" in the title, but the OP is actually asking about the default outline
h
hichris123

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;
}