What is the default width of `<body>` margins?
P粉369196603
P粉369196603 2023-10-19 21:54:40
0
2
494

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粉369196603
P粉369196603

reply all(2)
P粉573809727

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粉864594965

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!