tags:

views:

79

answers:

2

I know that it's incorrect to style a <section> tag but how about the <header> and <footer> tags. If using these tags provides a more semantic markup then they should be used, however, if they can't be styled then a <div> would still need to be inserted inside the tag to wrap the content and style it.

I know that <header> can be styled but I'm not sure if it's correct to do so.

So the question is: Should html5 tags be styled or should a <div> be placed inside to take care of the styling?

+1  A: 

It's is not incorrect to style these tags, but they are not solely for styling purposes as they serve a semantic function. By all means style the elements that you need to use, but don't add them to achieve styles thereby ruining the semantics.

Having said that you must also beware of styling them as they are not recognised by all browsers. For example IE6 and 7 will not apply the styles as they won't recognise the element names. You can get around this in IE7 using ARIA tags which will allow you some styling control.

lnrbob
+5  A: 

Nothing in the spec says you can't or shouldn't style HTML5 elements such as <section> or <article>. It only says that you shouldn't place a semantic HTML5 element somewhere 'for the sake of' styling something. Use a <div> instead.

So if you have a semantic reason to add the <section> or <article> somewhere, then by all means add it AND also feel free to style it as well. But if you have to wrap a section of your mark-up for styling purposes (eg. to add a border, or float left etc.), but that section does not have any semantic meaning in your mark-up, then use a <div>.

For instance:

<div class="mainBox">
    <nav class="breadcrumbs">
        <ol>
            <li>...list of links (snip)....</li>
        </ol>
    </nav>

    <section>
        <h1>Latest Tweets From Twitter</h1>

        <article>
            //... a Tweet (snip)... //
        </article>

        <article>
            //... a Tweet (snip)... //
        </article>

        //... lots more Twitter posts (snip)... //

    </section>

</div>

The <section> element is the main part of your page (ie. your list of tweets) and also has a heading at the start which is required. But it's wrapped in a div.mainBox element because maybe you want to wrap a border around the both the breadcrumbs and section parts, ie. it's purely for styling. But there's nothing to stop you styling the <section> and <article> elements also.

Sunday Ironfoot