It would be much, much better, in terms of both validity and semantics, if you wrote it using classes for your CSS instead:
<!DOCTYPE html>
<html>
<head>
<style>
.p01 {
color: blue;
}
</style>
</head>
<body>
<h1 class="p01"> Heading</h1>
<p>This is a paragraph.</p>
<p class="p01">This is a diff paragraph.</p>
<p>This is a paragraph.</p>
<p class="p01">I am different.</p>
</body>
</html>
Just because it works using id
doesn't mean that it's correct. Imagine in a month that you want to add some javascript to get only one of those elements, you couldn't then use this:
var e = document.getElementById("p01");
because you couldn't be certain of what would be returned.
One way to look at it is by thinking of houses. Imagine that classes define the types of houses (apartments, bungalows, houses with pitched roofs etc), whereas ids define specific houses (John's house, Wendy's house etc).
Now imagine that you want to have all the bungalows painted red. Using the class, you can easily grab all of them at once, like:
var houses = document.getElementsByClassName("bungalow");
paint_red(houses);
Now imagine that you want to send a package to Wendy's house. In this case, you can find that specific house using its id:
var wendys_house = document.getElementById("wendy");
send_package_to(wendys_house);
Because you know that the id
is unique, you can be certain that only Wendy's house will receive a package.