CSS Selectors

Type

    

p {}


    

Class

    

<div class="class-name"></div>


    
    

.class-name {}


    

Multiple classes

    

<div class="class-one class-two"></div>


    
    

.class-one.class-two {}


    

Type with class

    

<p class="class-name"></p>


    
    

p.class-name {}


    

ID

    

<div id="id-name"></div>


    
    

#id-name {}


    

Descendant

    

#id-name p {}


    

Child

    

#id-name > p {}


    

Attribute

    

/* Elements with attribute */
[title] {}


    
    

/* Type with attribute */
a[title] {}


    
    

/* Exact */
a[title="value"] {}


    
    

/* Contains value */
a[title*="value"] {}


    
    

/* Starts with value */
a[title^="value"] {}


    
    

/* Ends with value */
a[title$="value"] {}


    

Sibling

    

p ~ ul {}


    

Adjacent sibling

    

p + ul {}


    

Selector list

    

p, .class-name, #id-name {}


    

Pseudo class

    

a:hover {}


    

Pseudo element

Pseudo elements:

  • ::after
  • ::before
  • ::first-letter
  • ::first-line
    

.class-name::before {}


    

Universal

    

* {}