<p> or <br>

J

Jim Scott

Is it a debateable point or 'whatever suits' as to whether test is
presented using <p> or <br> tags?
 
S

Steve Pugh

Jim said:
Is it a debateable point or 'whatever suits' as to whether test is
presented using <p> or <br> tags?

No.

If it's a paragraph then mark it up with a <p> element.

If it's a line break then mark it up with a <br> element.

They mean different things and in most browsers result in a different
presentation.

Steve
 
A

Andy Dingley

Jim said:
Is it a debateable point or 'whatever suits' as to whether test is
presented using <p> or <br> tags?

Neither - it's very clear.

<p>Marks the boundaries of a paragraph. <br> is an inline element that
marks a line break, where it occurs _within_ some piece of text. That's
really all there is to it - it's pretty clearly stated, if only you
follow the HTML spec through in detail.

<br><br> is always wrong. You've broken the line once, how do you break
it a second time?

If you want a debate, then it's less clear-cut when you should use <p>
and <div>. Obviously <p> is used for paragraphs and <div> should be
used for "chunks fo text that aren't a grammatical paragraph", but this
is a viable grammar question about similar HTML constructs when <p> vs.
<br> is really comparing chalk and cheese.
 
J

Jim Scott

Neither - it's very clear.

<p>Marks the boundaries of a paragraph. <br> is an inline element that
marks a line break, where it occurs _within_ some piece of text. That's
really all there is to it - it's pretty clearly stated, if only you
follow the HTML spec through in detail.

<br><br> is always wrong. You've broken the line once, how do you break
it a second time?

If you want a debate, then it's less clear-cut when you should use <p>
and <div>. Obviously <p> is used for paragraphs and <div> should be
used for "chunks fo text that aren't a grammatical paragraph", but this
is a viable grammar question about similar HTML constructs when <p> vs.
<br> is really comparing chalk and cheese.
Not quite.
On my site, which is almost all pictures with text, using <br> avoids a space
appearing between the text and the picture or is that because I use </p>?
 
S

Steve Pugh

Jim said:
On my site, which is almost all pictures with text, using <br> avoids a space
appearing between the text and the picture or is that because I use </p>?

Most browsers give top and bottom margins to paragraphs. So <p>...</p>
will have some white space before and after it.

You can suggest that the margins be zero size via CSS, so if it is
logically a paragraph but you don't want the white space, use
<p>...</p> and set the margins to zero in CSS. But if it is not
logically a paragraph don't use <p>...</p>.

Steve
 
A

Andy Dingley

Jim said:
On my site, which is almost all pictures with text, using <br> avoids a space
appearing between the text and the picture or is that because I use </p>?

What's a "space" ? Sounds like a presentation issue, in which case
don't worry about it in the HTML, leave it to the CSS.

If you <img> is part of the same para as the text, then use <br>
between them.

If your test is a separate paragraph beneath the image (or above, or
alongside it) then use <p>...</p> and put the <img> elsewhere.
 
J

jojo

Andy said:
What's a "space" ? Sounds like a presentation issue, in which case
don't worry about it in the HTML, leave it to the CSS.

If you <img> is part of the same para as the text, then use <br>
between them.

