What does "document type" mean?

what does document type means?

3 Likes

Document type means you are telling to the browser what type of document you are submitting to the browser.Reason for using document type in the beginning of the hmtl script is while running that script in the browser it will understand that it is an html document,so the browser will arrange the document in hmtl formate and run rest of the script properly and the it gives output.

64 Likes

Document type is simply telling the computer what file this is. This can be html file, text file, php file and so on.

15 Likes

The Document Type states what type of code you are using. EX.

<!DOCTYPE html>

Shows that you are using HTML5

4 Likes

Think of it as two people who know multiple languages and want to begin a conversation. First, they must agree on what language to communicate in. Identifying html as the DOCTYPE is declaring the language that is about to be spoken is html.

79 Likes

I’m a total beginner, but I think of it as telling the OS which language the code is written in so that it can interpret and present it correctly. Just hope I’m right in thinking that way.

2 Likes

telling the computer? Or telling the browser?
Browsers were implemented to read html documents(html can be written in previous versions of html eg html4,3,2 or even 1 ) but you always have to specify what html you are writing, inside the html document!

The OS? We are talking about browsers. Operating Systems are a whole other thing.

2 Likes

How will the computer know the difference between html file, text file, php file and the other types of files?

I think this is more explanatory than other comments that have been given.

1 Like

wouldn’t using <!DOCTYPE html5> be better if you wanted to be more specific or wanted to future proof the .html file

One would think so, yes, but the standards actually specify that <!DOCTYPE html> specifically means html5. There are other declarations that refer to earlier versions of html. I’d predict that with the way that browsers are ‘evergreen’ these days and the way the standards are evolving, there probably will never be an “HTML6” - just the continuous evolution of HTML5 (which we may as well then refer to as just plain HTML).

This is correct way to think about it conceptually, for those who are wondering - the only thing to correct is that it is the Browser application (running on top of the Operating System) that needs to be informed that the DOCTYPE is of a certain type (e.g HTML) so that it can do what it needs to do in order to compute and display the output for that given DOCTYPE. Not the Operating System.

As part of the whole process, the Browser will actually perform communications with the Operating System to do client side things (things on your computer) like store a downloaded file, output content to the screen, play sounds, etc.

The HTML standard is currently maintained by the WHATWG. It doesn’t have any version 5,6 etc. It is just called the HTML Living standard. Reference - HTML Standard, Edition for Web Developers?