-2

There are many new elements in HTML5, such as main, header, article, section etc.

Is is good idea to not give these elements an id or class?

For example: I have only one main element on the page. Is it a bad idea to give it an id or class?

marcushobson
  • 144
  • 1
  • 2
  • 11
Martin Heralecký
  • 5,649
  • 3
  • 27
  • 65
  • 1
    Yes. No. Maybe. There's no general answer to this. If it works well for you without, then the less code the better. You may or may not get to a point where you *need* to add some distinctive id or class later, it may or may not be troublesome to add it at that point depending on how well you've maintained the code... – deceze Jun 02 '15 at 06:58
  • Already we have same kind of discussion please refer this for your clarification http://stackoverflow.com/questions/298607/css-best-practice-about-id-and-class – Karthi Keyan Jun 02 '15 at 07:10
  • 1
    The question is, what would you need the id or class *for*? It's "nonsense" to give an element id or a class if you don't need it, HTML5 or not. – JJJ Jun 02 '15 at 07:11

3 Answers3

1

For example: I have only one main element on the page. Is it a bad idea to give it an id or class?

It depends

Consider this:
You are using multiple pages,
all pages have one main element each,
but all are linked to one single CSS file,
but you want all main to have some different styling...

You should probably use id here

in any other case where page has only one element of a certain tag and has it's own seprate css it's redundant to use ids or classes

Ashesh
  • 3,499
  • 1
  • 27
  • 44
0

You don't need to give an id to an element which occurs only once in your code, as the id can not be used multiple times. If you have only one header tag, do not give it an id, just operate directly on this tag.

class will of course be handy if you'd assign it to multiple elements on your webpage.

wjkawecki
  • 183
  • 1
  • 9
-1

I think we should use classe for reuse code because ID can't be used more (in page). However, in your case id can wise because there is one element.

For more information, there are great article: css-tricks stackoverflow

Community
  • 1
  • 1
Jean
  • 71
  • 9