What are selectors in CSS?

Recommended Answers

All 2 Replies

They are the patterns you use to select elements eg:

    color: red;

This makes all paragraphs red - the "p" is the selector


    border: 1px solid red;

The selector is ".active" which selects all elements with a class of active

Selectors help to select an element to which you want to apply a style. For example below is a simple style called as ‘intro” which applies red color to background of a HTML element.


To apply the above “intro” style to div we can use the “class” selector as shown in the below figure.

<div class="intro">
<p>My name is Shivprasad koirala.</p>
<p>I write interview questions.</p>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.