tags:

views:

116

answers:

6

Possible Duplicate:
HTML: What is the functionality of !DOCTYPE

hi

i am .asp web developer as a beginner,

i find many article for , but i not get a complete idea..

1.what the use of <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; ?

2.there is any need for use this in my classic asp page?

+4  A: 

The doctype tells the browser what version of html to use to render the page. If you use xhtml strict for example, not closing your meta tags with a /> will result in the page not validating.

So basically, it lets the browser know what set of rules to use when rendering the page.

Edit: That doctype will render the page in xhtml transitional. And I am a PHP developer but I would assume you need to include the doctype in your ASP.

Wolfy87
Well, sort of. The doctype of a document describes the document's element and attribute rules to any interpreter, but it is largely ignored by browsers, with one exception: the presence of "modern" doctypes triggers "standards" mode, while older or missing doctypes trigger "quirks" mode, which typically only affects the browser's default CSS rules. Switching doctypes between, for instance, HTML4 and XHTML does not cause browsers to parse the HTML differently. But sending the document with an HTML mime-type does trigger different rendering from an XML (or XHTML) mime-type in most browsers.
eyelidlessness
Thank you for the corrections eyelidlessness, I have always thought it to be alot more influential on the browser than it actually is.
Wolfy87
Some clarification, because I wrote my last comment in a hurry and tired. The switch to "quirks" mode may change how the DOM tree is parsed from the HTML, and what sorts of Javascript and CSS functionality is available. In IE this is the most pronounced, with an additional change: the box model is changed. IE's "quirks" mode is *essentially* the IE 5.5 rendering engine (meaning that from 6 on, IE has maintained a 5.5 compatibility mode; 8 on will maintain modes for all of the previous versions back to 5.5 *except* 6), which used a different box model.
eyelidlessness
Further details: http://www.quirksmode.org/css/quirksmode.html and http://www.cs.tut.fi/~jkorpela/quirks-mode.html
eyelidlessness
+3  A: 

Doctype tells the browser which version of html you're using .

http://www.w3schools.com/tags/tag_doctype.asp

It's really important 'cause your browser won't do the same thing with the same html code. And it's important to respect the doctype :

  • SEO point of view, bot are made to read your html code so it's better that it is perfect.

  • the browser will do the rendering better and faster.

  • If you don't respect the rules you'll have some strange bug.

Doctype is about client-side, so it doesn't have anything to do with your server-side technology :

client : javascript / css / html

server : php / asp/ asp.net / java

If you are a beginner you have to understand well this. You'll have to learn both sides and try to learn them independently.

remi bourgarel
A: 

DOCTYPE is not needed, it's an optional element of a web page (not ASP, PHP or other) and only helps the browser to render and use proper rendering mode.

The doctype declaration is not an HTML tag; it is an instruction to the web browser about what version of the markup language the page is written in.

As you mention you're a beginner, the HTML code (the code that is rendered in any web browser) is divided in 2 main areas.

<html>
   <head>
      // Everything here is to help the browser to display the correct design
   </head>

   <body>
      // Everything here will show in the user display
   </body>
</html>

the <doctype> that is added adove the <html> tag represents "Hey Browser, this how I made my code, please follow the standards of this type"

It's the same as you see a Navy Officer with it's patent on the shoulders... It's an optional thing to have (in the civil world) but if you see someone wearing it, your approach to that individual will be very different and many you don't say: "Wazz'up" but "How do you do".

It's all about standards.


<doctype> it's only come important with more ways to render the same things in the user browser, in 1990 all we knew was <html> and there was no difference between <br> and <br />, even today, the browser render engine does not care about the breaking space tag, but other might, as <img alt="" src="" > and <img alt="" src="" />

Then, there is the difference between HTML and XHTML, though they are an XML language variants, XHTML is much more restrict and, for example, all tags need to be closed, so you do need to write <br/>.

I hope I can help you make some sense on the <doctype> tag :)

balexandre
doctype not needed ? you're really telling a beginner that doctype is not needed ? Come on !
remi bourgarel
It's an optional element! It is not required, read the docs! Latests browsers will automatically choose the DTD to use from the code in use. It's all about Validation, not rendering, I can make you a page that renders in any browser the same way without any `<doctype>`.
balexandre
I just read the documentation. When the w3c says "don't forget to" I don't think it's optional. When you're working with web tech, you never think every one as an up to date browser, you think like they are all under iE6.
remi bourgarel
And no you can't make it render the same way, the default style of elements (for instance) is doctype-dependant.
remi bourgarel
-1. HTML is not a variant of XML and the DOCTYPE is mandatory in valid HTML4 and HTML5 documents.
Alohci
@Alohci You just downvote saying exactly what I said, it's only for Validation not Rendering
balexandre
+1  A: 

Yes, you do need a doctype -- having one forces the browser to apply certain rules to the layout of your HTML. If you don't have one, browsers will render using their default mode, which is different for different browsers, meaning your page will look wrong in some browsers. If you specify a doctype, you can (for the most part) forget about that issue.

There are about six or seven doctypes in common use, but to be honest the best one to use these days is the HTML5 doctype:

<!DOCTYPE html>

Yep, its as simple as that -- you don't need any of the other junk in the doctype; just that. That'll be enough to force all the browsers into the most up-to-date standards-compliant mode.

Spudley
IE (not 9) acts kinda stupid with such `<doctype>` though they are catching up very fast with 9 eheh :)
balexandre
A: 

Specifying the DOCTYPE also help lessen inconsistencies among the different major browsers. This is a significant factor in professional web development, but take note that specifying DOCTYPE won't always ensure that all rules will be followed by the browser. The browser will only try its best to follow what it can until you find out you still need some workaround for other behaviors.

As for the question if there is a "need" for it, the answer is YES if you are creating a professional website or a system that will be used by a lot of people. But if you're just doing it for fun or homework or school exercise then it's only part of the long list of best practices in web development. But I strongly suggest that as early as now, even as a beginner, you start incorporating DOCTYPE in your webpages.

Manny
A: 

this is more of a html question, which you would've come across if you had more experience making static html files before jumping into programming classic asp to produce html.

  1. different doctypes may give you different outcomes in your html layouts. refer to: http://www.w3schools.com/tags/tag_doctype.asp

  2. you'll need it. html pages without a doctype will default to old school quirks mode which can be frustrating to work with later.

hope this helps!

mjsg