Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's a valid HTML5 document?

I've just been reading the HTML5 author spec. It states that the <html>, <head> and <body> tags are optional. Does that mean that you can leave them out completely and still have a valid HTML5 document?

If I'm interpreting this correctly, it means this should be completely valid:

<!DOCTYPE html> <p>Hello!</p> 

Is this correct?

You can check out the spec here:

http://dev.w3.org/html5/spec-author-view/syntax.html#syntax

"8.1.2.4 Optional tags" is the bit out about it being OK to omit <html>, <head> and <body>

like image 629
d13 Avatar asked Mar 21 '12 00:03

d13


People also ask

What is an HTML5 document?

HTML5 is a markup language used for structuring and presenting content on the World Wide Web. It is the fifth and final major HTML version that is a World Wide Web Consortium (W3C) recommendation. The current specification is known as the HTML Living Standard.

What is a valid document in HTML?

With HTML, the essentials are doctype declaration, <html><head> and </body>. But, you will be amazed to know that a valid HTML document can work without the <head> element. The doctype declaration<! DOCTYPE html> will come always since it tells and instructs the browser about what the page is about.

How do I confirm a document is HTML5?

To confirm if a webpage is HTML5 or 4.01, check the doctype at the very top of the webpage in source code view.

What is the correct DOCTYPE for HTML5?

Correct Option: D doctype html>, doctype is the very first thing to write in HTML5. <!


1 Answers

The title element is indeed required, but as Jukka Korpela notes, it also must be non-empty. Furthermore, the content model of the title element is:

Text that is not inter-element whitespace.

Therefore, having just a space character in the title element is not considered valid HTML. You can check this in W3C validator.

So, an example of a minimal and valid HTML5 document is the following:

<!doctype html><title>a</title> 
like image 162
Smi Avatar answered Oct 14 '22 20:10

Smi