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;
}
From the comments below, the most elegant solution is:
h1,h2,h3,h4,h5,h6 {
display: inline;
}
Thank you everyone for your input!
Web Development Tutorials to Increase Your Skills
Seeking to improve your HTML and CSS skils? The resources below can help you become a better web developer and designer and help you make your website superior to your competitors:
- Learn CSS3: In CSS3 First Look, staff author James Williamson provides an in-depth introduction to the newest CSS standard, detailing its modular format, history, and current level of browser support, while also demonstrating its capabilities and applications. The course includes tutorials on using new selectors, modifying typography and color, working with the box model, and understanding media queries.
- XHTML and HTML Essential Training: Bill Weinman helps designers and coders understand XHTML and HTML. In the process, Bill covers document structure, block and inline-level tags, floating images, controlling white space, phrase and font markup, and tables and frames. He even provides a good introduction to CSS. Bill offers step-by-step guidance for building a complete working web site
- Learn HTML5: Author James Williamson introduces the newest HTML specification, providing a high-level overview of HTML5 in its current state, how it differs from HTML 4, the current level of support in various browsers and mobile devices, and how the specification might evolve in the future.
- The Complete Web Designer: Ten modules/courses compiled to teach you everything you need to know to become a commercial web designer. Hands-on practical training that simplifies and targets the key techniques needed to build modern web sites. Training from experienced web designers who KNOW what is required in the real world of web design
- The Complete Web Developer: With so many languages and technologies out there, it is really hard for someone to know what to study and in what order - especially if you want to be able to make a living at it! Course focuses on using PHP and MySQL. The Complete Programmer package is designed to guide you along to the way, step-by-step, towards becoming a professional web programmer.
About the Author
Paul Flyer loves to research the web and find resources and tools for building, maintaining and promoting websites. Based in Saint Louis, MO, he works in management and spends his free time sharpening his web development and copy writing skills. Feel free to contact Paul with any questions, comments or ideas. He is also available to help you with your own website.
Profile cancel
Popular Articles
- Removing Line Breaks/Space Before/After H1 tags
- Free Download Manager for Firefox
- Web Development and Design Tool Recommendations
- .htaccess and WordPress
- Removing Image Borders with CSS
- What does it mean to be pinged
- Graphic Design Tool Resources
- Free Blog Software Recommendation
- How to use cPanel to backup your website











Thanks for the tip!
More compatible – with browsers.
h1,h2,h3,h4,h5,h6 {
display: inline;
}
Thanks for the additional info Ryan.
Ryan – thanks SO MUCH. Have really been having problems with this – and your answer got it sorted straight away. Thanks!
Very Thanks for solution.
Thanks for the information…Kool
Oh Thank You!! I could never figure this out.
Thank you Thank you Thank you!!!!!!!!!
Awesome, this is something that I never had to mess with before. Your page came in and saved the day! Thanks for the tips.
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
Genius. Saved me probable hours of frustration.
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?
inline:display – take out the actual line break!
Just what I was looking for. Thanks!
@ryan awesome.. display:inline; is perfect!
Many thanx!
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.
Thank you. Just what I was looking for. its very help full
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
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
And I thought I was stuck with the extra spacing on header tags! Figured it was just the way the tag was meant to be and the browsers render it. Should have known CSS to the rescue to remove the line break.
Thank you!
Thanks a lot for this information….
Thank you very much for this very useful info!
Thank you Ryan..very helful.
I’ve been working on how to put the H1 tag on the same line as another style for http://www.majuda.com and my client only wanted the words “call recording” in the H1 tag for SEO purposes, however the “Affordable Enterprise” before it had to be in line and use the same style because it normally makes a before and after an H1 tag. Anyway, here’s the css i used…
h1 {font-size:12px; color:#3EA0CF; font-family: verdana; line-height:120%; display: inline;}
.headerH1 {font-size:12px; color:#3EA0CF; font-family: verdana; font-weight:bold; line-height:120%;}
Then in the html it looked like this…
Affordable Enterprise Call Recording
…just in case anyone is interested.
Thanks Ryan for the ‘display: inline;’ tip. Saved heaps of time.
@ ryan – Many thanks mate, that solved my problem!
Nothing seems to work with IE, only FF.
What version of IE? Can you share the URL as an example?
Thanks for share…
works great… thanks. now it look better in my blog.
That was so simple…gosh!!!
Salil,
Glad it helped!
Paul
I found this website is very interesting and more useful for the beginners. Thanks a lot