0

In What order should you declare “id” and “class” for the same HTML element, and why ? It seems that my questions is reported for being a duplicate, but mine is referring to a specific H1 HTML element in this case. Thank you

<h1 id="orange-text" class="pink-text blue-text">Hello World!</h1>
Cleptus
  • 3,446
  • 4
  • 28
  • 34
attila.hajdo
  • 79
  • 1
  • 10

2 Answers2

2

There is no predefined order for the attributes in terms of passing w3c validation... it's completely up to you. Any order of HTML attributes will have no effect on performance either.

Gökhan Mete ERTÜRK
  • 3,378
  • 2
  • 19
  • 23
1

Order is not important, both of them works correctly. But I always add "id" before "class" because I think is easier to read and the "id" provide more information.

Aitor
  • 455
  • 7
  • 17
  • "id" is only one-word identifier, but class may have a lot of words, which potentially can provide more information. First of all be consistent in your notation/code style, no matter what style do you prefer -- it's not important in current case – zhibirc Jul 26 '18 at 07:15
  • 1
    It's my own rule. I should use "id" for javascript actions, por example. But everyone will have their own style. – Aitor Jul 26 '18 at 07:21