dcsimg
www.webdeveloper.com
Results 1 to 12 of 12

Thread: Using <p> to skip lines

  1. #1
    Join Date
    Jun 2008
    Posts
    100

    Using <p> to skip lines

    Hi,I am having trouble with skipping a line using <p>. Previously, I have always used just a single <p> if i wanted to skip lines, but when i validate, it says it's not valid.

    Isn't:

    <p>Hi</p>
    <p>This is netzeye.</p>
    suppose to have result like this?
    Hi

    This is netzeye.

  2. #2
    Join Date
    Nov 2006
    Location
    Springfield, MO
    Posts
    1,541
    Yes. There's probably something else going on in your page. Can you provide a web page address?

  3. #3
    Join Date
    Jan 2007
    Location
    San Diego, California
    Posts
    15
    netzeye-

    A single <p> tag as a line break is not valid HTML because it is missing the closing tag.

    Consider using CSS to change your <p> tag padding, (which would add space after your paragraph) or simply using a <br/> tag to add a new line.

    Using CSS would be the best, most elegant solution.

    -Josh

  4. #4
    Join Date
    Jun 2008
    Posts
    100
    Yep, http://www.netzeye.com/Products/view...ct.php?id=1003


    Joshua, im not sure how to create a line break via CSS, can you please teach me?

  5. #5
    Join Date
    Jan 2007
    Location
    San Diego, California
    Posts
    15
    Just add in your CSS something similar to:
    HTML Code:
    p {padding-bottom:10px}
    That will add a 10px space after each paragraph. It works for all elements displayed as a block (i.e. tables, as I see you utilize frequently).

    -Josh

  6. #6
    Join Date
    Jun 2008
    Posts
    100
    thanks, it works!

  7. #7
    Join Date
    Jan 2007
    Location
    San Diego, California
    Posts
    15
    Happy to help.

    -Josh

  8. #8
    Join Date
    Jun 2005
    Location
    United Kingdom
    Posts
    1,043
    Quote Originally Posted by joshua.toenyes
    netzeye-

    A single <p> tag as a line break is not valid HTML because it is missing the closing tag.......
    Using <p> as a line break is discouraged. However, the closing </p> is optional in HTML 4.01. It is not optional in XHTML, of course.

    9.3.1 Paragraphs: the P element

    <!ELEMENT P - O (%inline* -- paragraph -->
    <!ATTLIST P
    %attrs; -- %coreattrs, %i18n, %events --
    >

    Start tag: required, End tag: optional

    Attributes defined elsewhere

    * id, class (document-wide identifiers)
    * lang (language information), dir (text direction)
    * title (element title)
    * style (inline style information )
    * align (alignment)
    * onclick, ondblclick, onmousedown, onmouseup, onmouseover, onmousemove, onmouseout, onkeypress, onkeydown, onkeyup (intrinsic events )

    The P element represents a paragraph. It cannot contain block-level elements (including P itself).

    We discourage authors from using empty P elements. User agents should ignore empty P elements.
    Last edited by kiwibrit; 08-05-2008 at 04:55 AM.

  9. #9
    Join Date
    Mar 2005
    Location
    Sydney, Australia
    Posts
    7,974
    Quote Originally Posted by kiwibrit
    Using <p> as a line break is discouraged. However, the closing </p> is optional in HTML 4.01. It is not optional in XHTML, of course.
    It is optional for the web browsers because they need to work ouit how to display the paragraph when you leave it out.

    Actually leaving it out of a web page just makes your page harder to maintain and so to save your self errors in the future when you forget where each paragraph ends you should insert a short comment to remind you. </p> is an acceptable format for the comment to take as that is a lot shorter than the alternative <!-- paragraph ends here -->

  10. #10
    Join Date
    Jun 2005
    Location
    United Kingdom
    Posts
    1,043
    I agree - I was a bit in pedant mode. That said, the absence of a closing tag for <p> (in HTML) should not cause a false rendering of a page in a browser.

    Another good reason for closing tags is that it makes switching to xhtml easier should that ever be appropriate.

  11. #11
    Join Date
    Aug 2007
    Posts
    3,767
    Quote Originally Posted by kiwibrit
    I agree - I was a bit in pedant mode. That said, the absence of a closing tag for <p> (in HTML) should not cause a false rendering of a page in a browser.
    But empty <p>s should be ignored and not rendered. The problem would be that the validator probably thinks that the p tag contains the following p tag which would be invalid.

  12. #12
    Join Date
    Jan 2007
    Location
    San Diego, California
    Posts
    15
    Quote Originally Posted by kiwibrit
    Using <p> as a line break is discouraged. However, the closing </p> is optional in HTML 4.01. It is not optional in XHTML, of course.
    Thanks for pointing that out, your are absolutely right... I code everything in XHTML, and that is what I was referring to.

    Still however, using <p> tag for a line break in HTML, even if it is valid, is bad practice at a minimum.

    His page most likely didn't validate because he is using XHTML 1.0 Transitional...

    -Josh

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles