Home >Web Front-end >CSS Tutorial >Can HTML IDs Start with Numbers?
Yes, it is valid to have an HTML element with an ID that starts with a number. IDs can consist of any non-whitespace character except space, including numbers.
However, Using IDs Starting with Numbers in CSS Selectors Can Be Problematic:
While valid in HTML, using IDs starting with numbers in CSS selectors can be challenging. To select an element with such an ID, the leading number must be escaped using the ASCII character code, which can be inconvenient and error-prone. For example, to select an element with the ID "12", the CSS selector would be #3132.
Recommendations:
If you plan to use CSS selectors to style or target elements with numeric IDs, it's generally recommended to start the IDs with letters to avoid the need for escaping. For example, #my-element-12 would be a more practical choice than #12.
The above is the detailed content of Can HTML IDs Start with Numbers?. For more information, please follow other related articles on the PHP Chinese website!