[css] How to remove the border highlight on an input text element

When an HTML element is 'focused' (currently selected/tabbed into), many browsers (at least Safari and Chrome) will put a blue border around it.

For the layout I am working on, this is distracting and does not look right.

<input type="text" name="user" class="middle" id="user" tabindex="1" />

Firefox does not seem to do this, or at least, will let me control it with:

border: x;

If someone can tell me how IE performs, I would be curious.

Getting Safari to remove this little bit of flare would be nice.

This question is related to css input safari webkit border

The answer is


Update 2020 - :focus-visible

Good news for accessibility - Chrome & Firefox just added support for :focus-visible.

Hiding focus styles is bad practice due to accessibility requirements (keyboard navigation) which makes your websites less accessible.

Use :focus-visible pseudo-class and let the browser to determinate when to apply focus.

:focus-visible /* Chrome */

Note that Firefox supports similar functionality through an older, prefixed pseudo-class:

:-moz-focusring /* Firefox */

_x000D_
_x000D_
button {
  color: #000;
  background-color: #fff;
  padding: 10px 16px;
  margin: 10px 0;
  border-radius: 4px;
}

button:focus {
  box-shadow: 0 0 0 2px #E59700;
  outline: 0;
}

button:hover {
  background-color: #eee;
}

button.with-focus-visible:focus:not(:focus-visible) {
  box-shadow: none;
  outline: 0;
}

button.with-focus-visible:focus-visible, 
button.with-focus-visible:moz-focusring {
  box-shadow: 0 0 0 2px #E59700;
  outline: 0;
}
_x000D_
<p>Click on the button using a mouse. Then try tabbing to the button.</p>
<button>without :focus-visible</button>
<button class="with-focus-visible">with :focus-visible</button>
_x000D_
_x000D_
_x000D_

docs: https://developer.mozilla.org/en-US/docs/Web/CSS/:focus-visible

w3 specifications: https://www.w3.org/TR/selectors-4/#the-focus-visible-pseudo


This was confusing me for some time until I discovered the line was neither a border or an outline, it was a shadow. So to remove it I had to use this:

input:focus, input.form-control:focus {

    outline:none !important;
    outline-width: 0 !important;
    box-shadow: none;
    -moz-box-shadow: none;
    -webkit-box-shadow: none;
}

Remove the outline when focus is on element, using below CSS property:

input:focus {
    outline: 0;
}

This CSS property removes the outline for all input fields on focus or use pseudo class to remove outline of element using below CSS property.

.className input:focus {
    outline: 0;
} 

This property removes the outline for selected element.


You could use CSS to disable that! This is the code I use for disabling the blue border:

*:focus {
    outline: none;
}

This is a working example


Try this:

*:focus {
    outline: none;
}

This would affect all your pages.


You can remove the orange or blue border (outline) around text/input boxes by using: outline:none

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

Use this code:

input:focus {
    outline: 0;
}

This is an old thread, but for reference it's important to note that disabling an input element's outline is not recommended as it hinders accessibility.

The outline property is there for a reason - providing users with a clear indication of keyboard focus. For further reading and additional sources about this subject see http://outlinenone.com/


You can try this also

input[type="text"] {
outline-style: none;
}

or

.classname input{
outline-style: none;
}

The only solutiion that worked with me

The border is actually a shadow. So to hide it I had to do this:

input[type="text"]:focus{
     box-shadow: 0 0 0 rgb(255, 255, 255);
}

 input[type="checkbox"]:focus{
      box-shadow: 0 0 0 rgb(255, 255, 255);
 }

In Bootstrap 4 to remove border outline you can use shadow-none, it will remove focus outline.

            <div class="form-group">
                <label for="exampleInputEmail1">Name</label>
                <input type="text" class="form-control form-control shadow-none" 
                id="exampleInputEmail1"aria-describedby="emailHelp">
            </div>

This is a common concern.

The default outline that browsers render is ugly.

See this for example:

_x000D_
_x000D_
form,_x000D_
label {_x000D_
  margin: 1em auto;_x000D_
}_x000D_
_x000D_
label {_x000D_
  display: block;_x000D_
}
_x000D_
<form>_x000D_
  <label>Click to see the input below to see the outline</label>_x000D_
  <input type="text" placeholder="placeholder text" />_x000D_
