I've been wondering if I can use <p> </p>
(just space in paragraph) instead of <br />
Because I love to keep my code semantic and thought if this is right has been bothering me for a while now. I have seen WYSIWSG editors (TinyMCE) use this, but I still rather ask then do it wrong.
The p tag is a block level element, and is mainly used to add content, whereas the br tag is used to force a line-break within the element.
The br tag It's an inline element, and does not need a closing tag. We use it to create a new line inside a p tag, without creating a new paragraph. And compared to creating a new paragraph, it does not add additional spacing.
When it comes to learning HTML, two tags that most people learn early on are the paragraph and line break tags, which are <p> and <br /> respectively. These tags put natural breaks in your text so that your web page's content is easier to read.
The <p> element is used to identify blocks of paragraph text. The closing <p> tag is optional and is implied by the opening tag of the next HTML element encountered in an HTML document after an opening <p> tag.
That is not "semantic", an empty paragraph is something that more or less cannot exist, semantically. It contains no information, i.e. no semantic content. All it does is change the visual layout, i.e. the presentation.
You're far better off using styling to change the margins, borders or padding to achieve the effect you're after.
What's wrong with using the margins of the paragraphs for vertical-spacing instead?
<p>Hello World</p>
<p>This is much cleaner than using empty tags with non-breaking spaces.</p>
The right way to do it is with CSS: use the margin-top
or margin-bottom
.
<p> </p>
is pretty horrible... I'd rather see <br>
than that (even though it may be less "correct").
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With