How Do Browsers Handle Missing Units in CSS Attributes?

Mary-Kate Olsen
Release: 2024-10-24 14:00:02
Original
350 people have browsed it

How Do Browsers Handle Missing Units in CSS Attributes?

Fallback for CSS Attributes Without Unit

In CSS, when a unit (e.g., px, em, pt, %) is missing from an attribute, browsers handle the situation differently.

Quirks Mode Behavior

In quirks mode, some browsers may fall back to a preferred unit, typically px. This behavior is based on the legacy of unitless HTML attributes like width and height.

Standards Mode Behavior

In standards mode, as per CSS2.1 specifications, all non-zero length values require units. UAs are expected to ignore length values without units.

Browser Inconsistencies

Despite the standardized behavior in standards mode, browsers exhibit inconsistencies in quirks mode:

  • Internet Explorer: Ignored unitless rules in IE7 and later
  • Firefox: Fallback to px for width but ignored border-width
  • Chrome, Opera, Safari: Fallback to px for both width and border-width

W3C Requirements

The W3C does not dictate the behavior for unitless CSS attributes in quirks mode. The specifications only mandate that UAs ignore unitless length values in standards mode.

Specific Questions:

  1. Why px fallback in quirks mode?
    It's a quirky behavior based on legacy HTML attributes.
  2. Mandatory fallback to preferred unit?
    No, it's not mandatory in quirks mode.
  3. Correct quirks mode behavior for given example:
    There is no defined correct behavior as it depends on browser quirks. Chrome, Opera, and Safari's behavior is more consistent with ignoring unitless rules in standards mode.

The above is the detailed content of How Do Browsers Handle Missing Units in CSS Attributes?. For more information, please follow other related articles on the PHP Chinese website!

source:php
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!