What is Pseudo Class in CSS?
- It is used to apply the style on the special state of the HTML element.
- Pseudo-classes are used to style HTML elements when a user mouse over.
- Used to style the visited and unvisited links.
- Used to style the different HTML elements on different states.
This will be our basic boilerplate code for CSS Pseudo Classes
index.html
List of Pseudo Classes in CSS
i) :hover
It is used to style the element on mouse hover.
ii) :link
Used to style all the unvisited links.
iii) :visited
Used to style all the visited links.
iv) :active
It is used to style the active link.
v) :first-child
This will style the first child element of the parent.
vi) :last-child
This will style the last child element of the parent.
viii) :nth-child(n)
This will select every nth child element of parent element.
ix) :nth-last-child(n)
This will select every n child element of the parent element from the last.
x) :nth-last-of-type(n)
This will select every n element of its parent from the last child.
xi) :nth-of-type(n)
This will select every n element of the parent.
xii) p:only-of-type
This will select every <p> element that is only <p> element of its parent.
xiii) :first-of-type
This will select every 1st element of the selected type of its parent.
xiv) :last-of-type
This will select every last element of the selected type of its parent.
xv) :empty
This will select the element which don't have any children.
xvi) :focus
Select the input element that has focus.
xvii) :checked
Select every checked input element.
xviii) :disabled
Select every disabled input element.
xix) :enabled
Select every enabled input element.
xx) :required
This will select the input element which has required attribute.
xxi) :optional
Select the input element with no required attributed.
xxii) :read-only
This will select every element with "readonly" attribute.
xxiii) :valid
This will select every <input> elements with a valid value.
xxiv) :invalid
This will select every element with "readonly" attribute.
xxv) :root
This will select the root element of the document.