Assassinbeast
Assassinbeast

Reputation: 1277

HTML validator fails with custom html elements

When i try to validate an HTML file with custom elements, then it will get errors.

Can anyone explain why? Here is an example:

<!DOCTYPE html>
<html>
	<head>
		<title>Some app</title>
	</head>
	<body>
		<div data-wt="hmm">
			<hello-world>Yes!</hello-world>
		</div>
	</body>
</html>

Then it says that the hello-world element is not valid. But the custom attributes are valid.

Upvotes: 1

Views: 41

Answers (1)

Alex
Alex

Reputation: 35118

While you can invent new attributes (by using data-...) you can not just invent new elements - this would make the HTML invalid.

You could register new elements, as described here.

var XFoo = document.registerElement('hello-world', {
  prototype: Object.create(HTMLElement.prototype)
});

But as this use JavaScript, the validator will still not pass.

Upvotes: 1

Related Questions