developer.mozilla.org
Handling common HTML and CSS problems - MDN Web Docs
Excerpt
With the scene set, we'll now look specifically at the common cross-browser problems you will come across in HTML and CSS code, and what tools can be used to prevent problems from happening, or fix problems that occur. This includes linting code, handling CSS prefixes, using browser dev tools to track down problems, using polyfills to add support into browsers, tackling responsive design problems, and more. Some of the trouble with HTML and CSS lies with the fact that both languages are fairly simple, and often developers don't take them seriously, in terms of making sure the code is well-crafted, efficient, and semantically describes the purpose of the features on the page. In the worst cases, JavaScript is used to generate the entire web page content and style, which makes your pages inaccessible, and less performant (generating DOM elements is expensive). In other cases, nascent features are not supported consistently across browsers, which can make some features and styles not work for some users. Responsive design problems are also common — a site that looks good in a desktop browser might provide a terrible experience on a mobile device, because the content is too small to read, or perhaps the site is slow because of expensive animations. … Note: One common problem with CSS and HTML arises when different CSS rules begin to conflict with one another. This can be especially problematic when you are using third party code. For example, you might use a CSS framework and find that one of the class names it uses clashes with one you've already used for a different purpose. Or you might find that HTML generated by some kind of third party API (generating ad banners, for example) includes a class name or ID that you are already using for a different purpose. To ensure this doesn't happen, you need to research the tools you are using first and design your code around them. ... HTML errors don't tend to show up so easily in dev tools, as the browser will try to correct badly-formed markup automatically; the W3C validator is the best way to find HTML errors — see Validation above. ... Now let's move on to look at some of the most common cross browser HTML and CSS problems. The main areas we'll look at are lack of support for modern features, and layout issues. This is a common problem, especially when you need to support old browsers or you are using features that are implemented in some browsers but not yet in all. In general, most core HTML and CSS functionality (such as basic HTML elements, CSS basic colors and text styling) works across all the browsers you'll want to support; more problems are uncovered when you start wanting to use newer HTML, CSS, and APIs. MDN displays browser compatibility data for each feature documented; for example, see the browser support table for the :has() pseudo-class. … Another example is form elements. When new <input> types were introduced for inputting specific information into forms, such as times, dates, colors, numbers, etc., if a browser didn't support the new feature, the browser used the default of type="text". ... <form> Another set of problems comes with CSS prefixes — these are a mechanism originally used to allow browser vendors to implement their own version of a CSS (or JavaScript) feature while the technology is in an experimental state, so they can play with it and get it right without conflicting with other browser's implementations, or the final unprefixed implementations. … Prefixed features were never supposed to be used in production websites — they are subject to change or removal without warning, may cause performance issues in old browser versions that require them, and have been the cause of cross-browser issues. This is particularly a problem, for example, when developers decide to use only the -webkit- version of a property, which implied that the site won't work in other browsers.
Source URL
https://developer.mozilla.org/en-US/docs/Learn_web_development/Extensions/Testing/HTML_and_CSSRelated Pain Points
Global CSS selectors lack encapsulation
7CSS selectors are globally scoped by default, meaning a class intended for one element can inadvertently affect others far removed in the document tree, causing 'CSS hell' in large-scale projects.
Cross-Browser Compatibility and Testing Challenges
6Making designs and experiences work consistently across different browsers remains a significant challenge (26% of developers in Q1 2021). Browser testing is time-consuming, polyfill management is complex, and developers struggle to identify reliable, high-quality polyfills.
Using JavaScript instead of CSS for tasks now handled natively
5Developers continue to write JavaScript for functionality that modern CSS now handles natively, such as container queries, the `:has()` selector, scroll-linked animations, and view transitions. This creates unnecessary complexity and hurts performance.
Responsive Design Implementation Complexity
5While responsive design is necessary to accommodate different screen sizes, its successful implementation remains challenging. Developers must balance complexity and functionality across diverse device types and screen resolutions.
Debugging configuration and CSS specificity issues
5Debugging Tailwind configuration issues is less intuitive than debugging CSS itself. Developers must examine parent element styles, specificity conflicts, and conditional classes to understand unexpected style overrides, making troubleshooting complex and time-consuming.
Vendor-specific prefixes and browser inconsistencies
4Developers must write browser-specific prefixes and hacks to handle inconsistent CSS rendering behavior across different browsers, particularly for advanced features.