ID セレクター

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.

CSS の ID セレクター (ID selector) は、 id 属性の値に基づいて要素と一致します。選択される要素の id 属性は、セレクターで指定した値と完全一致していなければなりません。

css
/* id="demo" のついた要素 */
#demo {
  border: red 2px solid;
}

構文

css
#id_value { スタイルプロパティ }

なお、これは次の属性セレクターと等価です (ただし、詳細度は異なります)。

css
[id=id_value] { スタイルプロパティ }

CSS

css
#identified {
  background-color: skyblue;
}

HTML

html
<div id="identified">これは特別な ID がついています!</div>
<div>これは単なる普通の div です。</div>

結果

仕様書

Specification
Selectors Level 4
# id-selectors

ブラウザーの互換性

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
ID selector (#idName)

Legend

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

Full support
Full support

関連情報