Block vs. Inline Level Elements
July 24, 2007 at 5:45 am 3 comments
HTML elements are either block or inline elements. The characteristics of block elements include:
- Always begin on a new line
- Height, line-height and top and bottom margins can be manipulated
- Width defaults to 100% of their containing element, unless a width is specified
Examples of block elements include <div>, <p>, <h1>, <form>, <ul> and <li>. The characteristics of inline elements, on the other hand, are the opposite of block elements:
- Begin on the same line
- Height, line-height and top and bottom margins can’t be changed
- Width is as long as the text/image and can’t be manipulated
Examples of inline elements include <span>, <a>, <label>, <input>, <img>, <strong> and <em>.
To change an element’s status, you can use display: inline or display: block. But what’s the point of changing an element from being block to inline, or vice-versa? Well, at first it may seem like you might hardly ever use this trick, but in actual fact, this is a very powerful technique, which you can use whenever you want to:
- Have an inline element start on a new line
- Have a block element start on the same line
- Control the width of an inline element (particularly useful for navigation links)
- Manipulate the height of an inline element
- Set a background colour as wide as the text for block elements, without having to specify a width
Full Article at: http://www.sitepoint.com/article/top-ten-css-tricks
Entry filed under: css. Tags: .



1. Horizontal and Vertical Centering Using CSS: A Beginner’s Guide | Noobcube | September 1, 2009 at 2:39 pm
[...] Worldtechies: Block vs. Inline Level Elements [...]
2.
dinesh | July 31, 2010 at 12:45 pm
Simple and good description
3. block vs. inline elements | oniangelique | September 22, 2011 at 2:29 pm
[...] http://sureshjain.wordpress.com/2007/07/24/block-vs-inline-level-elements/ Share this:TwitterFacebookLike this:LikeBe the first to like this post. This entry was posted in Uncategorized by oniangelique. Bookmark the permalink. [...]