</form>
_x000D_
_x000D_
_x000D_


The most common "fix" that most recommend is outline:none - which if used incorrectly - is disaster for accessibility.


So...of what use is the outline anyway?

There's a very dry-cut website I found which explains everything well.

It provides visual feedback for links that have "focus" when navigating a web document using the TAB key (or equivalent). This is especially useful for folks who can't use a mouse or have a visual impairment. If you remove the outline you are making your site inaccessible for these people.

Ok, let's try it out same example as above, now use the TAB key to navigate.

_x000D_
_x000D_
form,_x000D_
label {_x000D_
  margin: 1em auto;_x000D_
}_x000D_
_x000D_
label {_x000D_
  display: block;_x000D_
}
_x000D_
<form>_x000D_
  <label>Click on this text and then use the TAB key to naviagte inside the snippet.</label>_x000D_
  <input type="text" placeholder="placeholder text" />_x000D_
</form>
_x000D_
_x000D_
_x000D_

Notice how you can tell where the focus is even without clicking the input?

Now, let's try outline:none on our trusty <input>

So, once again, use the TAB key to navigate after clicking the text and see what happens.

_x000D_
_x000D_
form,_x000D_
label {_x000D_
  margin: 1em auto;_x000D_
}_x000D_
_x000D_
label {_x000D_
  display: block;_x000D_
}_x000D_
_x000D_
input {_x000D_
  outline: none;_x000D_
}
_x000D_
<form>_x000D_
  <label>Click on this text and then use the TAB key to naviagte inside the snippet.</label>_x000D_
  <input type="text" placeholder="placeholder text" />_x000D_
</form>
_x000D_
_x000D_
_x000D_

See how it's more difficult to figure out where the focus is? The only telling sign is the cursor blinking. My example above is overly simplistic. In real-world situations, you wouldn't have only one element on the page. Something more along the lines of this.

_x000D_
_x000D_
.wrapper {_x000D_
  width: 500px;_x000D_
  max-width: 100%;_x000D_
  margin: 0 auto;_x000D_
}_x000D_
_x000D_
form,_x000D_
label {_x000D_
  margin: 1em auto;_x000D_
}_x000D_
_x000D_
label {_x000D_
  display: block;_x000D_
}_x000D_
_x000D_
input {_x000D_
  outline: none;_x000D_
}
_x000D_
<div class="wrapper">_x000D_
_x000D_
  <form>_x000D_
    <label>Click on this text and then use the TAB key to naviagte inside the snippet.</label>_x000D_
    <input type="text" placeholder="placeholder text" />_x000D_
    <input type="text" placeholder="placeholder text" />_x000D_
    <input type="text" placeholder="placeholder text" />_x000D_
    <input type="text" placeholder="placeholder text" />_x000D_
    <input type="text" placeholder="placeholder text" />_x000D_
    <input type="text" placeholder="placeholder text" />_x000D_
  </form>_x000D_
_x000D_
  <form>_x000D_
    First name:<br>_x000D_
    <input type="text" name="firstname"><br> Last name:<br>_x000D_
    <input type="text" name="lastname">_x000D_
  </form>_x000D_
_x000D_
_x000D_
  <form>_x000D_
    <input type="radio" name="gender" value="male" checked> Male<br>_x000D_
    <input type="radio" name="gender" value="female"> Female<br>_x000D_
    <input type="radio" name="gender" value="other"> Other_x000D_
  </form>_x000D_
_x000D_
_x000D_
_x000D_
  <form>_x000D_
    <label for="GET-name">Name:</label>_x000D_
    <input id="GET-name" type="text" name="name">_x000D_
  </form>_x000D_
_x000D_
_x000D_
  <form>_x000D_
    <label for="POST-name">Name:</label>_x000D_
    <input id="POST-name" type="text" name="name">_x000D_
  </form>_x000D_
_x000D_
_x000D_
  <form>_x000D_
    <fieldset>_x000D_
      <legend>Title</legend>_x000D_
      <input type="radio" name="radio" id="radio">_x000D_
      <label for="radio">Click me</label>_x000D_
    </fieldset>_x000D_
  </form>_x000D_
_x000D_
</div>
_x000D_
_x000D_
_x000D_

Now compare that to the same template if we keep the outline:

