Block vs Inline display style in CSS
HTML elements can be displayed either in block or inline style.
The difference between these is one of the most basic things you need to know in order to use CSS effectively.
HTML elements can be displayed either in block or inline style.
The difference between these is one of the most basic things you need to know in order to use CSS effectively.
All HTML elements are naturally displayed in one of the following ways:
<p> tags and <div> tags are naturally displayed block-style.
(I say "naturally" because you can override the display style by setting the CSS display property e.g. display:inline;.)
A block-display element will span the full width of the space available to it, and so will start on a new line in the flow of HTML. The flow will continue on a new line after the block-display element.
Here I've started a paragraph and now I'm going to insert a <div>
and then continue the text here...
See how the <div> jumped in and took over the full width of the space?
Common HTML elements that are naturally block-display include:
Inline-display elements don't break the flow. They just fit in with the flow of the document.
So here I've got a paragraph going on, and I'm going to add a <span> tag that has a yellow background and italic text. See how it just fits right in with the flow of the text?
More elements are naturally inline-style, including:
Although each HTML element has its natural display style, you can over-ride these in CSS.
This can be very useful when you want your page to look a particular way while using semantically-correct HTML.
Say you want to provide a list of items, but you don't want a big bulleted list. You just want to say that you're going to the store to buy:
Or maybe you want a nice toolbar, which is stricly a list (of links) and so should be marked up as a <ul>.
See our production worked example ebook for more in-depth CSS tricks!
If you want to build clean and robust web pages using HTML & CSS, I strongly recommend Build Your Own Web Site The Right Way Using HTML & CSS. It's great value at under $20.
For a more comprehensive CSS manual, you can't beat Eric Meyer's Definitive Guide.
If you're wanting a guide to using CSS to help you create more eye-catching and beautiful designs, this may be the one for you: Zen of CSS Design
New eBook - Web page production with xHTML and CSS #1Experience the thought process of a professional web producer as he guides you through the web page production process, from photoshop design to working HTML template.
The book tells you how to approach web production, beginning with semantic HTML, guiding you through how to slice up a photoshop document, and finally how to use CSS for presentation.
New eBook - Guide to Semantic HTMLBen Hunt adds another great eBook to the collection with his "Guide to Semantic HTML". The book gives you advice and tips on how, and why to use semantic HTML.
Included is a comprehensive list of HTML tags, each with their semantically appropriate uses, along with a worked example taking you through the process of how to build a website using semantic HTML.
Do you love our approach to crafting simple & effective web sites that just work for people?
We'd love to hear about your web strategy. Contact one of our team today!