En un document HTML, el selector ID CSS coincideix amb un element basat en el valor del seu atribut id
. L'atribut ID
de l'element seleccionat ha de coincidir exactament amb el valor indicat en el selector
/* The element with id="demo" */
div#demo {
border: red 2px solid;
}
Sintaxi
#id_value { style properties }
Recordeu que això és equivalent al següent attribute selector
:
[id=id_value] { style properties }
Exemple
CSS
div#identified {
background-color: skyblue;
}
HTML
<div id="identified">This div has a special ID on it!</div>
<div>This is just a regular div.</div>
Resultat
Especificacions
Especificació | Estat | Comentari |
---|---|---|
Selectors Level 4 The definition of 'ID selectors' in that specification. |
Working Draft | |
Selectors Level 3 The definition of 'ID selectors' in that specification. |
Recommendation | |
CSS Level 2 (Revision 1) The definition of 'ID selectors' in that specification. |
Recommendation | |
CSS Level 1 The definition of 'ID selectors' in that specification. |
Recommendation | Definició inicial |
Navegadors compatibles
We're converting our compatibility data into a machine-readable JSON format.
This compatibility table still uses the old format,
because we haven't yet converted the data it contains.
Find out how you can help!
Descripció | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Suport bàsic | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
Descripció | Android | Chrome for Android | Edge | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|---|
Suport bàsic | ? | ? | (Yes) | ? | ? | ? | ? |