Subscribe to the RWT RSS Feed

RWT Webmaster Tools Blog

Resources and Tools You Can Use

 

Removing Line Breaks/Space Before/After H1 tags

Header Tags (h1,h2,h3,h4,h5,h6) produce a space/break above and below the enclosed text. Sometimes this is not desireable. To remove the space from below the tag use this in the CSS file:


h1,h2,h3,h4,h5,h6{
margin-bottom: 0px;
padding-bottom: 0px;
}

Similarly, the code for removing the space from above a H1 tag:


h1,h2,h3,h4,h5,h6{
margin-top: 0px;
padding-top: 0px;
}

Of course, these two can be combined to remove the space from both above and below a H1 tag. Remember, shorthand can be used to accomplish this.


h1,h2,h3,h4,h5,h6{
margin: 0px 0px 0px 0px;
padding: 0px 0px 0px 0px;
}

comments / trackbacks

20 Responses to “Removing Line Breaks/Space Before/After H1 tags”
  1. Thanks for the tip!

  2. More compatible – with browsers.

    h1,h2,h3,h4,h5,h6 {
    display: inline;
    }

  3. Thanks for the additional info Ryan.

  4. Ryan – thanks SO MUCH. Have really been having problems with this – and your answer got it sorted straight away. Thanks!


  5. Apul Gupta Says:

    Very Thanks for solution. :)

  6. Thanks for the information…Kool :)

  7. Oh Thank You!! I could never figure this out.

  8. Thank you Thank you Thank you!!!!!!!!!

  9. Awesome, this is something that I never had to mess with before. Your page came in and saved the day! Thanks for the tips.

  10. Thanks guys.

    I am having fun with CSS and this solves a problem for me even after all this time.

    So much to learn and so little time to do it in.

    Murray

  11. Genius. Saved me probable hours of frustration.

  12. ok so what your saying is simply padding:0 margin:0!?!

    What about actually remove the line break though so the text flows like it’s part of the same sentance?

  13. inline:display – take out the actual line break!


  14. Charles Bronson Says:

    Just what I was looking for. Thanks!

  15. @ryan awesome.. display:inline; is perfect!

  16. Many thanx!

  17. If you have tried all these suggestions without a result (like I did) try putting this:

    * {
    margin: 0;
    padding: 0;
    }

    in your CSS file.

    Then use padding: bla bla bla bla; to define the spaces you want in-between H1, H2 and Paragraphs. See http://www.searchourworld.com for the results.

    Hope that helps. :-)

  18. Thank you. Just what I was looking for. its very help full

  19. thats great. but it removes my align left formating for my heading.

    IMPACT : HOME

    how do I display heading inline and aligned to the left?

    thanks
    gem :)

  20. Just answered my own question. If you use

    h1,h2,h3,h4,h5,h6{
    margin: 0px 0px 0px 0px;
    padding: 0px 0px 0px 0px;
    }

    you can align text left.

    display : inline – means you cann’t.

    Gem :)

Leave a Reply