Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Our volunteers haven't translated this article into Tiếng Việt yet. Join us and help get the job done!

The <string> CSS data type represents a string. It is formed by a Unicode characters delimited by either double (") or single (') quotes. A double quoted string cannot contain double quotes unless escaped using a backslash (\). The same practice applies for single quoted strings, they cannot contain single quotes unless escaped using a backslash (\). The backslash character must be escaped to be part of the string.

New lines are not accepted unless escaped by using a line feed character such as \A or \00000a. However, strings can span over several lines. In that case, the new line must be escaped using a \ as the last character of the line.

Characters can be described using their Unicode code point in hexadecimal, when escaped using \. \27 represents the single quote (').

Examples

/* Simple quote escaping */
"Awesome string with double quotes"
"Awesome string with \" escaped double quotes"
'Awesome string with single quotes'
"Awesome string with \' escaped single quotes"

/* New line in a string */
"Awesome string with \Aline break"

/* String spanning over two lines (these two strings are exactly the same) */
"A really long \
awesome string"
"A really long awesome string"
Note: Double quoted strings can also be escaped using \22 and single quoted strings can be escaped using \27.

Specifications

Specification Status Comment
CSS Values and Units Module Level 3
The definition of '<string>' in that specification.
Candidate Recommendation No significant change from CSS Level 2 (Revision 1)
CSS Level 2 (Revision 1)
The definition of '<string>' in that specification.
Recommendation Explicitly defined; allows 6-digit Unicode escaped characters
CSS Level 1
The definition of '<string>' in that specification.
Recommendation Implicitly defined; allows 4-digit Unicode escaped characters

Browser Compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 1.0 1.0 (1.0) (Yes) (Yes) 1.0 (85)
\xx 1.0 1.0 (1.0) 6.0 (Yes) 1.0 (85)
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes)
\xx (Yes) (Yes) (Yes) (Yes) (Yes) (Yes)

Document Tags and Contributors

 Contributors to this page: fscholz, Sebastianz, teoli, kscarfone, FredB, Sheppy, McGurk, BijuGC
 Last updated by: fscholz,