Posts tagged ‘id’

CSS Id and Class

The id and class Selectors

In addition to setting a style for a HTML element, CSS allows you to specify your own selectors called “id” and “class”.


The id Selector

The id selector is used to specify a style for a single, unique element.

The id selector uses the id attribute of the HTML element, and is defined with a “#”.

The style rule below will be applied to the element with id=”para1″:

Example

#para1
{
text-align:center;
color:red;
}

Remark Do NOTstart an ID name with a number! It will not work in Mozilla/Firefox. Continue reading ‘CSS Id and Class’ »

What is ID selector

ID selector is an individually identified (named) selector  to which a specific style is declared.  Using the ID attribute the declared style can then be associated with one and only one HTML element per document as to differentiate it from all other elements. ID selectors are created by a character # followed by the selector’s name. The name can contain characters a-z, A-Z, digits 0-9, period, hyphen, escaped characters, Unicode characters 161-255, as well as any Unicode character as a numeric code, however, they cannot start with a dash or a digit.

#exm {color: red; background: black}

<P ID=exm>This and only this element can be identified as exm</P>

Related:What is CLASS selector