Tell me more ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

I'm trying to develop a base for a blog using some of the new tags introduced in HTML5 and I want to not only make sure I'm using them correctly, but my code is also semantic.

Here is just the 'sample' document.

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<title>page title</title>
</head>
<body>
<div class="container">
    <header>
        <hgroup>
            <h1>Blog title</h1>
            <h2>Blog tagline goes here</h2>
        </hgroup>
        <nav>
            <ul>
                <li><a href="#top-level-link">Top Link</a></li>
                <li><a href="#top-level-link">Top Link</a></li>
                <li><a href="#top-level-link">Top Link</a></li>
            </ul>
        </nav>
    </header>
    <!-- <hr> commenting out so the answers still make sense -->
    <aside>
        <nav>
            <ul>
                <li><a href="#">sidebar link</a></li>
                <li><a href="#">sidebar link</a></li>
                <li><a href="#">sidebar link</a></li>
            </ul>
        </nav>
    </aside>
    <div class="content">
        <article>
            <h3>Article Header</h3>
            <section>
                <h4>Section header</h4>
                <p>Article section content</p>
            </section>
            <section>
                <h4>Section header</h4>
                <p>Article section content</p>
            </section>
            <section>
                <h4>Section header</h4>
                <p>Article section content</p>
            </section>
            <footer>
            posted by <a rel="author" href="#">user</a> on <time datetime="2012-01-01T00:00+00:00">January 1st, 2012. 12:00pm</time>
            </footer>
        </article>
        <article>
            <h3>Article Header</h3>
            <section>
                <h4>Section header</h4>
                <p>Article section content</p>
            </section>
                    <!-- more sections may exist per article -->
            <footer>
            posted by <a rel="author" href="#">user</a> on <time datetime="2012-01-01T00:00+00:00">January 1st, 2012. 12:00pm</time>
            </footer>
        </article>
        <article>
            <h3>Article Header</h3>
            <section>
                <h4>Section header</h4>
                <p>Article section content</p>
            </section>
                    <!-- more sections may exist per article -->
            <footer>
            posted by <a rel="author" href="#">user</a> on <time datetime="2012-01-01T00:00+00:00">January 1st, 2012. 12:00pm</time>
            </footer>
        </article>
    </div>
    <!-- <hr> Don't wanna make these guys look crazy -->
    <footer>
    Page footer.
    </footer>
</div>
</body>
</html>

Can anyone see any misuse of the new tags or any better - cleaner way to write this?

share|improve this question
2  
Also, <meta charset="utf-8">. It's probably simpler. – TRiG Jun 26 '12 at 17:12
lol probably. :) – rlemon Jun 26 '12 at 17:30

2 Answers

up vote 9 down vote accepted

Quick review:

  • Remove this damn <hr>, styling is for CSS.
  • In each <section>, you better have an <h2> :-)
  • You can add rel="author" to your <a> link on the author. Even better, you can use <a href="https://url.to.google.plus/user?rel=author" rel="author">The author's name</a> (Google will recognize this as a "rich snippet" and show your face in google results. Take a look at http://schema.org for more information). Rich snippets are a whole other topic, so I'll stop talking about it :)

Edit after your comment:

  • Each article should contain an <h2> for its article sections.
  • Each article should have its title in an <h1>. Yes, even if there are multiple <h1> in the main page. If there is just the titles on the main page (no article's text), feel free to use <h2>.
  • The <h1> on the frontpage is tolerated, not on the blog pages. Feel free to use it or not on the frontpage, but make sure that each blog page has the title of the post as an <h1>, not the site's name.

Related picture:

flowchart

share|improve this answer
you mean in each section have a h4? – rlemon Jun 26 '12 at 13:32
@rlemon edited. – Florian Margaine Jun 26 '12 at 13:39
Primary headers in the page, <article>s, and <sections> should use <h1> elements. If the region has a secondary header <h2> should be used. – zzzzBov Jun 26 '12 at 17:02
@zzzzBov even though semantic html is nice, we also can't forget about SEO. That's why using H1 elements everywhere is often not an option (or rather, not the best option). – Florian Margaine Jun 26 '12 at 17:05
@FlorianMargaine, the question was about semantic HTML, and not optimizing for search engines. Besides, google's (not worth pretending that anyone uses a different search engine) algorithms follow common web practices, and are adapting to support HTML5. – zzzzBov Jun 26 '12 at 17:37
show 3 more comments

In my opinion for the most part, that looks good. However, there are a few small things I would question.

  • Do you really need the wrapper div element? I would remove it so you have the header as the first child of the body.

  • I would probably get rid of the section elements of each article. While their use is probably semantically valid, I think just the p elements would suffice.

  • The contents of the time elements currently causes your document not to validate. See the relevant part of the HTML5 spec for more details. Here's the error from the validator:

    The text content of element time was not in the required format: The literal did not satisfy the date or time format.

Update

  • The hr element is not semantically valid in the way you have used it. It could be replaced with CSS targeting the page header and footer. From the spec (emphasis added):

    The hr element represents a paragraph-level thematic break, e.g. a scene change in a story, or a transition to another topic within a section of a reference book.

share|improve this answer
I gave him the same answer about section in article tags. Then after reading the specs and some posts about that, it seems that for big articles, section is really appropriate to subdivide a blog post, and then add header, headings and footer to every section – DieVarDump Jun 26 '12 at 13:16
Ahh I also misread the TIME tag spec... Adding datetime attribute (with a valid value) will correct the validator errors. Thanks:) – rlemon Jun 26 '12 at 13:25
ahh also did not know that about the HR element.. – rlemon Jun 26 '12 at 13:32
@DieVarDump - I'm not sure that each section in this case would need a header and footer, hence the suggestion to remove the section elements. I'm not entirely sure on that point though. – James Allardice Jun 26 '12 at 13:34
I think having a header is probably prudent... but a footer may not be needed for each section. (but this should be reviewed per article basis... not every article will need more than one section.) – rlemon Jun 26 '12 at 13:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.