CSS id selectors – define style by element id

The CSS id selector matches element having a specific id attribute This can be used to specify CSS style based on element id. Note that id should be unique and no two elements should have same id.

Here is the syntax for defining style using id selector.

#id1 { style properties } /*element having id id1*/

div#id1 { style properties } /*div element having id id1*/

Example – style using id selector

/* div#id1 can also be used to be more specific */
#id1 {
  width: 100px; height:100px;
  background-color: lightgreen;

<div id="id1">
  Hello world



Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit


Click here to write/view comments