<!DOCTYPE> tag is an HTML declaration that specifies the version of HTML being used in a web page. It is located at the beginning of an HTML document, before the
<!DOCTYPE> tag is required for all HTML documents, and its purpose is to tell web browsers what type of document they are rendering, which determines how they should interpret and display the content.
Here’s an example of an HTML document with a
<!DOCTYPE> tag for HTML5:
<title>My Web Page</title>
<h1>Welcome to my web page!</h1>
<p>This is some text.</p>
In this example, the
<!DOCTYPE html> declaration tells the browser that this is an HTML5 document. This is important because different versions of HTML have different rules and features, and the browser needs to know which version to use to render the document correctly.
There are different versions of the
<!DOCTYPE> tag for different versions of HTML, such as HTML 4.01, XHTML 1.0, and HTML5. It’s important to use the correct version of the
<!DOCTYPE> tag for the HTML version being used, as this affects how the browser interprets the document.