188

I tried to create buttons and insert my own images instead of the standard button images. However, the gray border from the standard buttons still remains, showing on the outside of my black button images.

Does anyone know how to remove this gray border from the button, so it's just the image itself? Thank you.

3
  • Try -webkit-appearance: inherit; or -webkit-appearance:initial
    – Max
    Jun 27, 2018 at 23:47
  • 1
    @Brut: I might be wrong, but that looks browser-specific to me, and I'm pretty sure Jameson wants something that'll work for all modern browsers. Jan 30, 2019 at 23:01
  • In my case I was seeing the box-shadow
    – Pieterjan
    Sep 13, 2022 at 11:38

14 Answers 14

291

Add

padding: 0;
border: none;
background: none;

to your buttons.

Demo:

https://jsfiddle.net/Vestride/dkr9b/

2
  • I appreciate.. but i added just like you said to the stylesheet and it didn't work unfortunately. Should I just embed it straight into the html, if that would make a difference?
    – JamesonW
    Jul 16, 2012 at 1:42
  • I added a fiddle plus background: none; to the buttons. Take a peak at the fiddle and see if that works for you.
    – Vestride
    Jul 17, 2012 at 2:30
68

This seems to work for me perfectly.

button:focus { outline: none; }
7
  • 10
    outline:none; is not recommended for accessibility reasons. If you must remove the focus border, please provide another way for users to see that it has focus. outlinenone.com
    – Vestride
    Jan 30, 2017 at 22:33
  • Another point of view to the previous comment is that buttons shouldn't necessarily hold focus. If you click it and an action is performed, then the focus should not remain.
    – Octopus
    Sep 27, 2020 at 22:46
  • 1
    @Octopus If someone is not able to move a mouse pointer to click on a button directly, but instead needs to tab through the form controls to get to the button in question, then they will need some cue to know that they have reached the correct button before activating it. Sep 19, 2021 at 22:18
  • Note: In general some websites tend to prefer outline visibility for all users to see especially for disabled users. However some websites prefer not to display outlines, it really depends on your website designs and your website audience. For example for an internal admin panel you can do what ever you like as you already know who your website users are and admin panels are private websites not public facing. Oct 26, 2021 at 4:27
  • Also on highly graphical web pages sometimes items look better without outlines, like those story book websites out there, Im an sure we have all seen them similar to computer game designs. Oct 26, 2021 at 4:30
18

I was having the same problem and even though I was styling my button in CSS it would never pick up the border:none but what worked was adding a style directly on the input button like so:

<div style="text-align:center;">
    <input type="submit" class="SubmitButtonClass" style="border:none;" value="" />
</div>
1
  • you are using the CSS cascade to override the property with a inline style. You should check out some articles on the CSS cascade and CSS specificity.
    – DrCord
    Dec 15, 2015 at 17:30
12
input[type="button"] {
border: none;
outline:none;
}
0
8

You can easily give this style to it:

MyButton {
border: none;
outline: none;
background: none;
}

The border: none; will also do the job for you separately without giving outline (Because: An outline is a line drawn outside the element's border. so when there is no border, outline property doesn't have any meaning on its own).

The background shorthand CSS property sets all background style properties at once, such as color, image, origin and size, or repeat method. so when you set its value to none, then it prevents your button having any color, image and etc....

6

For removing the default 'blue-border' from button on button focus:

In Html:

<button class="new-button">New Button...</button>

And in Css

button.new-button:focus {
    outline: none;
}

Hope it helps :)

5

Try using: border:0; or border:none;

1
  • 1
    #button { border: none; } This seems to work just fine. Aug 23, 2020 at 23:43
2

You can also try background:none;border:0px to buttons.

also the css selectors are div#yes button{..} and div#no button{..} . hopes it helps

2
  • Also you can set background of button as images, instead using img tags
    – user1527729
    Jul 16, 2012 at 1:33
  • Or do it in pure css. like background:#555; font-weight:bold: color:#fff; padding:6px 8px;
    – user1527729
    Jul 16, 2012 at 1:35
2

Add this as css,

button[type=submit]{border:none;}
2

Just use:

CSS

button {
 border:none; 
 outline:none;
}
1
  • 1
    Welcome to StackOverflow. While your code snippet may answer the question, providing additional context regarding why and/or how your code snippet works improves its long-term value. Furthermore it doesn't seem to differ very much from the accepted answer... Jun 13, 2021 at 13:15
1

The usual trick is to make the image itself part of a link instead of a button. Then, you bind the "click" event with a custom handler.

Frameworks like Jquery-UI or Bootstrap does this out of the box. Using one of them may ease a lot the whole application conception by the way.

1

You can target the button in the CSS styling like so:

 div button {
    border: none;
 }
1

HTML code: Then, you can style the link to look like a button.

<button class=”button-solid”>Button without border</button>

CSS code: You might find that your button does not have a border. But when clicked, a border appears on the button. You can remove that border by applying the following CSS code on the button.

.button-solid {
    border: none;
}
button-solid:focus {
    border: none;
    outline: none;
}
-6
$(".myButtonClass").css(["border:none; background-color:white; padding:0"]);
1
  • The person is asking for a css code not a jQuery code.
    – MJ DLS
    Jan 7, 2022 at 3:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.