_x000D_
_x000D_
.wrapper {_x000D_
  width: 500px;_x000D_
  max-width: 100%;_x000D_
  margin: 0 auto;_x000D_
}_x000D_
_x000D_
form,_x000D_
label {_x000D_
  margin: 1em auto;_x000D_
}_x000D_
_x000D_
label {_x000D_
  display: block;_x000D_
}
_x000D_
<div class="wrapper">_x000D_
_x000D_
  <form>_x000D_
    <label>Click on this text and then use the TAB key to naviagte inside the snippet.</label>_x000D_
    <input type="text" placeholder="placeholder text" />_x000D_
    <input type="text" placeholder="placeholder text" />_x000D_
    <input type="text" placeholder="placeholder text" />_x000D_
    <input type="text" placeholder="placeholder text" />_x000D_
    <input type="text" placeholder="placeholder text" />_x000D_
    <input type="text" placeholder="placeholder text" />_x000D_
  </form>_x000D_
_x000D_
  <form>_x000D_
    First name:<br>_x000D_
    <input type="text" name="firstname"><br> Last name:<br>_x000D_
    <input type="text" name="lastname">_x000D_
  </form>_x000D_
_x000D_
_x000D_
  <form>_x000D_
    <input type="radio" name="gender" value="male" checked> Male<br>_x000D_
    <input type="radio" name="gender" value="female"> Female<br>_x000D_
    <input type="radio" name="gender" value="other"> Other_x000D_
  </form>_x000D_
_x000D_
_x000D_
_x000D_
  <form>_x000D_
    <label for="GET-name">Name:</label>_x000D_
    <input id="GET-name" type="text" name="name">_x000D_
  </form>_x000D_
_x000D_
_x000D_
  <form>_x000D_
    <label for="POST-name">Name:</label>_x000D_
    <input id="POST-name" type="text" name="name">_x000D_
  </form>_x000D_
_x000D_
_x000D_
  <form>_x000D_
    <fieldset>_x000D_
      <legend>Title</legend>_x000D_
      <input type="radio" name="radio" id="radio">_x000D_
      <label for="radio">Click me</label>_x000D_
    </fieldset>_x000D_
  </form>_x000D_
_x000D_
</div>
_x000D_
_x000D_
_x000D_

So we have established the following

  1. Outlines are ugly
  2. Removing them makes life more difficult.

So what's the answer?

Remove the ugly outline and add your own visual cues to indicate focus.

Here's a very simple example of what I mean.

I remove the outline and add a bottom border on :focus and :active. I also remove the default borders on the top, left and right sides by setting them to transparent on :focus and :active (personal preference)

_x000D_
_x000D_
form,_x000D_
label {_x000D_
  margin: 1em auto;_x000D_
}_x000D_
_x000D_
label {_x000D_
  display: block;_x000D_
}_x000D_
_x000D_
input {_x000D_
  outline: none_x000D_
}_x000D_
_x000D_
input:focus,_x000D_
input:active {_x000D_
  border-color: transparent;_x000D_
  border-bottom: 2px solid red_x000D_
}
_x000D_
<form>_x000D_
  <label>Click to see the input below to see the outline</label>_x000D_
  <input type="text" placeholder="placeholder text" />_x000D_
</form>
_x000D_
_x000D_
_x000D_

So, we try the approach above with our "real-world" example from earlier:

_x000D_
_x000D_
.wrapper {_x000D_
  width: 500px;_x000D_
  max-width: 100%;_x000D_
  margin: 0 auto;_x000D_
}_x000D_
_x000D_
form,_x000D_
label {_x000D_
  margin: 1em auto;_x000D_
}_x000D_
_x000D_
label {_x000D_
  display: block;_x000D_
}_x000D_
_x000D_
input {_x000D_
  outline: none_x000D_
}_x000D_
_x000D_
input:focus,_x000D_
input:active {_x000D_
  border-color: transparent;_x000D_
  border-bottom: 2px solid red_x000D_
}
_x000D_
<div class="wrapper">_x000D_
_x000D_
  <form>_x000D_
    <label>Click on this text and then use the TAB key to naviagte inside the snippet.</label>_x000D_
    <input type="text" placeholder="placeholder text" />_x000D_
    <input type="text" placeholder="placeholder text" />_x000D_
    <input type="text" placeholder="placeholder text" />_x000D_
    <input type="text" placeholder="placeholder text" />_x000D_
    <input type="text" placeholder="placeholder text" />_x000D_
    <input type="text" placeholder="placeholder text" />_x000D_
  </form>_x000D_
