Skip to content

[css-om] Serialization of font-family names: quoted string vs keyword #5846

Open
@jfkthame

Description

@jfkthame

According to 6.7.2. Serializing CSS Values, the serialization of a font-family name should be "The string serialized as a string", where this means a string surrounded by literal ASCII double-quotes (and with any internal double-quotes or backslashes escaped).

However, AFAICT no browser consistently follows this.

For a family-name that is a single word (without special characters that would require quoting to be parsed), WebKit/Blink prefer to serialize the name as an unquoted keyword.

For example, from Safari's Javascript console:

> document.body.style.fontFamily = "'Times'"
< "'Times'"
> document.body.style.fontFamily
< "Times"

Note that the name is returned without quotes (even though it was specified as a quoted string).

Now try a multi-word family name:

> document.body.style.fontFamily = "'Times New Roman'"
< "'Times New Roman'"
> document.body.style.fontFamily
< "\"Times New Roman\""

Here, the result is quoted.

Furthermore:

> document.body.style.fontFamily = "Avenir Next"
< "Avenir Next"
> document.body.style.fontFamily
< "\"Avenir Next\""

Even when the family name was specified without quotes, Safari adds them. (At least it seems consistent.)

Firefox takes a different approach; it seems to serialize the name according to how it was specified. So a name specified in unquoted form:

> document.body.style.fontFamily = "Times"
< "Times"
> document.body.style.fontFamily
< "Times"

serializes as such, while the same name, quoted:

> document.body.style.fontFamily = "'Times'"
< "'Times'"
> document.body.style.fontFamily
< "\"Times\""

returns a serialization that also has the quotes.

This holds for multi-word names, too; even then, Firefox returns an unquoted serialization if the name was specified in that form:

document.body.style.fontFamily = "Times New Roman"
"Times New Roman"
document.body.style.fontFamily
"Times New Roman"

So my question is whether implementers have any interest in aligning with the CSSOM spec here, in which case these are simply browser bugs to be fixed; or should the spec be adjusted to more closely match implementation reality?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions