Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Padding on body element

Tags:

html

css

Why people add padding:0; on body element? I don't see any point in that. All browsers use default margin:8px; on body not padding. Am I missing something ? Is there any quirks?

like image 440
Blaja Avatar asked Jul 28 '26 07:07

Blaja


2 Answers

  * {
     margin: 0;
     padding: 0;
    }

This is part of the "CSS Reset" theory which helps keep your designs consistent across browsers, a very good thing. Unfortunately this is not a good practice. It is very heavy on the rendering agent to apply rules to every single element in the document, especially with large web pages, and this can also destroy a lot of good default styling, especially when you want to have default styled submit buttons.

like image 115
Pym Avatar answered Jul 30 '26 22:07

Pym


If body { margin: 0; } is used, all other standards compliant browsers (excluding Opera) will set items into the top left corner of the window.

If body { padding: 0; } is used, only Opera (both Mac and Windows) will set items into the top left corner of the window.

The best way to set items into the top left corner of the window is to use body { margin: 0; padding: 0; } which will work for all standards compliant browsers.

like image 43
Vuthy Sok Avatar answered Jul 30 '26 21:07

Vuthy Sok



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!