0

I'm working on an online store. I've learned a little PHP and so I'm using a single template file with some conditional includes and such rather than building separate product pages (no database yet though, still learning!).

So I have sections that only exist once per instance of the template (ie once per page) such as section id="product_image". Normally that would be identified with an id. But on a template which is reused a bunch of times do you think class would be more semantically appropriate? (yes I know there's no functional/technical need to switch to class)

Lee Saxon
  • 457
  • 3
  • 14

2 Answers2

0

An id is singular. There can be only one of the same ID on the page, and an element may only have one ID attribute.

So if your component gets reused, the ID must be different between reuses (Perhaps some sort of database primary key, or something similar).

A class name describes your elements semantically, i.e. this section is a what? widget? calendar? featured articles? That's what a class name is for.


Personally, I always use class names, and only use IDs if I want the link-scroll functionality. Classes, are everything IDs are, but more flexible.

Madara's Ghost
  • 172,118
  • 50
  • 264
  • 308
0

the id and class attributes may be used for structure and functionality, but not semantic meaning, although readability in markup is a great aim.

To infuse your markup with meaning, use semantic elements, and structured data.

The Google Structured Data Testing Tool is a great resource.

code_monk
  • 9,451
  • 2
  • 42
  • 41