346

I am wondering if its possible to remove the default blue and yellow glow when I click on a text input / text area using CSS?

Michael Irigoyen
  • 21,233
  • 17
  • 82
  • 125
Alec Smart
  • 85,672
  • 35
  • 115
  • 178
  • 6
    @Steve, another reason to disable it is if you want the glow-effect to work in all browsers by using :focus instead of the ill-supported outline style. – Langdon Mar 09 '10 at 16:30
  • 91
    It's really annoying when people start a philosophical conversation on whether something is the "right thing to do" when the question is a technical one. – tim Mar 22 '13 at 19:31
  • 2
    I'm making an online spreadsheet, Steve, so it would be appropriate for my usage. It depends, but if it's just a simple form then you should leave the outline as it is. – william44isme Aug 12 '13 at 15:02
  • 4
    I think it's perfectly ok to disable it and make a custom :focus effect with css... – ithil Oct 30 '13 at 08:07
  • Also, knowing how to disable something does not mean that it’s irreversible. Anyone who works for any client knows that they might want to see something rendered one way and then switch it back to the original/default way. Lecturing them on accessibility will not change that desire or make anyone happy. – Giacomo1968 Feb 12 '18 at 18:27
  • @tim It's so funny because if you express something like there's no ambiguity about it, people basically stop doing this. But then the OP said "I am wondering if..." instead of "how can I..." – Nathan Apr 22 '18 at 20:25

13 Answers13

636

Edit (11 years later): Don't do this unless you're going to provide a fallback to indicate which element is active. Otherwise, this harms accessibility as it essentially removes the indication showing which element in a document has focus. Imagine being a keyboard user and not really knowing what element you can interact with. Let accessibility trump aesthetics here.

textarea, select, input, button { outline: none; }

Although, it's been argued that keeping the glow/outline is actually beneficial for accessibility as it can help users see which Element is currently focused.

You can also use the pseudo-element ':focus' to only target the inputs when the user has them selected.

Demo: https://jsfiddle.net/JohnnyWalkerDesign/xm3zu0cf/

ajm
  • 18,564
  • 3
  • 30
  • 34
  • 2
    Perfect, thankyou very much. Also wondering, can I remove the textarea resize option also (at the bottom right of textarea)? – Alec Smart Jun 01 '09 at 16:30
  • 3
    +1 for the caution; *please* try to avoid doing anything which breaks the user's expectation of how their platform performs; you may actually be harming their productivity and making your web site harder to use. – Rob Jun 01 '09 at 16:31
  • Yes, set the max-height and max-width. – Tyler Rash Jun 01 '09 at 16:32
  • and @ajm, thanks! I didn't know that, I thought it was here to stay with no way to fix it. – marcgg Jun 01 '09 at 16:37
  • 6
    Remove my chrome/safari textarea resize option at your own peril! I find it really useful, indispensible even on some sites. – JeeBee Jun 01 '09 at 16:42
  • 1
    Am not removing the resize option, but thought it would be good to know just in case :) – Alec Smart Jun 01 '09 at 16:45
  • @Marc G: That isn't relevant here. The question was about disabling the textarea resize feature in Safari and Chrome -- a feature that doesn't exist in IE. – Tyler Rash Jun 01 '09 at 17:34
  • Very interesting, this outline CSS rule seems to be very under-used. – Liam Dec 16 '09 at 17:29
  • this is not a valid for css2.1 is there any other way ? –  Jan 15 '11 at 22:48
  • 6
    for getting rid of the resize handle: resize: none; – Daniel Feb 15 '12 at 16:09
  • 1
    This doesn't completely work in chrome (textarea). You need to set `box-shadow:none;` as well... this is getting to be a nightmare. – Cory Mawhorter May 25 '13 at 21:45
  • This is a great solution for experienced web devs, just make sure you are implementing another way to clearly see which element is currently in focus. – Micah Jan 23 '15 at 16:27
  • 1
    I use this on clicked buttons, but I have to put !important for it to work in my node-webkit (chromium-based) app. button { outline: none !important; } – TKoL Mar 29 '15 at 17:30
  • I had to also set `border:none; box-shadow:none` in my case to the affected text area. – mz2 Aug 05 '15 at 17:54
  • 1
    None of the above worked for me. Using Chrome `version 45.0.2454.101 m` – J86 Oct 04 '15 at 13:32
  • You missed the 'select' `textarea, input, button, select { outline: none; }` – Haje Dec 22 '17 at 09:20
93

This effect can occur on non-input elements, too. I've found the following works as a more general solution

:focus {
  outline-color: transparent;
  outline-style: none;
}

Update: You may not have to use the :focus selector. If you have an element, say <div id="mydiv">stuff</div>, and you were getting the outer glow on this div element, just apply like normal:

#mydiv {
  outline-color: transparent;
  outline-style: none;
}
Wade
  • 3,509
  • 2
  • 26
  • 45
