Hi!
When should I use <p and when should I use <div?
Some only use <p strictly for paragraphs, others for almost everything. What do you think?
Thanks
Printable View
Hi!
When should I use <p and when should I use <div?
Some only use <p strictly for paragraphs, others for almost everything. What do you think?
Thanks
<p> should be used when you want to specify a paragraph, <div> should be used to divide your html.
Well I know that... could you give me some precise examples?
Use <p> just for tekst (paragraph).
Use <div> if you want to create some kind of box with content for example image with caption or news containing: header <hx />, paragraph <p>, image <img />, date <p>...
Div is usefull when you want to create collection of tags, if you want to group them all and then position on the webpage as a one element.
HTML Code:<div>
<h1>Lorem Ipsum</h1>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing
elit. Nulla hendrerit ante eu augue. Proin pretium magna
quis pede. Suspendisse potenti. Duis vitae ante nec
risus dapibusimperdiet. Aenean a urna. In auctor metus
id lectus bibendum mollis. Aliquam tincidunt pharetra
lectus. Integer ultrices nonummy mi. Sed egestas massa
vel diam.</p>
<p>Phasellus rhoncus, arcu sit amet ullamcorper
venenatis, justo massa lacinia dolor, id porta ante libero
id ligula. Nullam pretium quam quis orci.Curabitur vitae
urna. Suspendisse urna elit, porttitor non, tincidunt
vitae, hendrerit ac, ligula. Aliquam elementum
accumsan velit.</p>
</div>
A paragraph is one or more sentences that deal with a single, specific thought. This paragraph, for instance, contains two sentences.
When you move on to talk about another thought, you'll start a new paragraph, like this one.
On web pages, paragraphs are usually separated by whitespace corresponding to a blank line. In printed matter, paragraphs are often run together, using some indention of the first line to indicate the start of each new paragraph.
DIVs are generic block-level containers, which you use when there is no semantically correct element type available. It can be used for grouping a number of elements that belong together, so that you can address the group as a whole (e.g., for styling purposes).