--- title: ID セレクター slug: Web/CSS/ID_selectors tags: - CSS - Reference - Selector - Selectors translation_of: Web/CSS/ID_selectors --- <div>{{CSSRef}}</div> <p>CSS の <strong>ID セレクター</strong> (ID selector) は、 {{htmlattrxref("id")}} 属性の値に基づいて要素と一致します。選択される要素の <code>id</code> 属性は、セレクターで指定した値と完全一致していなければなりません。</p> <pre class="brush: css no-line-numbers notranslate">/* id="demo" のついた要素 */ #demo { border: red 2px solid; }</pre> <h2 id="Syntax" name="Syntax">構文</h2> <pre class="syntaxbox notranslate">#id_value { <em>スタイルプロパティ</em> }</pre> <p>なお、これは次の{{Cssxref("Attribute_selectors", "属性セレクター")}}と等価です (ただし、詳細度は異なります)。</p> <pre class="syntaxbox notranslate">[id=id_value] { <em>スタイルプロパティ</em> }</pre> <h2 id="Examples" name="Examples">例</h2> <h3 id="CSS">CSS</h3> <pre class="brush: css notranslate">#identified { background-color: skyblue; } </pre> <h3 id="HTML">HTML</h3> <pre class="brush: html notranslate"><div id="identified">これは特別な ID がついています!</div> <div>これは単なる普通の div です。</div> </pre> <h3 id="Result" name="Result">結果</h3> <p>{{EmbedLiveSample("Examples", '100%', 50)}}</p> <h2 id="Specifications" name="Specifications">仕様書</h2> <table class="standard-table"> <thead> <tr> <th scope="col">仕様書</th> <th scope="col">状態</th> <th scope="col">備考</th> </tr> </thead> <tbody> <tr> <td>{{SpecName("CSS4 Selectors", "#id-selectors", "ID selectors")}}</td> <td>{{Spec2("CSS4 Selectors")}}</td> <td></td> </tr> <tr> <td>{{SpecName("CSS3 Selectors", "#id-selectors", "ID selectors")}}</td> <td>{{Spec2("CSS3 Selectors")}}</td> <td></td> </tr> <tr> <td>{{SpecName("CSS2.1", "selector.html#id-selectors", "ID selectors")}}</td> <td>{{Spec2("CSS2.1")}}</td> <td></td> </tr> <tr> <td>{{SpecName("CSS1", "#id-as-selector", "ID selectors")}}</td> <td>{{Spec2("CSS1")}}</td> <td>初回定義</td> </tr> </tbody> </table> <h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザーの互換性</h2> <p>{{Compat("css.selectors.id")}}</p>