VOOZH about

URL: https://www.geeksforgeeks.org/css/which-characters-are-valid-in-css-class-names-selectors/

⇱ Which characters are valid in CSS class names/selectors? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Which characters are valid in CSS class names/selectors?

Last Updated : 3 Aug, 2023

It is very easy to choose a valid class name or selectors in CSS just follow the rule. 

  • A valid name should start with an underscore (_), a hyphen (-) or a letter (a-z)/(A-Z) which is followed by any numbers, hyphens, underscores, letters.
  • It cannot start with a digit, starting with the digit is acceptable by HTML5 but not acceptable by CSS.
  • Two hyphens followed by a number is valid.

Example 1: This example describes the list of valid id selectors using CSS. 

Output:

👁 Image

Example 2: This example describes the list of valid class selectors using CSS. 

Output:

👁 Image
Comment
Article Tags: