What is the default margin that HTML sets for its
tags? I noticed there is some auto margin, but I was wondering if anyone knows what it is (and if it's in
px
or %
etc.).
P粉5738097272023-10-20 16:53:31
According to W3School’s CSS reference, The default attributes and values of the body tag are,
body{ display : block; margin : 8px; }
By accessing the Calculation Pane in Chrome Dev Tools.
P粉8645949652023-10-20 00:12:56
In most major browsers, the default margins on all sides are 8px
. It is defined in pixels by the user-agent-stylesheet
provided by the browser.
Some browsers allow you to create and use your own user-agent-stylesheet
, but if you are developing a website I recommend not changing this as your users most likely won't Make a modified stylesheet and you'll see a different page than you did.
If you want to change it, you can do this:
body { margin: 0px; padding: 0px; ... }
But if you have a large project and want to be more complete, use normalize.css. It resets many default values to be consistent across browsers.