Selectors in CSS


What are CSS Selectors?



Element Selector:

Element selectors are used to targeting the HTML element by tag name and style them in our style sheet.

Example:

index.html

<!DOCTYPE html>
<html>
<head>
    <title>Element Selector</title>
<link  rel=" shortcut icon" href=" favicon.png" >
<link  rel=" stylesheet" href=" style.css" >
</head>
<body>
   <p > Mallu Coder Sugu</p>
</body>
</html>

Syle.css

            p {
            color: red;
                }

Group Selectors:

The name suggests group selectors are used to selecting multiple elements and applying the same style to them.

Example:
<!DOCTYPE html>
<html>
<head>
    <title>External CSS</title>
<link  rel=" shortcut icon" href=" favicon.png" >
<link  rel=" stylesheet" href=" style.css" >
</head>
<body>
   <p > Mallu Coder Sugu</p>
   <h2 > Stay and Learn </h2>
</body>
</html>

            p, h2 {
            color: red;
                }

Id Selector

Id selectors are mainly used to target particular HTML element with the help of id and apply styles to them. The id of any HTML element should be unique. Hash (#) is used to target the particular element from the HTML document.

Example:

<!DOCTYPE html>
<html>
<head>
    <title>External CSS</title>
<link  rel=" shortcut icon" href=" favicon.png" >
<link  rel=" stylesheet" href=" style.css" >
</head>
<body>
   <h2 id="heading"> Mallu Coder Sugu</h2>
</body>
</html>

# heading {
            color: red;
                }

Class Selector

Class selectors are mainly used to target multiple HTML elements with their classes and apply styles to them. An HTML element can contain multiple classes and multiple elements can have the same class. (.) is used to target the multiple elements with the class from the HTML document.

Example:

<!DOCTYPE html>
<html>
<head>
    <title>External CSS</title>
<link  rel=" shortcut icon" href=" favicon.png" >
<link  rel=" stylesheet" href=" style.css" >
</head>
<body>
   <p class="test"> Mallu Coder Sugu</p>
</body>
</html>

.test {
            color: red;
                }

Introduction to CSS Part-2 PDF Click here to download

Easy Pickup


  • 1. CSS More Samples
  • 2. CSS Malayalam Classes
  • 3. CSS Malayalam Notes

New Post 



View Post


Acer Predator Neo (2023) Core i7 13700HX 13th Gen







ചന്ദ്രനുശേഷം സൂര്യൻ! അഭിമാനമാകാൻ ആദിത്യാ എല്‍1; ദൗത്യത്തെക്കുറിച്ച് അറിയേണ്ടതെല്ലാം...





മൈക്രോസോഫ്റ്റ് എക്സൽ ഉപയോഗിക്കുന്നുണ്ടോ?, ഇനി മാറ്റം ഇങ്ങനെ......



SYAMRAJ R

Founder and Developer of Mallu Coder Sugu.We provide the best Computer or Programming Related Content With Notes PDF, Amazing Designs, Easy to Readable for Learners.






Welcome to our Web Designing Studio! Stay and learn from here... Follow our social media for new updates