what is the correct syntax of doctype in html5?

1 day ago 3
Nature

The correct syntax of the DOCTYPE declaration in HTML5 is:

html

<!DOCTYPE html>

This declaration must appear at the very beginning of every HTML document before the <html> tag. It is not an HTML tag but an instruction to the browser about the document type and version of HTML being used, enabling standards mode rendering

. The DOCTYPE declaration is case-insensitive, so variations like <!doctype html>, <!Doctype html>, or <!DocType html> are all valid

. For older versions of HTML, such as HTML 4.01 or XHTML, the DOCTYPE declaration is more complex and includes references to a Document Type Definition (DTD), for example:

html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

or

html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

However, these older forms are largely obsolete with the adoption of HTML5

. Summary:

  • HTML5 DOCTYPE: <!DOCTYPE html>
  • Must be the first line in the HTML document
  • Case-insensitive
  • Older HTML versions use longer, DTD-referencing DOCTYPEs

This simple declaration ensures browsers render the page in standards mode rather than quirks mode