<string>
Quick Summary for <string>
The <string> CSS data type represents a sequence of characters. Strings are used in numerous CSS properties, such as content, font-family, and quotes.
Code Usage for <string>
/* Simple strings */ "This string is demarcated by double quotes." 'This string is demarcated by single quotes.'  /* Character escaping */ "This is a string with \" an escaped double quote." "This string also has \22 an escaped double quote." 'This is a string with \' an escaped single quote.' 'This string also has \27 an escaped single quote.' "This is a string with \\ an escaped backslash."  /* New line in a string */ "This string has a \Aline break in it."  /* String spanning two lines of code (these two strings will have identical output) */ "A really long \ awesome string" "A really long awesome string" 
More Details for <string>

<string>

The <string> CSS data type represents a sequence of characters. Strings are used in numerous CSS properties, such as content, font-family, and quotes.

Syntax

The <string> data type is composed of any number of Unicode characters surrounded by either double (") or single (') quotes.

Most characters can be represented literally. All characters can also be represented with their respective Unicode code points in hexadecimal, in which case they are preceded by a backslash (\). For example, \22 represents a double quote, \27 a single quote ('), and \A9 the copyright symbol (©).

Importantly, certain characters which would otherwise be invalid can be escaped with a backslash. These include double quotes when used inside a double-quoted string, single quotes when used inside a single-quoted string, and the backslash itself. For example, \\ will create a single backslash.

To output new lines, you must escape them with a line feed character such as \A or \00000A. In your code, however, strings can span multiple lines, in which case each new line must be escaped with a \ as the last character of the line.

However, to get new lines, you must also set the white-space property to appropriate value.

Note: HTML entities (such as &nbsp; or &#8212;) cannot be used in a CSS <string>.

Examples

Examples of valid strings

/* Simple strings */ "This string is demarcated by double quotes." 'This string is demarcated by single quotes.'  /* Character escaping */ "This is a string with \" an escaped double quote." "This string also has \22 an escaped double quote." 'This is a string with \' an escaped single quote.' 'This string also has \27 an escaped single quote.' "This is a string with \\ an escaped backslash."  /* New line in a string */ "This string has a \Aline break in it."  /* String spanning two lines of code (these two strings will have identical output) */ "A really long \ awesome string" "A really long awesome string" 

Specifications

Specification
CSS Values and Units Module Level 5 # strings

See also

CSS Units and Values CSS Basic Data Types Introduction to CSS: Values and Units

Last modified: Jan 28, 2022, by MDN contributors

Select your preferred language English (US)DeutschFrançais日本語中文 (简体) Change language

No Items Found.

Add Comment
Type in a Nick Name here
 
Other Categories in CSS
css
Search CSS
Search CSS by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code here, mostly for my reference. Also if i find a good link, i usually add it here and then forget about it. more...

Subscribe to weekly updates about things i have added to the site or thought interesting during the last week.

You could also follow me on twitter or not... does anyone even use twitter anymore?

If you found something useful or like my work, you can buy me a coffee here. Mmm Coffee. ☕

❤️👩‍💻🎮

🪦 2000 - 16 Oct 2022 - Boots
Random Quote
"We're tight-fisted with property and money, yet think too little of wasting time, the one thing about which we should all be the toughest misers.”
Seneca
Random CSS Property

max-inline-size

The max-inline-size CSS property defines the horizontal or vertical maximum size of an element's block, depending on its writing mode. It corresponds to either the max-width or the max-height property, depending on the value of writing-mode.
max-inline-size css reference