Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why is this html code valid? [closed]

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

like image 572
Giorgi Gogitidze Avatar asked Feb 24 '16 11:02

Giorgi Gogitidze


People also ask

How do you check is HTML valid or not?

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.

What does valid HTML mean?

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.

Why my HTML code is not working?

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)


1 Answers

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        </>
  • Line 1 is valid doctype for HTML 4.0.1.
  • Line 2 is valid <html> open tag, closing </html> tag is not necessary.
  • Line 2 is also valid <head> open tag, closing </head> tag is not necessary.
  • Line 3 is a valid <title> open tag which Internet browser read <title// <p ltr<span id=p> simply as <title>, closing </title> tag is not necessary.
  • Line 4-5 is the content (inner HTML) of <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.

like image 65
ichan-akira Avatar answered Sep 28 '22 12:09

ichan-akira