HTML & CSS interview question · Most asked
What does <!DOCTYPE html> do?
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
- What is HTML?
- What is HTML5, and how is it different from HTML 4?
- What is semantic HTML, and why does it matter?
- What is the alt attribute for, and what makes good alt text?
- What input types and validation attributes did HTML5 add?
- What is the difference between script, script async and script defer?
- Compare localStorage, sessionStorage and cookies.
- What is ARIA, and what is the first rule of ARIA?