27

I have observed that some CSS properties, like font-family declared with quotation marks, perhaps are case-sensitive, but all other are not... But how web-browsers and "HTML renderers" MUST interpret? Is the same in any CSS context (XML, SVG, etc.) and all other applications? What the standards say about?

Example: Adobe InDesign exported both, font-family:'Optima Bold' and font-family:'optima bold'. Can I "normalize to lower case" (ex. to merge similar classes)?

NOTES

References are incomplete and in conflict:


Comparing with this question/answers, the point here, perhaps, can be translated to some (personal) objective considerations:

  1. There are a (objective!) normative (W3C spec of CSS2, CSS3, XHTML1, or HTML5) source for this answer?

  2. "Standard font-family unique names" can not be case-sensitive (otherwise cease to be standard)... So, the only justifiable (by sensible arguments) properties to be case-sensitive are:

    2.1. X values at url(X), see background, etc. properties;

    2.2. content values, example;

    2.3. ... more ?? ...

Community
  • 1
  • 1
Peter Krauss
  • 13,174
  • 24
  • 167
  • 304

2 Answers2

23

(updating @ÁlvaroG.Vicario answer and comments, and complementing this answer... This is a Wiki, please edit to enhance)

Example: for CSS3 (and HTML5) there are new explicit rules, as "font-face property must be case-insensitive".[2]


Context

W3C interoperating standards, mainly XML, HTML, CSV and CSS.

CSS general rules

CSS2 (a W3C standard of 2008) fixed basic conventions about "Characters and case", and CSS3 (a W3C standard for 2015) added something more.

  1. By default "all CSS syntax is case-insensitive (...)" [1]

  2. There are exceptions, "(...) except for parts that are not under the control of CSS"[1]

2.1. element names are case-sensitive in HTML5 (?) and XML, but case-insensitive in HTML4.

2.2. identifiers (including element names, classes, and IDs in selectors) are case-sensitive. HTML attributes id and class, of font names, and of URIs lies outside the scope of the CSS specification.

  1. ....

  2. The

Case matrix

Exceptions and specific (explicited in a reference) rules. "YES" indicate that value is case-sensitive.

Property values:

 CSS property      | Case-sens. | Reference and notes
 ------------------|------------|--------------------
 %colorVals        | NO         | [3]
 font-family       | NO         | [2]
 %url              | YES        | ...
 content           | YES        | ...
 ----------------------------------------------------
 %colorVals = color, background, etc.
 %url = background-image, etc. that use `url()`, see [7] and notes. 

Selector values:

 CSS selector      | Case-sens. | Reference and notes
 ------------------|------------|--------------------
 id                | YES        |...
 element           | YES/NO     | ... YES for XML...
 class name        | YES        | [5]
 (`~ i` operator)  | NO         | [6]
 ----------------------------------------------------
 YES/NO = depends on the document language (see ref. and notes).

REFERENCES:

[1] W3C/CSS2/syndata, sec. 4.1.3 Characters and case.

[2] W3C/CSS3-fonts, sec. 5.1 Case sensitivity of font family names

[3] W3C/CSS3-color, sec. 4.1. Basic color keywords

[4] W3C/CSS3-values, sec. 3.1. Pre-defined Keywords

[5] W3C/Selectors, sec. 3. Case sensitivity

[6] W3C/Selectors4, sec. 6.3. Case-sensitivity

[7] RFC 3986 and URL syntax illustration at Wikipedia.


Quotations and notes

  • Typical URLs starts with domain, that is case insensitive, but after it (path, query or fragment syntatical components), is case sensitive. See [7].

  • "User agents must match these names case insensitively". [2]

Community
  • 1
  • 1
Peter Krauss
  • 13,174
  • 24
  • 167
  • 304
  • Few more case-insensitive items: CSS3 color names - http://www.w3.org/TR/css3-color/#html4, http://www.w3.org/TR/css3-color/#css2-system; pre-defined keywords - http://www.w3.org/TR/css3-values/#keywords – Victor Nov 12 '14 at 09:34
  • `background-image: url("adDressToImagE...")` is not case sensitive. (at less in chrome). – Juanma Menendez Apr 16 '19 at 18:00
  • 1
    Hi @JuanmaMenendez, please edit, it is a Wiki! But see the problem, an URL value have its proper syntax, the first part, the domain, is case insesitive, but the remain is not (!). I edited to avoid confusion (and corrected table error). – Peter Krauss Apr 21 '19 at 12:43
  • @PeterKrauss you are right. According to [W3C](https://www.w3.org/TR/WD-html40-970708/htmlweb.html) _"There may be URLs, or parts of URLs, where case doesn't matter, but identifying these may not be easy. Users should always consider that URLs are case-sensitive"_ – Juanma Menendez Apr 23 '19 at 00:13
  • Hi @JuanmaMenendez, not need to comment, I agree and the table in the text also agree, *" 'YES' indicate that value is case-sensitive"* (see note and ref [7]). – Peter Krauss Apr 23 '19 at 02:49
8

The spec for CSS 2 says:

CSS syntax is case-insensitive within the ASCII range (i.e., [a-z] and [A-Z] are equivalent), except for parts that are not under the control of CSS. For example, the case-sensitivity of values of the HTML attributes "id" and "class", of font names, and of URIs lies outside the scope of this specification. Note in particular that element names are case-insensitive in HTML, but case-sensitive in XML.

... which makes quite sense: CSS itself accepts both background-image and BACKGROUND-IMAGE but it has no way to know whether your web server considers LOGO.PNG and logo.png as identical or different resources.

(I've been unable to find the equivalent document for CSS3)

Álvaro González
  • 142,137
  • 41
  • 261
  • 360
  • Yes, your answer is similar to http://stackoverflow.com/a/12533957 that not say something about *property values*... Have a occasional mention of "font names", but **where (?)** assertions about "*OK, font-variant, font-weight, text-decoration, text-transform, etc. **are case insensitive properties***". Yes, URL values (that contains something like `logo.png` are the unique, *the only justifiable by sensible arguments*) – Peter Krauss Jul 31 '13 at 12:37
  • Yours is a generalisation of the question you link. The answer is the same. Not sure if you have further questions... :-? – Álvaro González Jul 31 '13 at 12:39
  • @PeterKrauss Er... Are you asking for reference about case sensitiveness in every single language and technology that can make use of CSS values at some point? That's a daunting task. Anyone can invent a vendor-prefixed attribute that performs a task. I can even invent my own language and let it use CSS for styling. – Álvaro González Jul 31 '13 at 13:05
  • Sorry, the question is constrained by *W3C standards* (family of CSS-compatible and uptodate standards like HTML4, XHTML1, etc.). I can edit also about it, or add a "HTML" tag to the question. – Peter Krauss Jul 31 '13 at 13:12
  • [beware of the ol tag](https://github.com/w3c/csswg-drafts/issues/2101) – Knu Feb 21 '21 at 10:24