5

So, I'm diving into the HTML5 template tag, as a possible future solution to my web application problems. One thing that I don't seem to find is: Can you use the id attribute inside the template tag?

The template can be reused, but ids can't be. So using the same template multiple times (which is why they were invented in the first place) will result in invalid HTML, theoretically. Any official answers?

2 Answers 2

7

Can you use the id attribute inside the template tag.

Yes, however:

The template can be reused, but id's can't be.

Correct.

So using the same template multiple times (which is why they were invented in the first place) will result in invalid HTML, theoretically.

Yes. Don't do that. Make sure the IDs are unique before you add them to the main DOM. You could edit them in the template's DOM before you append it to the main DOM.

1
  • 2
    So, actually, the first answer is also no :) I'm kind of a purist haha.
    – David
    Apr 26, 2015 at 20:12
0

If you will stamp the template into the main document, the IDs must be unique, however, if you are stamping the template into a shadow root, then you can re-use IDs within the shadow DOM.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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