HTML & CSS interview question · Most asked

What does <!DOCTYPE html> do?

Create a free account to save this page, take notes and track your progress. Sign in

Summary

It tells the browser to render the page in standards mode using modern HTML rules. Without a doctype (or with certain old ones), browsers use quirks mode, which emulates old browser bugs and changes layout behaviour.

Longer Answer

The doctype must be the first thing in the document. HTML 4 doctypes referenced a DTD and were long; HTML5's is deliberately short because browsers never used the DTD, only the presence of the doctype to choose the rendering mode.

Key Points

  • First line of every page.
  • Triggers standards mode.
  • Missing doctype means quirks mode.
  • HTML5's doctype is deliberately short.

Deep dive: HTML Tutorial: HTML Document Structure

Explanation

What interviewers look for

Knows about standards mode vs quirks mode.

Follow-up questions

  • What changes in quirks mode?

More most-asked HTML & CSS questions

← All HTML & CSS questions

Was this page helpful?