MDN self-hosted library · e01.org
ID selectors / notebook

ID selectors

Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.

css
/* The element with id="demo" */
#demo {
  border: red 2px solid;
}
css
#id_value {
  /* … */
}
css
[id="id_value"] {
  /* … */
}
html
<p id="blue">This paragraph has a blue background.</p>
<p>This is just a regular paragraph.</p>
html
<!-- The next two paragraphs have id attributes
that contain characters which must be escaped in CSS -->

<p id="item?one">This paragraph has a pink background.</p>
<p id="123item">This paragraph has a yellow background.</p>
css
#blue {
  background-color: skyblue;
}
css
/* In the next two rules, the id attributes must be escaped */

#item\?one {
  background-color: pink;
}

#\00003123item {
  background-color: yellow;
}