CSS Data Type
Description
The <string> CSS data type represents a sequence of characters used in CSS values, typically enclosed in either single or double quotes. It allows authors to specify textual content or identifiers in a flexible way, enabling the assignment of meaningful labels, custom messages, or other string-based information within CSS properties. Unlike numeric types such as <number> or length types like <length>, the <string> type is purely textual and does not participate in mathematical operations or calculations.
One of the primary use cases for <string> is the content property, which can insert textual content before or after an element using pseudo-elements. This allows developers to add stylistic annotations, icons (via text), or other labels without altering the HTML structure. Strings can include plain text, escaped characters, or even Unicode symbols, giving designers wide flexibility in presentation.
Another important aspect of <string> is that it can be combined with functions such as attr() to dynamically display attribute values, or with counters for numbering lists. Strings are sensitive to quotation marks; mismatched or missing quotes can lead to invalid declarations. They are also commonly used in properties like font-family, where quoted names are required for multi-word font names.
Example usage in CSS:
/* Using <string> with content property */
h1::before {
content: "Chapter: ";
}
p::after {
content: " - Read more";
}
/* Using <string> with font-family */
body {
font-family: "Open Sans", Arial, sans-serif;
}
In these examples, the strings "Chapter: " and " - Read more" are inserted as textual content, while "Open Sans" specifies a font family name that contains a space and must therefore be quoted. The <string> type thus serves as a versatile tool for including textual information directly in CSS.
Syntax
property: <string>;
Values
- <string>Defines the characters used in the string.
Example
Browser Support
The following information will show you the current browser support for the CSS string data type. Hover over a browser icon to see the version that first introduced support for this CSS data type.
This data type is supported by all modern browsers.
Desktop
Tablets & Mobile
Last updated by CSSPortal on: 3rd January 2026
