1

According to specs, I've fulfilled all the criteria but still, CSS doesn't apply.

The id attribute specifies its element's unique identifier (ID). The value must be unique amongst all the IDs in the element's home subtree and must contain at least one character. The value must not contain any space characters.

So what are the valid id values in HTML5?

#123123c{
  color: red;
}
<div id="123123c"> Hello DEVELOPERS solve this problem </div>
DecPK
  • 24,537
  • 6
  • 26
  • 42

2 Answers2

4

let me grab it for you. if there might some people stuck on this issue

That’s because even though HTML5 is quite happy for an ID to start with a number, CSS is not. CSS simply doesn’t allow selectors to begin with a number. The relevant part of the specification states:

In CSS, identifiers (including element names, classes, and IDs in selectors) can contain only the characters [a-zA-Z0-9] and ISO 10646 characters U+00A0 and higher, plus the hyphen (-) and the underscore (_); they cannot start with a digit, two hyphens, or a hyphen followed by a digit. Identifiers can also contain escaped characters and any ISO 10646 character as a numeric code (see next item).

W3C Specification.

But, you can easily work around this by using an attribute selector:

[id="123123c"] {
  color: red;
}
<div id="123123c"> Hello DEVELOPERS solve this problem </div>
James Tubiano
  • 231
  • 3
  • 17
0

The id selector cannot start with numbers ...it must start with alphabet or underscore(_)

<!DOCTYPE html>
<html>
<head>
<style>
#_123123c {
  color: red;
}
</style>
</head>
<body>
<div id="_123123c"> Hello DEVELOPERS solve this problem </div>
</body>
</html>