Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between these DOCTYPE declarations?

Tags:

html

doctype

Whats the difference between these two DOCTYPE declarations?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

and

<!DOCTYPE html>

What are the consequences of using each of these, and how do they affect SEO?

like image 594
Smaller Avatar asked May 30 '16 22:05

Smaller


People also ask

What are the different DOCTYPE?

In HTML version 4, there are three types of DOCTYPES can be used: strict,transitional and frameset.

What is a DOCTYPE declaration and what is its purpose?

The DOCTYPE declaration is an instruction to the web browser about what version of HTML the page is written in. This ensures that the web page is parsed the same way by different web browsers. In HTML 4.01, the DOCTYPE declaration refers to a document type definition (DTD).

What is the difference between DOCTYPE HTML and HTML?

DOCTYPE html tag defines the TYPE of document as HTML. After the browser understands the TYPE of document is HTML, we may now define the HTML document itself by the code we create between the html/html tags. -a web-document consisting of HTML pages. -an HTML page consisting of a header, body, and footer.


1 Answers

In HTML 4.01, the <!DOCTYPE> declaration refers to a Document Type Definition (DTD). This is because HTML 4.01 was based on Standard General Markup Language (SGML).

The DTD specifies the rules for the markup language, so that the browsers render the content correctly.

HTML5 is not based on SGML, and therefore does not require a reference to a DTD.

This is why HTML5 has only one doctype. That is the second one in your example.

<!DOCTYPE html>

HTML4.0.1 on the other hand had three doctypes

Strict: This DTD contains all HTML elements and attributes, but does NOT INCLUDE presentational or deprecated elements (like font). Framesets are not allowed.

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

Transitional: This DTD contains all HTML elements and attributes, INCLUDING presentational and deprecated elements (like font). Framesets are not allowed.

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

Frameset: This DTD is equal to HTML 4.01 Transitional, but allows the use of frameset content.

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

XHTML also had three doctypes.

XHTML 1.0 Strict: This DTD contains all HTML elements and attributes, but does NOT INCLUDE presentational or deprecated elements (like font). Framesets are not allowed. The markup must also be written as well-formed XML.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

XHTML 1.0 Transitional: This DTD contains all HTML elements and attributes, INCLUDING presentational and deprecated elements (like font). Framesets are not allowed. The markup must also be written as well-formed XML.

This is the one in your first example

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

XHTML 1.0 Frameset: This DTD is equal to XHTML 1.0 Transitional, but allows the use of frameset content.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
like image 102
Richard Hamilton Avatar answered Oct 14 '22 01:10

Richard Hamilton