FrontEnd Interview: What does a DOCTYPE do?


Hi! Let’s answer today to one of the typical Frontend
Interview questions. If this is your first time here and you want
to learn Frontend and JavaScript, start right now by subscribing, and don’t forget to
turn on the subtitles. [Music playing] DOCTYPE is an abbreviation for DOCument TYPE. A document type declaration is an
instruction that associates a particular SGML (for example, a webpage) with a document type
definition (DTD) (f.e. HTML 2.0 – 4.0) or XML document. A DTD defines how documents of a certain type
should be structured (f.e. a button can contain a span but not a div), whereas a DOCTYPE declares
what DTD a document supposedly respects (f.e. this document respects the HTML DTD). For webpages, the DOCTYPE declaration is required. It is used to tell user agents what version
of the HTML specifications your document respects. Once a user agent has recognized a correct
DOCTYPE, it will trigger the no-quirks mode matching this DOCTYPE for reading the document. If a user agent doesn’t recognize a correct
DOCTYPE, it will trigger the quirks mode. DOCTYPEs are required for legacy reasons. Including the DOCTYPE in a document ensures
that the browser makes a best-effort attempt at following the relevant specifications. The DOCTYPE declaration for the HTML5 standards
is. HTML5 is not SGML-based. The browsers use the DOCTYPE only for mode
selection. Since web browsers are implemented with special-purpose
HTML parsers, rather than general-purpose DTD-based parsers, they don’t use DTDs and
will never access them even if a URL is provided. The difference between HTML and XHTML is following. The Extensible Hypertext Markup Language,
or XHTML, has two important notes for frontend developers. It needs to be well-formed, meaning all elements
need to be closed and nested correctly or it returns an error. Since it is more strict than HTML is requires
less pre-processing by the browser, which may improve the performance of a site. An HTML validator is a quality assurance program
used to check HTML markup elements for syntax errors. A validator can be a useful tool for an HTML
user who receives data electronically from a variety of input sources. Syntax errors, such as open tags, extra spaces,
or forgotten quotation marks, can cause a Web page to look drastically different than
the creator intended, or render correctly in one browser, but not in another. A valid HTML document is essential for building
the Document Object Model and Accessibility Object Model. [Music playing] If you like this video give it “thumbs up”,
share it with your friends, subscribe to the channel and watch other episodes. Thanks for watching and dive deeper.

One Comment

Add a Comment

Your email address will not be published. Required fields are marked *