If your test is a separate paragraph beneath the image (or above, or
alongside it) then use <p>...</p> and put the <img> elsewhere.
And if you have got a image with some subtitle or description use a
<div> (because it'S no "grammatical paragraph" as andy already said).
 
R

rvtol_pe

<br><br> is always wrong. You've broken the line once, how do you break
it a second time?

I don't see why this is wrong. BR is a single line break and there is
nobody forbidding you to use 2 of them and it will validate correctly.
The P tag simply helps you to define a paragraph and to have some more
flexibility when it comes to styling; however, there are plenty of
cases that would have a double BR making your code more readable.
 
J

John Salerno

I don't see why this is wrong.

there are plenty of
cases that would have a double BR making your code more readable.

Do you mean more readable in a text editor? If so, why would you use an
HTML tag for this?
 
J

John Salerno

Andy said:
Obviously <p> is used for paragraphs and <div> should be
used for "chunks fo text that aren't a grammatical paragraph"

Just out of curiosity, where did you get that quote from? I can see why
it would be confusing if <div> is still defined in terms of "text" and
"paragraph", but it seems (to me, at least) that <div> is really used
for sections of your webpage that are distinct in terms of overall
content, i.e. a header and a footer can each be a <div>, the main body
could be, sidebars could be, etc. In those terms, it has nothing to do
with text or paragraphs necessarily.
 
H

Harlan Messinger

I don't see why this is wrong. BR is a single line break and there is
nobody forbidding you to use 2 of them and it will validate correctly.

"Colorless green dreams sleep furiously" is a syntactically correct
English sentence that would would pass an English validator if one
existed, but it is also meaningless.

This is an example of
a sentence with a line break in it.

This is another example of



a sentence with a line break in it.

In each case, the sentence is broken in one place, i.e., there is *one*
line break. In the second example, I choose to make the two parts appear
farther apart than they normally would, and in an e-mail I have to use
multiple line break characters to make that happen, but still, the text
is broken only *once*. In HTML, <br> represents the fact of the line
being broken, and <br><br> is redundant; layout is controlled using
styles. If you want something that looks like this:

The equation

z^2 = x^2 + y^2

is the heart of the Pythagorean Theorem.

use styles.

..subquote { display: block; margin: 1em 0 1em 2em; }

<p>The equation <span class="subquote">z^2 = x^2 + y^2</span> is the
heart of the Pythagorean Theorem. said:
The P tag simply helps you to define a paragraph

It doesn't help you to define one. It denotes one.
and to have some more
flexibility when it comes to styling; however, there are plenty of
cases that would have a double BR making your code more readable.

There are cases where extra spacing makes your code more readable. A
double BR isn't the correct way to accomplish that. Let's put it this
way: why is the amount of spacing created by two BRs necessarily what
you want? What if the desirable amount of space corresponds to 1.3 BRs?
What if the part after the break (as in the above example) shouldn't be
aligned with the part before it? Then what?
 
P

patrick j

I don't see why this is wrong. BR is a single line break and there is
nobody forbidding you to use 2 of them and it will validate correctly.
The P tag simply helps you to define a paragraph and to have some more
flexibility when it comes to styling; however, there are plenty of
cases that would have a double BR making your code more readable.

I think it's a matter of style.

I would always tend to use <p> and then use CSS to adjust spacing.

This is also true of my use of word processors. I always use the para
spacing to create space between para's, I never use empty line breaks
as do many people.

The advantage I think of adjusting spacing for <p> is that it is
incremental whereas using more than one <br> is not very adjustable.

At least that's the way I see it :)
 
A

Andy Dingley

John said:
Just out of curiosity, where did you get that quote from?

Not a quote, it's just indicating an approximation -- in particular
that usinmg <div> in this way (non-para text) doesn't also rule it out
for the other uses of <div>. Quite obviously the content model of
<div> is different from <p> for a start - you can put <div> or <p>
inside a <div>, but never inside a <p>
 
R

RvT

John Salerno schreef:
Do you mean more readable in a text editor? If so, why would you use an
HTML tag for this?

No, more readable when editing your HTML code in an editor. <p></p> is
a new nesting, making the code in certain situations more difficult to
read.
 
C

Chris F.A. Johnson

I don't see why this is wrong. BR is a single line break and there is
nobody forbidding you to use 2 of them and it will validate correctly.
The P tag simply helps you to define a paragraph and to have some more
flexibility when it comes to styling; however, there are plenty of
cases that would have a double BR making your code more readable.

All cases where you want a two-line space can be handled with CSS.
 
J

Jim S

All cases where you want a two-line space can be handled with CSS.

Hello!
If you come in the middle of a thread, please read what went before.
I am trying to avoid a 'whitespace' as I now know it is called (jargon
bluddy jardon) not create one extra.
 
L

Leif K-Brooks

Jim said:
If you come in the middle of a thread, please read what went before.
I am trying to avoid a 'whitespace' as I now know it is called
(jargon bluddy jardon) not create one extra.

Chris was replying to rtvol_pe, not to you.
 
T

Toby Inkster

Jim said:
On my site, which is almost all pictures with text, using <br> avoids a space
appearing between the text and the picture or is that because I use </p>?

Note the difference in rendering between:

<p>text <img></p>

and

<p>text</p> <img>

Also, note that "</p>" is an optional tag. So which of the two examples
above do you think is equivalent to:

<p>text <img>

?

It's the first one.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top