Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

invalid tags in HTML <abc> vs <1234>

Tags:

html

web

I was writing a simple web page. And I wanted to print <abc> and <1234> inside the page. Why <1234> is printed not <abc>? I know <abc> is invalid tag thats why it is not rendered. But what about <1234>?

like image 669
Naman Avatar asked Nov 24 '25 00:11

Naman


2 Answers

This is down to the way that browsers parse the HTML into a format that gets displayed as a web page.

As a rule, HTML tags must start with letters. Because of this, the browser attempts to parse as a valid tag (therefore hiding it), but doesn't recognise <1234> and therefore leaves it untouched.

Edit:

As @Arkana pointed out below, there's nothing I can see in the HTML specification that specifically forbids starting a HTML tag with a number. My best guess is that because no (currently valid) HTML tags actually do start with a number, the browser's parser just ignores these tags, based on the same rule that IDs and Names follow according to the HTML4 spec.

like image 72
BiscuitBaker Avatar answered Nov 26 '25 16:11

BiscuitBaker


You have to do it like:

and &lt;1234&gt;

Use HTML entities.

&lt; = <
&gt; = >

Using them tells HTML that you want the < and > to be displayed as it is and not be interpreted as the < and > in <html>

DEMO

P.S.: Here's a list of them.

like image 20
HighBoots Avatar answered Nov 26 '25 17:11

HighBoots



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!