Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the default margins for the html heading tags (<h1>, <h2>, <h3>, etc.)?

Tags:

html

css

I avoid using the defaults with the reset code below:

margin:0px; and padding:0px;

For example, what are the default margins for the heading tag below?

<h1>Header</h1>
like image 264
Mr.T.K Avatar asked Aug 13 '11 10:08

Mr.T.K


People also ask

What are the default margins in HTML?

By default, the margin value of some HTML elements is set to zero, though some elements have specified margin values as their default, such as the <h1> through <h6> heading tags. Margins of two different elements are also allowed to overlap sometimes in a behavior called margin collapse.

What is the default margin for H1 tag?

However, an H1 for example has a top and bottom margin: . 67em; , by default. These top & bottom margins grow all the way to 2.33em for an H6 .

What are H1 H2 H3 tags in HTML?

HTML defines six levels of headings. A heading element implies all the font changes, paragraph breaks before and after, and any white space necessary to render the heading. The heading elements are H1, H2, H3, H4, H5, and H6 with H1 being the highest (or most important) level and H6 the least.

What are H1 H2 and H3 headings?

To break it down, remember: H1 = Main keywords and subject matter, what the overall post is about. H2 = Sections to break up content, using similar keywords to the H1 tag. H3 = Subcategories to further break up the content, making it easily scannable.


2 Answers

Your Question:

It varies between browsers. Check each browser's specific default stylesheets to tell.

For Google Chrome for example, it's 0.67em.


A Better Solution?

Do know that if you wish to aim for x-browser consistency, you'll have to use a CSS Reset.

The most common one being:

* { padding: 0; margin: 0; }

Although other (and probably better) exist.

like image 112
Madara's Ghost Avatar answered Oct 01 '22 19:10

Madara's Ghost


It's different regarding which browser, thus if you want a pixel-perfect design then practice is to "reset" those values to 0 (margin and padding) and set them yourself.

"CSS reset" is very common to front-end developers, a simple example of one i use :

html,body,blockquote,code,h1,h2,h3,h4,h5,h6,p,pre{margin:0;padding:0}
button,fieldset,form,input,legend,textarea,select{margin:0;padding:0}
fieldset{border:0}
a,a *{cursor:pointer}
div{margin:0;padding:0;background-color:transparent;text-align:left}
hr,img{border:0}
applet,iframe,object{border:0;margin:0;padding:0}
button,input[type=button],input[type=image],input[type=reset],input[type=submit],label{cursor:pointer;}
ul,li{list-style:none;margin:0;padding:0;}
strong{font-weight:bold;}
em{font-style:italic;} 
like image 40
darma Avatar answered Oct 01 '22 21:10

darma