can someone explain to me , why is this code valid?
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html<head>
<title//
<p ltr<span id=p></span</p>
</>
I look forward to receiving your reply. thanks for attention
Take checkHTML("<p>Test<P>test") for instance. That is perfectly valid HTML, but the browser will normalize it when it pulls it back out of innerHTML . There will be no text outside an element in the DOM generated from that valid HTML.
correct: a valid document is correctly displayed by the browser. debugging: invalid HTML code can trigger bugs hard to target. maintenance: a valid document is easier to update later, even by someone else.
Possible Reasons:You might not have saved the changes after writing the code (most likely). Problem with the browser (load it in another browser) Check the extension (just for clarification)
Those HTML code is valid because HTML 4.01 allow those things, and Internet browser who respect doctype, will display that with no problem.
If you change the doctype to HTML 5, it will definitely give error, since HTML 5 is more strict about writing proper HTML tag.
HTML 4.01 (no error according to https://validator.w3.org/#validate_by_input):
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html<head>
<title//
<p ltr<span id=p></span</p>
</>
HTML 5 (15 error according to https://validator.w3.org/#validate_by_input):
<!DOCTYPE html>
<html<head>
<title//
<p ltr<span id=p></span</p>
</>
Explanation:
That HTML structure is valid because according to HTML 4.0.1 Specification (https://www.w3.org/TR/1999/REC-html401-19991224/):
B.3.7 Shorthand markup
Some SGML SHORTTAG constructs save typing but add no expressive capability to the SGML application. Although these constructs technically introduce no ambiguity, they reduce the robustness of documents, especially when the language is enhanced to include new elements. Thus, while SHORTTAG constructs of SGML related to attributes are widely used and implemented, those related to elements are not. Documents that use them are conforming SGML documents, but are unlikely to work with many existing HTML tools.
The SHORTTAG constructs in question are the following:
- NET tags:
<name/.../
- closed Start Tag:
<name1<name2>
- Empty Start Tag:
<>
- Empty End Tag:
</>
Quoted from https://www.w3.org/TR/1999/REC-html401-19991224/appendix/notes.html#h-B.3.7.
So based on that HTML 4.01 Specification, this means:
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
2 <html<head>
3 <title//
4 <p ltr<span id=p></span</p>
5 </>
<html>
open tag, closing </html>
tag is not necessary.<head>
open tag, closing </head>
tag is not necessary.<title>
open tag which Internet browser read <title// <p ltr<span id=p>
simply as <title>
, closing </title>
tag is not necessary.<title>
tag which is </span</p> </>
(this is what Internet browser display as the title of the page).That was my additional explanation. Hope that able to help you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With