Unique id value in html

This question is more out of curiosity than stuck. I know that the html id must be unique, and I see an error in the html validation. However, browsers are happy to apply style sheets to both elements. This is because they are more relaxed in parsing or what. Does this mean that I can use this for styling, etc. Or has side effects.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>

<style type="text/css">
  #abc { color: red; }
</style>
</head>
<body>
  <div id="abc">Hello Div 1</div>
  <div id="abc">Hello Div 2</div>
</body>
</html>

Output in browsers.
alt text

+3
source share
3 answers

If your browser crashed every time it loaded an HTML page with errors, it would die all the time. And you will not think about the browser.

, , . , .

, , HTML.

+3

. , .

, HTML . , . , .

CSS-.

0

"" css.

side effect: you will feel less comfortable if you want to use getElementById and add dynamic functions. from the point of view of design does not matter.

0
source

Source: https://habr.com/ru/post/1781558/


All Articles