I was in a hurry to churn out some html code and did not provide a DTD tag for my index.htm file...does anyone know what DTD is used by default when no tag is provided?
The reason I ask is that when I add in my chosen type of
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
the page is distorted and I want to go in and fix it. My code follows the guide lines given for XHTML at
Thanks!
Browsers don't "fake" a doctype they parse in "quirks mode". Quirks mode assumes the web page was written a while ago and never updated, so it attempts to render it in the same way an older version of the browser would have in order to attain backwards compatibility.
In Internet Explorer, rendering in quirks mode makes the page appear the same as it would have in IE 5.5.
Related
No matter what I try to do, pages keep looking significantly different depending on whether they are from my local machine or the development server. When pressing F12, I've finaly noticed that pages have different instructions on the top:
1) Pages displayed by my local machine have the following values:
Browser Mode: IE9 Compatible View
Document Mode: Quirks
HTML starts with this line of code
<html xmlns="http://www.w3.org/1999/xhtml">
2) Whereas pages displayed by the development server have the following values:
Browser Mode: IE9 Compatible View
Document Mode: IE7 Standards
HTML starts with this line of code
<!-- DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" -->
<html xmlns="http://www.w3.org/1999/xhtml">
It looks like the the first line of the instruction that's making those pages to display differently.
Do I need to add that line to pages coming from my local machines as well? Why and how to do that?
Thanks for helping
Without a doctype, you are in quirks mode, and, no matter what else you do, pages won't look the same as in strict mode.
New web pages should always have a doctype and always use strict. Rarely would a newly created page have a need for quirks or the transitional doctype you are using.
Add either that transitional doctype on your first line or, preferably, the strict version:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
Better yet, use the new type: <!DOCTYPE html> which will keep all browsers in strict mode, including IE back to IE6 (or even IE4? Don't recall).
Currently we have the following DOC type:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN">
There are some initiatives to change to the following DOC type:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 TRANSITIONAL//EN" >
The argument is for the enforcement of strict W3C standards for cross browser compatibility, my question is, if we adopt the new DOC type,
without changing parts of the codes that are still in the 4.0.1 HTML definition to XHTML 1.0 definition, will it be of any use?
will changing to the new DOC type definition cause my existing JSP / HTML to break (suppose those that conform to 4.0.1 perfectly but not tested against 1.0 XHTML)?
I'll assume that you actually mean the following as the new doctype:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Functionally, your JSP/HTML will not break. The modern webbrowser is forgiving enough and it'll close open tags where needed and it'll accept unspecified attributes. In the meanwhile you should however really consider to fix them anyway so that it w3-validates against the new doctype as much as possible.
However, major problems may arise in look'n'feel as specified by CSS. Your old doctype pushes the the browser in quirksmode which reveals among others the pretty serious box model bug in MSIE. With this bug, MSIE accounts the element's padding and border into element's width. So if you change this doctype, you'll only see changes in MSIE.
If your website was designed on normal webbrowsers according the web standards (i.e., it's been designed for Firefox, Chrome, Safari, etc), then you don't need to worry. It'll only going to look like in MSIE as intented, which is just an advantage.
But if your website was designed for MSIE and hereby thus ignoring the webstandards, then you'll have to make a lot of changes in CSS (mainly width/padding/border/margin) so that it look the same in MSIE as intented. You'll also gain the additional advantage that it will now look properly on normal browsers.
As to the doctype choice, well this is going to be subjective, but if you need my opinion, then read the following answers:
Should I start with HTML or XHTML?
Is it possible to use JSF+Facelets with HTML 4/5?
I've noticed some weird behavior with a CMS i'm using. The Doctype is commented out in Internet Explorer 7 (IE9 in IE7 standards mode) see attached image:
I think this is causing a few other errors i have with CSS and JavaScript (jQuery).
Does anyone know anything that will trigger this behavior.
The doctype i'm using:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
Once the DOCTYPE has determined whether to use quirks (like IE5.5) mode or slightly-more-standards (IE7 native) mode, the DOCTYPE is not really of interest to the browser any further.
It seems that IE7 (at least) then inserts the doctype into the DOM as if it was a comment.
It's just the way the browser works. Unless you've JavaScript walking the DOM, it's unlikely to affect the way the page works.
I'm writing a web page. How do I know what doc type to use?:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
or
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
I believe the rationale behind using Transitional is that if your page uses deprecated html elements, the browsers will try to support them?
Thanks
I'd use <!DOCTYPE html>, it's by far the easiest alternative, and it triggers standards mode in all modern browsers as Anne van Kesteren noted several years ago.
You should prefer strict above transitional/loose/invalid(!). Your first transitional example is invalid. It will let any browser render in non-standards/quirks mode, it won't let IE render in almost-standards mode.
This site contains excellent background information and a compatibilty table. Here's an extract of relevance:
Standards mode, more stable validation target
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
This doctype also triggers the standards mode, and the decade-old HTML 4.01 validity definition is stable. Please be sure to test your image alignment in Firefox, Safari, Chrome or Opera 9 or 10. Testing image alignment with Internet Explorer is inadequate however be sure to test in IE8, too.
You’d like to use the Standards mode, but you still want to validate deprecated markup or you use sliced images in table layouts and don’t want to fix them
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
This gives you the Almost Standards mode (and the full Standards mode in really old Mozilla releases). Please note that your layouts based on sliced images in tables are likely to break if you later move to HTML5 (and, hence, the full Standards mode).
I'd say, go for HTML5 doctype <!DOCTYPE html>, unless you want a more stable validation target.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
HTML 4 Strict DTD if you
a) Don't plan on using HTML 5 elements
b) Don't plan on really using xhtml with Content-Type of application/xhtml+xml
In this day and age you really shouldn't be "transitioning" or trying to using old, deprecated non-standard elements. Go standard all the way.
If you do plan on trying out HTML 5, by all means just use <!DOCTYPE HTML> which is the HTML 5 DTD.
I have a page which needs to be rendered in Quirks mode for the page to be loaded properly. The problem is that the page uses valid XHTML and thus has a doctype. This forces the page to render in Standards mode in all browsers. Is there any workaround/hack that can force Quirks mode eventhough I have a doctype?
I also have a page that must live in the 90s along with all the memory leaks that come with IE in quirks mode, this is the DOCTYPE we use.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
See http://hsivonen.iki.fi/doctype/ for changing the DOCTYPE to Almost Standards mode or Quirks mode. Excerpts below. (Assumes a Content-Type of text/html.)
Almost Standards mode:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
This gives you the Almost Standards mode. Please note that your
layouts based on sliced images in tables are likely to break if you
later move to HTML5 (and, hence, the full Standards mode), so it’s
better to make your designs Standards mode-compatible right now.
Quirks mode:
No doctype.
Please don’t do this. Willfully designing for the Quirks mode will
come and haunt you, your coworkers or your successors in the future.
XHTML doctype:
I am not recommending any of the XHTML doctypes, because serving XHTML
as text/html is considered harmful. If you choose to use an XHTML
doctype anyway, please note that the XML declaration makes IE 6 (but
not IE 7!) trigger the Quirks mode.
Try removing the doctype?