HTML Element ID's can't start with a number

  • Category: Code
  • Last edited: June 16, 2016

I was recently building a jQuery-based slider for our upcoming website re-launch and needed to identify a series of elements numerically. Naturally I decided a number that auto-incremented would be ideal, so I build a testing stage to do just that.

After about 2 hours of testing and debugging to try find out why it wasn’t working, I changed the numerical ids to “block-one”, “block-two”, etc. This solved everything! It turns out that CSS does not allow elements’ ids to begin with a number. But classes are.

Who knew? Now you do. HTML ids cannot start with a number.