Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use 'border: none' or 'border: 0'?

Tags:

css

border

Which of the two methods conforms to W3C standards? Do they both behave as expected across browsers?

border: none;
border: 0;

like image 260
John Himmelman Avatar asked May 27 '10 16:05

John Himmelman


People also ask

What does border-style none do?

Like the none keyword, displays no border. Unless a background-image is set, the computed value of the same side's border-width will be 0 , even if the specified value is something else.

How do you put a border on 0?

We can specify the no border property using CSS border: none, border-width : 0, border : 0 properties. Approach 1: We will give border-color, border-style properties to both headings, for showing text with border and no-border. For no border heading, we will use the border-width : 0 which will result in no border.


1 Answers

Both are valid. It's your choice.

I prefer border:0 because it's shorter; I find that easier to read. You may find none more legible. We live in a world of very capable CSS post-processors so I'd recommend you use whatever you prefer and then run it through a "compressor". There's no holy war worth fighting here but Webpack→LESS→PostCSS→PurgeCSS is a good 2020 stack.

That all said, if you're hand-writing all your production CSS, I maintain —despite the grumbling in the comments— it does not hurt to be bandwidth conscious. Using border:0 will save an infinitesimal amount of bandwidth on its own, but if you make every byte count, you will make your website faster.


The CSS2 specs are here. These are extended in CSS3 but not in any way relevant to this.

'border'     Value:      [ <border-width> || <border-style> || <'border-top-color'> ] | inherit     Initial:    see individual properties     Applies to:     all elements     Inherited:      no     Percentages:    N/A     Media:      visual     Computed value:     see individual properties  

You can use any combination of width, style and colour.
Here, 0 sets the width, none the style. They have the same rendering result: nothing is shown.

like image 165
Oli Avatar answered Sep 22 '22 14:09

Oli