treehouse : what would you like to learn today?
Web Design Web Development iOS Development

correct use of
?

  • Which code is semantically correct ?

    This
    <body>
    <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. </p>


    <p>Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.Lorem ipsum dolor sit amet, consectetuer adipiscing elit</p>
    </body>


    or this

    <body>
    <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.
    <br>
    Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.Lorem ipsum dolor sit amet, consectetuer adipiscing elit</p>
    </body>
  • The first is correct. p=paragraph so a new paragraph should begin with a <p> tag. There aren't many reasons to ever use <br> - one might be for representing poetry, where each line is not a paragraph but demands it's own space.
  • OK . understand THX BOX
  • so BR has no use in our mark-up except poems and other same things ?
  • "jitendra" said:
    so BR has no use in our mark-up except poems and other same things ?

    when you want to break the line......

    I use it a lot I must admit, mind you p /p or br br that is the question???

    I find it easier to use br br, but I am not a purist, i just find it easier
  • something like

    p { padding: 10px 0 0 0 }

    will work and is even easier then <br />

    or put it on the bottom padding, however works best for you or the project.

    :o)
  • I only ever use it for something like this:

    <p>Contact Info:<br />
    First Last<br />
    555-555-5555<br />
    name@company.com</p>


    If you're starting a new paragraph, use the <p> tag.
  • is this better way to do this ?

    <ul>
    <li>Contact Info:</li>
    <li> First Last</li>
    <li> 555-555-5555</li>
    <li> name@company.com
    </ul>
  • Yes, but that requires extra styling, something that I'm usually too lazy to set up.
  • but this is a listing not a paragraph so i think use of <p> and <br> is not a semantic use
  • I would have to disagree with you there. Perhaps it's not the best example. What if I simply want to break a line?

    <p>This is the first part<br /> I want this part to be dropped down below it.</p>

    I would say that is perfectly acceptable and, if I'm not mistaken, exactly what the <br> is there for.
  • <address> tag is much more sematic than ul li as i think. u r showing Contact info not a content text so i would not use <p> and <br> to show contact info atleast.
  • "TheDoc" said:
    I only ever use it for something like this:

    <p>Contact Info:<br />
    First Last<br />
    555-555-5555<br />
    name@company.com</p>


    If you're starting a new paragraph, use the <p> tag.


    This would be an ideal situation to use Microformats. In it's current state the information displayed is meaningless to other computers, therefore you cannot share that information easily nor can you have any impact in terms of SEO. To mark up your content semantically, using appropriate, meaningful tags with their intended function (as laid out at the w3c), then your sites will be searchable and shareable - thus making them achieve higher positions in search engine results and allow greater networking potential. The <br> tag is pretty meaningless in these terms and although not officially deprecated yet, it doesn't add any meaningful value to your markup. Avoid it's use unless you feel you have a valid semantic reason to do so.
  • "jitendra" said:
    <address> tag is much more sematic than ul li as i think. u r showing Contact info not a content text so i would not use <p> and <br> to show contact info atleast.

    The address tag was not intended to be used for street addresses. Rather the address relating to the document itself. It might seem strange but using the <address> tag for your home address is not semantic in HTML terms.