CSS - Element Selectors
CSS - Element Selectors
Element Selectors in CSS
CSS element selectors are used to target and style specificHTML elements. These selectors are defined by simply using the elementβs name in the stylesheet.
Syntax
The syntax for CSS element selectors is as follows:
CSS CODE
element_name {
/*property: value;*/
color: red;
}Using Element Selectors Setting Background Color
To set thebackground colorand textcolorof all<p>elements, use the element selector.
Example
The following example sets the background color and text color for all <p> elements.
Preview
Using Element Selectors Setting Border
The element selector can be used to add aborderto all<div>elements.
Example
The following example adds a border to all <div> elements.
Preview
Using Element Selectors Setting Font
To apply a font style to all<li>elements, use the element selector.
Example
This example sets thefont sizeandfont familyfor all <li> elements.
Preview