<string>

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

<string>CSSデータ型で、一連の文字列を表します。文字列は content, font-family, quotes など、数々の CSS プロパティで使用されます。

構文

<string> データ型は任意の数の Unicode 文字を、二重引用符 (") または単一引用符 (') で囲んで構成します。

多くの文字は文字通りに表現されます。またすべての文字は、それぞれの 16 進数の Unicode コードポイントで表現することもできます。例えば、 \22 は二重引用符を表し、 \27 は単一引用符 (')、 \A9 は著作権記号 (©) を表します。

重要なことは、文字によっては他の方法として、バックスラッシュでエスケープすることもできます。これらには二重引用符で囲まれた文字列内で使われる二重引用符、単一引用符で囲まれた文字列内で使われる単一引用符、およびバックスラッシュ自身です。例えば、 \\ は単一のバックスラッシュを生成します。

改行文字を出力するには、 \A または \00000A のように改行文字としてエスケープする必要があります。しかし、改行を行の末尾の文字として \ でエスケープすると、コード内で文字列を複数行に渡らせることができます。

ただし、改行を行うためには、white-space プロパティに適切な値を設定する必要があります。

メモ: HTML エンティティ (&nbsp;&#8212; など) は、 CSS の <string> の中で使用することはできません。

有効な文字列の例

css
/* 単純な文字列 */
"This string is demarcated by double quotes."
'This string is demarcated by single quotes.'

/* 文字のエスケープ */
"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."

/* 文字列内の改行 */
"This string has a \Aline break in it."

/* 2 行にわたる文字列 (これら 2 つの文字列は同じ出力になります) */
"A really long \
awesome string"
"A really long awesome string"

仕様書

Specification
CSS Values and Units Module Level 4
# strings

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
<string>
Unicode escaped characters (\xx)

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

関連情報