In HTML (Hypertext Markup Language), a DOCTYPE declaration is a special line of code that appears at the very beginning of an HTML document’s source code. Its purpose is to tell web browsers and other software how to interpret and display the content of the HTML document.
Here’s a breakdown of the components of a DOCTYPE declaration:
- DOCTYPE: This is the keyword that signals the start of the DOCTYPE declaration.
- HTML version: This specifies which version of HTML the document is written in. For example, the HTML5 version is commonly used today.
- Public Identifier (optional): This part of the declaration identifies a formal public identifier, which is a unique string provided by an organization like the W3C (World Wide Web Consortium). It helps browsers to understand which standard to follow for rendering the HTML.
- System Identifier (optional): This part points to the location of a Document Type Definition (DTD) file. The DTD defines the rules and structure that the HTML document must follow. It’s used by browsers to understand how to parse and display the document.
Putting it all together, here’s an example of a DOCTYPE declaration for HTML5:
This declaration tells the browser that the document is written in HTML5. In modern web development, HTML5 is the most commonly used version of HTML.