Performance: DOCTYPE declaration
The DOCTYPE declaration affects how the browser renders the page by triggering standards mode or quirks mode, impacting rendering speed and layout accuracy.
<!DOCTYPE html> <html lang="en"> <head><title>Page</title></head> <body>Content</body> </html>
<html> <head><title>Page</title></head> <body>Content</body> </html>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| No DOCTYPE (quirks mode) | Same DOM nodes | Multiple reflows due to layout instability | Higher paint cost from layout shifts | [X] Bad |
| With <!DOCTYPE html> (standards mode) | Same DOM nodes | Single reflow with stable layout | Lower paint cost with no layout shifts | [OK] Good |
<!DOCTYPE html> declaration in an HTML document?<!DOCTYPE html>.<!DOCTYPE html> matches the correct HTML5 syntax exactly; others are either older versions or incorrect.<html> <!DOCTYPE html> <head></head> <body>Hello</body> </html>
<html> tag.<html>, which is incorrect, so DOCTYPE declaration must be the very first line before <html> tag. is correct.<!DOCTYPE html>
Page Title
uses correct DOCTYPE and includes lang="en" for accessibility.<!DOCTYPE html>
Page Title
includes charset and viewport meta tags, important for modern responsive pages.<!DOCTYPE html5>
Page Title
uses invalid DOCTYPE <!DOCTYPE html5>. <!DOCTYPE html>
Page Title
lacks lang and viewport meta tag.Pass the test and this pattern moves unknown