Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat are the best practices for cross-browser web sites?
    primarykey
    data
    text
    <p>(I'd like this to be the definitive community wiki. I seeded it from my own answer to <a href="https://stackoverflow.com/questions/1045830/dealing-with-firefox-and-internet-explorers-differences">this question</a>.)</p> <h1>Specify Everything</h1> <p>A lot of cross-browser issues amount to this: you didn't specify something, and different browsers make different assumptions. Therefore:</p> <h2>Declare a valid doctype</h2> <p>Your doctype tells the browser what rules you'll be using in your code. If you don't specify, the browser has to guess, and different browsers will guess differently.</p> <p>In my experience, a "strict" doctype makes IE behave better (enables things like CSS :hover selectors on divs in IE7).</p> <p><a href="http://www.alistapart.com/articles/doctype/" rel="nofollow noreferrer">This article</a> gives good background on doctypes.</p> <h2>Use Web standards</h2> <p>Avoid browser-specific markup, or only use it when its failure in other browsers won't be significant to the site experience.</p> <h2>Validate your HTML and CSS</h2> <p>You don't have to get everything perfect, but validation is good feedback. As <a href="http://www.codinghorror.com/blog/archives/001234.html" rel="nofollow noreferrer">Jeff said</a>:</p> <blockquote> Knowing the rules and boundaries helps you define what you're doing, and gives you legitimate ammunition for agreeing or disagreeing. You can make an informed choice, instead of a random "I just do this and it works" one. </blockquote> <p>Imagine you opened a paragraph tag and never closed it. If you then open a list tag, did you mean it to be inside the paragraph or not? Validating will help you catch that, close the tag, and eliminate ambiguity.</p> <h2>Consider a CSS Reset</h2> <p>Different browsers assume different baseline CSS rules. You can help them all to act the same by explicitly ironing out the differences up front. Eric Meyer, who wrote <a href="http://meyerweb.com/eric/books/css-tdg/" rel="nofollow noreferrer">CSS: The Definitive Guide</a>, uses <a href="http://meyerweb.com/eric/thoughts/2007/05/01/reset-reloaded/" rel="nofollow noreferrer">this reset</a>. Another popular choice is <a href="http://69.147.76.210/yui/reset/" rel="nofollow noreferrer">YUI Reset CSS</a>.</p> <h1>Use a Javascript library for DOM interactions</h1> <p>Whenever your Javascript needs to work with elements on your page, it's best to use a library like jQuery, Prototype, or MooTools. These libraries are used by many thousands of developers, and they take most of the inconsistencies between browsers' interpretation of Javascript, deal with those internally, and give you a consistent set of commands that just work. Trying to find and work around all these inconsistencies yourself is a waste of time and likely to create bugs.</p> <h1>Test in multiple browsers, deal with IE last</h1> <p>Test in multiple browsers as you go. Generally, you'll find that non-IE browsers behave similarly and IE is a special case - especially if you follow the advice above. When necessary, you can add IE hacks in a separate stylesheet and only load it for IE users.</p> <p><a href="http://www.quirksmode.org/" rel="nofollow noreferrer">Quirksmode.com</a> is a good place for hunting down random browser differences.</p> <p><a href="http://browsershots.org/" rel="nofollow noreferrer">Browsershots.org</a> can help show how your page will be displayed in an assortment of browsers and operating systems.</p> <h1>Fail Gracefully</h1> <p>No site will look perfect in every browser that exists. If a user doesn't have Flash, or Javascript, or advanced CSS, etc, you want your site to be usable anyway. Design with that in mind:</p> <h2>Check the bare HTML</h2> <p>Try loading your site with bare HTML - no styles, no scripts. Are menu options available? Does primary content precede secondary content? Is the site usable, even if ugly?</p> <h2>Consider test-driven progressive enhancement</h2> <p>Described in <a href="http://www.alistapart.com/articles/testdriven/" rel="nofollow noreferrer">this article</a>, this technique uses javascript to check if a browser has a given capability, such as support for a given CSS property, before using it on the page. It is unlike browser sniffing because it tests for features rather than a specific browser.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload