The <!DOCTYPE html> declaration is the first line of every HTML document. It tells the browser that the page is written in HTML5, which is the latest version of HTML.
Why Do We Use <!DOCTYPE html>
Browsers need to know which version of HTML is being used so they can display the page correctly. The <!DOCTYPE html> declaration ensures that the browser uses standard mode instead of quirks mode.
Standard mode helps the browser follow modern web standards, while quirks mode may cause layout and styling issues.
Is It an HTML Tag
<!DOCTYPE html> is not an HTML tag. It is a declaration that gives instructions to the browser. It does not have a closing tag and does not contain any content.
Where to Write It
The <!DOCTYPE html> declaration must always be written at the very top of the HTML document, before the <html> tag.
Example
<!DOCTYPE html> <html> <head> <title>Example Page</title> </head> <body> <p>This is a sample page</p> </body> </html>
Summary
<!DOCTYPE html> is an important declaration that ensures your webpage is displayed correctly in modern browsers. It should always be included at the top of every HTML file.