_x000D_
  <form>_x000D_
    First name:<br>_x000D_
    <input type="text" name="firstname"><br> Last name:<br>_x000D_
    <input type="text" name="lastname">_x000D_
  </form>_x000D_
_x000D_
_x000D_
  <form>_x000D_
    <input type="radio" name="gender" value="male" checked> Male<br>_x000D_
    <input type="radio" name="gender" value="female"> Female<br>_x000D_
    <input type="radio" name="gender" value="other"> Other_x000D_
  </form>_x000D_
_x000D_
_x000D_
_x000D_
  <form>_x000D_
    <label for="GET-name">Name:</label>_x000D_
    <input id="GET-name" type="text" name="name">_x000D_
  </form>_x000D_
_x000D_
_x000D_
  <form>_x000D_
    <label for="POST-name">Name:</label>_x000D_
    <input id="POST-name" type="text" name="name">_x000D_
  </form>_x000D_
_x000D_
_x000D_
  <form>_x000D_
    <fieldset>_x000D_
      <legend>Title</legend>_x000D_
      <input type="radio" name="radio" id="radio">_x000D_
      <label for="radio">Click me</label>_x000D_
    </fieldset>_x000D_
  </form>_x000D_
_x000D_
</div>
_x000D_
_x000D_
_x000D_

This can be extended further by using external libraries that build on the idea of modifying the "outline" as opposed to removing it entirely like Materialize

You can end up with something that is not ugly and works with very little effort

_x000D_
_x000D_
body {_x000D_
  background: #444_x000D_
}_x000D_
_x000D_
.wrapper {_x000D_
  padding: 2em;_x000D_
  width: 400px;_x000D_
  max-width: 100%;_x000D_
  text-align: center;_x000D_
  margin: 2em auto;_x000D_
  border: 1px solid #555_x000D_
}_x000D_
_x000D_
button,_x000D_
.wrapper {_x000D_
  border-radius: 3px;_x000D_
}_x000D_
_x000D_
button {_x000D_
  padding: .25em 1em;_x000D_
}_x000D_
_x000D_
input,_x000D_
label {_x000D_
  color: white !important;_x000D_
}
_x000D_
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.1/css/materialize.min.css" />_x000D_
_x000D_
<div class="wrapper">_x000D_
  <form>_x000D_
    <input type="text" placeholder="Enter Username" name="uname" required>_x000D_
    <input type="password" placeholder="Enter Password" name="psw" required>_x000D_
    <button type="submit">Login</button>_x000D_
  </form>_x000D_
</div>
_x000D_
_x000D_
_x000D_


I tried all the answers and I still couldn't get mine to work on Mobile, until I found -webkit-tap-highlight-color.

So, what worked for me is...

* { -webkit-tap-highlight-color: transparent; }

Removing all focus styles is bad for accessibility and keyboard users in general. But outlines are ugly and providing a custom focussed style for every single interactive element can be a real pain.

So the best compromise I've found is to show the outline styles only when we detect that the user is using the keyboard to navigate. Basically, if the user presses TAB, we show the outlines and if he uses the mouse, we hide them.

It does not stop you from writing custom focus styles for some elements but at least it provides a good default.

This is how I do it:

