CSS <string> Data Type
<string> data type represents a string. A string is character data surrounded with either single (
') or double (
") quote characters.
When you see
<string> (including the
>) anywhere in the CSS specifications, this refers to the fact that the value can be any valid string.
For example, the
content property accepts the following values:
Which means that you can provide a string as one of the possible values.
Here's an example of a string value:
So this could be used within a property such as the
content property, like this:
Here's a working example:
Some characters need to be escaped before they will render properly. For example, if you use double quotes to indicate the string, and the string itself contains a double quote character, you'll need to escape it. Otherwise it will interfere with the double quotes that indicate the string. The same applies to the single quote character.
Double quotes can be escaped as
"\"" or as
Single quotes can be escaped as
'\'' or as
However, if the string is enclosed in double quotes, you can use single quotes within the string without escaping them (and vice-versa).
So any of the following are fine:
<string>data type is defined in CSS Values and Units Module Level 3 (W3C Candidate Recommendation, 29 September 2016)
- It is also defined in the Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification (W3C Recommendation 07 June 2011)
- It is also defined in Cascading Style Sheets, level 1 (W3C Recommendation 17 Dec 1996)