Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

<p> or <br> for line breaks?

Status
Not open for further replies.

yippiekyyay

Programmer
Oct 26, 2002
186
CA
In my web pages, I always suppress the space after a <p> and use <br> when needed instead. I remember reading awhile ago though that you should use <H> and <P> tags while avoiding <br> - but I can't remember the reason or find any info on this. I would just like to make sure that I am doing things properly (and would like to know why one way is better than the other) - any info on this subject would be greatly appreciated!

-Sean
 
either of them are good. but personally speaking i love <br>...

Known is handfull, Unknown is worldfull
 
I don't think there is a real reason as far as expiring tag or anything, at least I do not think <p> is going away, but the <p> tag just does funny things and sometimes makes it hard to control things around it, spacing, images, tables, etc.

AJ
[americanflag]

If at first you do not succeed, cheat!


 
Thanks for the replies everyone!

I'm happy to hear about the usage of <br>, because I find that so much easier to use and to read in code.

Thanks again for the reassurance (with all these W3C standards, etc, I start to get really unsure).

Cheers
-Sean

 
the <p> tag is handy if you want to use &quot;indent&quot; or other style features in the css.

<style>p {text-indent: 8pt} </style>



Clive
 
I think it depends on whether you want to use CSS or not in the future (personally, the answer to this is yes).

If you don't - continue using breaks for spacing (<br>) and tables to layout the page.

If you do, i'd recommend splitting your text into paragraphs with <p> and setting their layout with CSS. Also don't use tables (haven't quite gotten to this level myself) for layout - instead switch to <div> and <span> and CSS.

ultimately, pages should separate layout from content (there is plenty of discussion about this), making it easier to change one without having to trawl through the other. Using CSS and avoiding 'layout' tags (eg.. <font color=&quot;..) in your HTML looks like the way to go to achieve this.

:)


Posting code? Wrap it with code tags: [ignore]
Code:
[/ignore][code]CodeHere
[ignore][/code][/ignore].
 
They are different tags with (perhaps subtly) different purposes....
[tt]
<p>This is a paragraph of text, enclosed within the relevant tags. Most browsers will render it with whitespace above/below it, but you can get rid of that with CSS. Note I include the (optional in HTML) closing tag 'cos it makes it clearer what's going on</p>

<p>This is another, but also a rhyme<br>
I make sure the line breaks the same place every time</p>
[/tt]
(OK, OK, I am the webmaster of :))

<p> tags identify a block of text as a paragraph, you can apply styles to it to change the font, background colour, margins etc. <br> is an inline tag that says &quot;put a line break here&quot;, it is intended to have limited uses - in poetry, program listings, etc. It's not a replacement for <p>.

Strictly speaking, your page has some content: say, a whole load of text. You use HTML tags to &quot;mark up&quot; that content, identifying (amongst other things) where paragraphs begin and end. The browser renders the marked up content according to a set of rules for how each element should be shown. You can amend those rules using CSS.

So, what you should do, if you want no space between your paragraphs (though the spacing makes them easier to read IMO) is something like this:
[tt]
<html>
<head>
<title>Look no BR's</title>
<style>
p { margin:0 }
</style>
</head>
<body>
<p>This is on one line</p>
<p>This is the next</p>
</body>
</html>
[/tt]
Put that style declaration in a seperate file and you can change the look (and spacing) of paragraphs across your site at a single stroke.

btw, <br>'s days are numbered. They're getting rid of it altogether in XHTML2. See
-- Chris Hunt
Extra Connections Ltd

The real world's OK for a visit, but you wouldn't want to LIVE there!
 
ChristHunt:
Mcgonagall - Well i am a Harry Potter buff. so i thought McGonagall here was one of those chracters.

:)

Known is handfull, Unknown is worldfull
 
Well, now you know where Ms Rowling got the name from!

-- Chris Hunt
Extra Connections Ltd

The real world's OK for a visit, but you wouldn't want to LIVE there!
 
Thanks again guys, good discussion!

I do employ CSS, but sometimes it seems unecessary to </p> and then <p class=&quot;whatever&quot;> for each new pragraph when I could just <br><br> (I hope that sentence makes sense).

I thought that perhaps marking off each paragraph in <p> tags help if you ever do something like render it to xml (which I know nothing about - ...but may some day).

I do believe in seperating content from layout, but I am surprised to read that you prefer not to use tables - what about people who ignore style sheets or who use older browsers?

Thanks again everyone!
-Sean
 
Using tables to control the layout of a page was a convenient misapplication of the HTML standard. All the newer browsers support css positioning and, although it can be a bit fudgy, I well remember the frustration of counting all my colspans and much prefer it.

People who ignore stylesheets get exactly what they want -> a page devoid of any 'presentational' information.

People who use older browsers are a mystery to me

MrBelfry
 
Hey MrBelfry - I like your logic!

Your answer to the CSS question is perfect, but unfortunately (in my work) I cannot ignore those who use older browsers (although, the percentage is very small).

I think I will try to start incorporating it for layout!

Cheers,
-Sean

 
Who said I prefer not to use tables? I'm still using them on all my sites, and have just said why here: thread253-610732 .

Using <p> instead of <br><br> is worth it though. True, it makes little difference when you first type the page in - but one day you'll want to change that layout and you'll find it much easier to do if it's properly marked up.

-- Chris Hunt
Extra Connections Ltd

The real world's OK for a visit, but you wouldn't want to LIVE there!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top