_x000D_
_x000D_
// detect keyboard users_x000D_
_x000D_
const keyboardUserCssClass = "keyboardUser";_x000D_
_x000D_
function setIsKeyboardUser(isKeyboard) {_x000D_
  const { body } = document;_x000D_
  if (isKeyboard) {_x000D_
   body.classList.contains(keyboardUserCssClass) || body.classList.add(keyboardUserCssClass);_x000D_
  } else {_x000D_
   body.classList.remove(keyboardUserCssClass);_x000D_
  }_x000D_
}_x000D_
_x000D_
// This is a quick hack to activate focus styles only when the user is_x000D_
// navigating with TAB key. This is the best compromise we've found to_x000D_
// keep nice design without sacrifying accessibility._x000D_
document.addEventListener("keydown", e => {_x000D_
  if (e.key === "Tab") {_x000D_
   setIsKeyboardUser(true);_x000D_
  }_x000D_
});_x000D_
document.addEventListener("click", e => {_x000D_
  // Pressing ENTER on buttons triggers a click event with coordinates to 0_x000D_
  setIsKeyboardUser(!e.screenX && !e.screenY);_x000D_
});_x000D_
_x000D_
document.addEventListener("mousedown", e => {_x000D_
  setIsKeyboardUser(false);_x000D_
});
_x000D_
body:not(.keyboardUser) *:focus {_x000D_
  outline: none;_x000D_
}
_x000D_
<p>By default, you'll see no outline. But press TAB key and you'll see focussed element</p>_x000D_
<button>This is a button</button>_x000D_
<a href="#">This is anchor link</a>_x000D_
<input type="checkbox" />_x000D_
<textarea>textarea</textarea>_x000D_
<select/>
_x000D_
_x000D_
_x000D_


try this css, it work for me

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

None of the solutions worked for me in Firefox.

The following solution changes the border style on focus for Firefox and sets the outline to none for other browsers.

I've effectively made the focus border go from a 3px blue glow to a border style that matches the text area border. Here's some border styles:

Dashed border (border 2px dashed red): Dashed border. border 2px dashed red

No border! (border 0px):
No border. border:0px

Textarea border (border 1px solid gray): Textarea border. border 1px solid gray

Here is the code:

_x000D_
_x000D_
input:focus, textarea:focus {_x000D_
    outline: none; /** For Safari, etc **/_x000D_
    border:1px solid gray; /** For Firefox **/_x000D_
}_x000D_
_x000D_
#textarea  {_x000D_
  position:absolute;_x000D_
  top:10px;_x000D_
  left:10px;_x000D_
  right:10px;_x000D_
  width:calc(100% - 20px);_x000D_
  height:160px;_x000D_
  display:inline-block;_x000D_
  margin-top:-0.2em;_x000D_
}
_x000D_
<textarea id="textarea">yo</textarea>
_x000D_
_x000D_
_x000D_


To remove it from all inputs

input {
 outline:none;
}

Examples related to css

need to add a class to an element Using Lato fonts in my css (@font-face) Please help me convert this script to a simple image slider Why there is this "clear" class before footer? How to set width of mat-table column in angular? Center content vertically on Vuetify bootstrap 4 file input doesn't show the file name Bootstrap 4: responsive sidebar menu to top navbar Stylesheet not loaded because of MIME-type Force flex item to span full row width

Examples related to input

Angular 4 - get input value React - clearing an input value after form submit Min and max value of input in angular4 application Disable Button in Angular 2 Angular2 - Input Field To Accept Only Numbers How to validate white spaces/empty spaces? [Angular 2] Can't bind to 'ngModel' since it isn't a known property of 'input' Mask for an Input to allow phone numbers? File upload from <input type="file"> Why does the html input with type "number" allow the letter 'e' to be entered in the field?

Examples related to safari

How to Inspect Element using Safari Browser What does the shrink-to-fit viewport meta attribute do? background: fixed no repeat not working on mobile Swift Open Link in Safari How do I make flex box work in safari? onClick not working on mobile (touch) window.open(url, '_blank'); not working on iMac/Safari HTML5 Video tag not working in Safari , iPhone and iPad NodeJS/express: Cache and 304 status code Video auto play is not working in Safari and Chrome desktop browser

Examples related to webkit

com.apple.WebKit.WebContent drops 113 error: Could not find specified service HTML5 Video autoplay on iPhone What does the shrink-to-fit viewport meta attribute do? Chrome / Safari not filling 100% height of flex parent How to style HTML5 range input to have different color before and after slider? What are -moz- and -webkit-? Video auto play is not working in Safari and Chrome desktop browser Rotate and translate Background color not showing in print preview Blurry text after using CSS transform: scale(); in Chrome

Examples related to border

How to create a inner border for a box in html? Android LinearLayout : Add border with shadow around a LinearLayout Giving a border to an HTML table row, <tr> In bootstrap how to add borders to rows without adding up? Double border with different color How to make a transparent border using CSS? How to add a border just on the top side of a UIView Remove all stylings (border, glow) from textarea How can I set a css border on one side only? Change input text border color without changing its height