Home > Blockchain >  Random Letter html Tag
Random Letter html Tag

Time:12-05

I was wondering if you can use a random letter as an html tag. Like, f isn't a tag, but I tried it in some code and it worked just like a span tag. Sorry if this is a bad question, I've just been curious about it for a while, and I couldn't find anything online.

CodePudding user response:

I was wondering if you can use a random letter as an html tag.

Yes and no.

"Yes" - in that it works, but it isn't correct: when you have something like <z> it only works because the web (HTML CSS JS) has a degree of forwards compatibility built-in: browsers will render HTML elements that they don't recognize basically the same as a <span> (i.e. an inline element that doesn't do anything other than reify a range of the document's text).

However, to use HTML5 Custom Elements correctly you need to conform to the Custom Elements specification which states:

The name of a custom element must contain a dash (-). So <x-tags>, <my-element>, and <my-awesome-app> are all valid names, while <tabs> and <foo_bar> are not. This requirement is so the HTML parser can distinguish custom elements from regular elements. It also ensures forward compatibility when new tags are added to HTML.

So if you use <my-z> then you'll be fine.


The HTML Living Standard document, as of 2021-12-04, indeed makes an explicit reference to forward-compatibility in its list of requirements for custom element names:

https://html.spec.whatwg.org/#valid-custom-element-name

  • They start with an ASCII lower alpha, ensuring that the HTML parser will treat them as tags instead of as text.
  • They do not contain any ASCII upper alphas, ensuring that the user agent can always treat HTML elements ASCII-case-insensitively.
  • They contain a hyphen, used for namespacing and to ensure forward compatibility (since no elements will be added to HTML, SVG, or MathML with hyphen-containing local names in the future).
  • They can always be created with createElement() and createElementNS(), which have restrictions that go beyond the parser's.
  • Apart from these restrictions, a large variety of names is allowed, to give maximum flexibility for use cases like <math-α> or <emotion-
  • Related