0% found this document useful (0 votes)
81 views1 page

The ID and Class Selectors

ID and class selectors allow custom styles to be applied to HTML elements. The ID selector uses the id attribute to uniquely style a single element, defined with a "#". The class selector uses the class attribute to style multiple elements with the same class, defined with a ".". Both ID and class selectors can target specific elements by combining the selector with the element name.

Uploaded by

Elaine Briosos
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
81 views1 page

The ID and Class Selectors

ID and class selectors allow custom styles to be applied to HTML elements. The ID selector uses the id attribute to uniquely style a single element, defined with a "#". The class selector uses the class attribute to style multiple elements with the same class, defined with a ".". Both ID and class selectors can target specific elements by combining the selector with the element name.

Uploaded by

Elaine Briosos
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Submitted by: Elaine Briosos IV- Our Lady of Perpetual Help

Monique Bustillo
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;
}
The Class Selector
The class selector is used to specify a style for a group of elements. Unlike the id
selector, the class selector is most often used on several elements.
This allows you to set a particular style for many HTML elements with the same class.
The class selector uses the HTML class attribute, and is defined with a "."
In the example below, all HTML elements with class="center" will be center-aligned:
Example
.center {text-align:center;}
You can also specify that only specific HTML elements should be affected by a class.
In the example below, all p elements with class="center" will be center-aligned:
Example
p.center {text-align:center;}

You might also like