1

I found that the end result is the same if you code the "normal" way like this:

<p>
This is a paragraph text section.
</p>
<p>
This is a paragraph text section.
</p>
<p>
This is a paragraph text section.
</p>
<p>
This is a paragraph text section.
</p>

compared to coding like this, in which only every other paragraph text is coded with p:

This is a paragraph text section.
<p>
This is a paragraph text section.
</p>
This is a paragraph text section.
<p>
This is a paragraph text section.
</p>

This would save space, but are there any compelling reasons to not do it this way?

jamiestroud69
  • 237
  • 1
  • 12
  • 2
    For one, any css applicable to `p` wouldn't be applied to the skipped paragraphs. Instead of mutilating the Html, look [at minifying it](http://stackoverflow.com/questions/728260/html-minification) ? – StuartLC Apr 06 '15 at 10:33

1 Answers1

4

As pointed out by @StuartLC:

css applicable to p wouldn't be applied to the skipped paragraphs

While your code risks this behavior, you could still minify it by taking into account that the closing p tag is optional in HTML5. Google's Style Guide even recommends omitting optional tags.

So you could write the code like this, without losing any p CSS properties:

<p>This is a paragraph text section.
<p>This is a paragraph text section.
<p>This is a paragraph text section.
<p>This is a paragraph text section.

Snippet

body {font: 13px verdana;}
p {color: red;}
<strong>Alternating `p` elements:</strong>
<p>This is a paragraph text section.</p>
This is a paragraph text section.
<p>This is a paragraph text section.</p>
This is a paragraph text section.
<hr>
<strong>With no closing `p` tags:</strong>
<p>This is a paragraph text section.
<p>This is a paragraph text section.
<p>This is a paragraph text section.
<p>This is a paragraph text section.
Rick Hitchcock
  • 33,093
  • 3
  • 40
  • 70