Another tool in the CSS selector toolbox is the pseudo-class.
A pseudo-class allows you to select elements based on some special state of the element, in addition to all the selectors previously discussed.
Pseudo-classes start with a colon and can be used alone or in conjunction with other selectors.
Some pseudo-classes let you select elements based on UI state, while others let you select elements based on their position in the document (with more precision than the combinators).
These pseudo-classes are based on some UI state.
Matches an element that is currently being activated.
For buttons and links, this usually means the mouse button has been pressed but not yet released.
Matches a radio button, checkbox, or option inside a select element that is checked or selected.
Matches an element that currently has the focus. This is typically used for buttons, links, and text fields.
Matches an element that the mouse cursor is currently hovering over.
This is typically used for buttons and links but can be applied to any type of element.
Used with form elements using HTML5 validation.
The :valid pseudo-class matches an element which is currently valid according to the validation rules, and :invalid matches an element which is not currently valid.
Matches a link whose URL has already been visited by the user.
To protect a user’s privacy, the browser limits what styling can be done on an element matched by this pseudo-class.
Syntax For Pseudo classes -
Now we will see a few Examples -
/* for universal links*/
/* visited link */
/* mouse over link */
/* selected link */
<link rel="stylesheet" href="sample.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Sofia|Audiowide|Trirong">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<h1 class="one">link to goole.com</h1>
<p><b><a href="https://www.facebook.com/" target="_blank">CLICK HERE TO GO TO GOOGLE</a></b></p>
Now we will see the list of pseudo-classes -