Class Selector

The CSS class selector (.) is used to apply styles to multiple elements that share the same class name. It allows for reusable and consistent styling across a webpage.

Syntax 

.classname {
    property: value;
}

Example:

.button {
    background-color: blue;
    color: white;
    padding: 10px 20px;
    border-radius: 5px;
    text-align: center;
}
/* Styling a specific element (paragraph) with a class */
p.notice {
    font-size: 18px;
    color: red;
}
Explanation
  • .button applies styles to all elements with the button class.
  • p.notice applies styles only to <p> elements with the notice class.

 Multiple Classes


You can assign multiple classes to an element and apply styles accordingly.

.primary {
    color: white;
    background-color: green;
}
.rounded {
    border-radius: 10px;
}
Example in HTML:

<button class="primary rounded">Click Me</button>
Qus. 1 : Which selector is being used to specify a group of elements

  1. Name
  2. ID
  3. Class
  4. Tag
Qus. 2 : To cluster a group of elements together to apply formatting

  1. tag
  2. class
  3. id
  4. div
Qus. 3 : How can you select all elements of a specific class in CSS

  1. #classname
  2. .classname
  3. element.classname
  4. *classname
Qus. 4 : Which of the following CSS selectors are used to specify a group of elements?

  1. tag
  2. id
  3. class
  4. both class and tag

Programs

HTML code using CSS to create a job application

View Solution


Latest Current Affairs 2025 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online MBA 2 years Online MCA Online BCA Best Website and Software Company in Allahabad