Carl W
  • 1,030
  • 7
  • 4
  • This works, for example for ` – kasimir Nov 28 '13 at 19:54
  • 1
    The accepted answer didn't work for me on Chrome on OSX. This solution did the job. – Bart May 12 '14 at 07:35
  • Also using this technique, you can maintain the focus, but redefine the value of the outline to be a solid color of your choice, etc. to fit your site's style if removing it altogether is not completely satisfactory. – Neil Monroe Feb 03 '15 at 22:20
  • 1
    Did not work for me on latest version of chrome `45.0.2454.101 m` – J86 Oct 04 '15 at 13:32
  • This answer from @Carl-W should not be overlooked! - This was useful when using jQuery to link to an anchor that was a div. I was reloading an iframe in the div, then manually going to the anchor without reloading. It would scroll down the page to the anchor, but the whole div had a blue outer glow. Added this CSS on the div element, and it worked! -- NOTE: I didn't use `:focus` for the selector, I just put the `outline-color` and `outline-style` on my div's css. – Wade Sep 01 '17 at 04:09
13

On textarea resizing in webkit based browsers:

Setting max-height and max-width on the textarea will not remove the visual resize handle. Try:

resize: none;

(and yes I agree with "try to avoid doing anything which breaks the user's expectation", but sometimes it does make sense, i.e. in the context of a web application)

To customize the look and feel of webkit form elements from scratch:

-webkit-appearance: none;
Thomas Maas
  • 1,759
  • 11
  • 8
  • 3
    It's also possible to allow resizing in one direction only, which may fix its interaction with some layouts without disabling it completely: the possible values for resize are `none`, `both`, `horizontal`, `vertical`, and `inherit`. – Boann Jul 28 '12 at 06:34
  • I like the solution offered here with ' -webkit-appearance: none;' - removes ALL of the styling from the input elements, so you can style them as you need to. Thanks! – hanazair Oct 14 '14 at 21:56
  • I don't know why this has so many upvotes, it's not an answer to the question at all. – paddotk Sep 14 '17 at 17:03
7

Carl W:

This effect can occur on non-input elements, too. I've found the following works as a more general solution

:focus {
  outline-color: transparent;
  outline-style: none;
}

I’ll explain this:

  • :focus means it styles the elements that are in focus. So we are styling the elements in focus.
  • outline-color: transparent; means that the blue glow is transparent.
  • outline-style: none; does the same thing.
Rory O'Kane
  • 25,436
  • 11
  • 86
  • 123
MineCMD
  • 394
  • 4
  • 13
7

I experienced this on a div that had a click event and after 20 some searches I found this snippet that saved my day.

-webkit-tap-highlight-color: rgba(0,0,0,0);

This disables the default button highlighting in webkit mobile browsers

Michael
  • 8,464
  • 2
  • 59
  • 62
4

This is the solution for people that do care about accessibility.

Please, don't use outline:none; for disabling the focus outline. You are killing accessibility of the web if you do this. There is a accessible way of doing this.

Check out this article that I've written to explain how to remove the border in an accessible way.

The idea in short is to only show the outline border when we detect a keyboard user. Once a user starts using his mouse we disable the outline. As a result you get the best of the two.

Wim Mostmans
  • 3,009
  • 1
  • 16
  • 20
2

If you want to remove the glow from buttons in Bootstrap (which is not necessarily bad UX in my opinion), you'll need the following code:

.btn:focus, .btn:active:focus, .btn.active:focus{
  outline-color: transparent;
  outline-style: none;
}
Kyle S
  • 61
  • 4
  • Thanks. `.btn:active:focus` was necessary to remove the glow whilst actually holding down the button. – homerjam Jan 15 '15 at 17:03
2

This solution worked for me.

input:focus {
    outline: none !important;
    box-shadow: none !important;
}
Harsh Prajapati
  • 180
  • 2
  • 5
1

some times it's happens buttons also then use below to remove the outerline

input:hover
input:active, 
input:focus, 
textarea:active,
textarea:hover,
textarea:focus, 
button:focus,
button:active,
button:hover
{
    outline:0px !important;
}
vamsikrishnamannem
  • 4,659
  • 5
  • 19
  • 34
0
<select class="custom-select">
        <option>option1</option>
        <option>option2</option>
        <option>option3</option>
        <option>option4</option>
</select>

<style>
.custom-select {
        display: inline-block;
        border: 2px solid #bbb;
        padding: 4px 3px 3px 5px;
        margin: 0;
        font: inherit;
        outline:none; /* remove focus ring from Webkit */
        line-height: 1.2;
        background: #f8f8f8;

        -webkit-appearance:none; /* remove the strong OSX influence from Webkit */

        -webkit-border-radius: 6px;
        -moz-border-radius: 6px;
        border-radius: 6px;
    }
    /* for Webkit's CSS-only solution */
    @media screen and (-webkit-min-device-pixel-ratio:0) { 
        .custom-select {
            padding-right:30px;    
        }
    }

    /* Since we removed the default focus styles, we have to add our own */
    .custom-select:focus {
        -webkit-box-shadow: 0 0 3px 1px #c00;
        -moz-box-shadow: 0 0 3px 1px #c00;
        box-shadow: 0 0 3px 1px #c00;
    }

    /* Select arrow styling */
    .custom-select:after {
        content: "▼";
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        font-size: 60%;
        line-height: 30px;
        padding: 0 7px;
        background: #bbb;
        color: white;

        pointer-events:none;

        -webkit-border-radius: 0 6px 6px 0;
        -moz-border-radius: 0 6px 6px 0;
        border-radius: 0 6px 6px 0;
    }
</style>
criss_ae
  • 51
  • 1
  • 12
0

I found it helpful to remove the outline on a "sliding door" type of input button, because the outline doesn't cover the right "cap" of the sliding door image making the focus state look a little wonky.

input.slidingdoorbutton:focus { outline: none;}
Rich Finelli
  • 817
  • 7
  • 15
0

I just needed to remove this effect from my text input fields, and I couldn't get the other techniques to work quite right, but this is what works for me;

input[type="text"], input[type="text"]:focus{
            outline: 0;
            border:none;
            box-shadow:none;

    }

Tested in Firefox and in Chrome.

Martyn Shutt
  • 1,538
  • 16
  • 24
0

Sure! You can remove blue border also from all HTML elements using *

*{
    outline-color: transparent;
    outline-style: none;
  }

And

 *{
     outline: none;   
   }
Santosh Khalse
  • 9,358
  • 3
  • 32
  • 35