CSS PSEUDO ELEMENTS
CSS Pseudo Elements are used to style specific parts of an element.
Here's the syntax:
selector::pseudo-element {
property: value;
}
::first-line
The :first-line pseudo-element is used to select the first line of text to style it. It only applies to block elements.
p::first-line {
color: #00ff2a;
}
Live Demo!
Output:
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
::first-letter
The :first-letter pseudo-element is used to style the first letter of the text. It only applies to block elements.
p::first-letter {
color: #ff5100;
font-size: 50px;
}
Live Demo!
Output:
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
::before
The ::before pseudo-element is used to style the content that comes before an element.
p::before {
content: "=>";
font-size: 20px;
color: red;
}
Live Demo!
Output:
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
::after
The ::after pseudo-element is used to style the content that comes after an element.
p::after {
content: "...";
color: red;
}
Live Demo!
Output:
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
::marker
The ::marker pseudo-element is used to select the markers of list items.
::marker {
color: rgb(60, 255, 0);
}
Live Demo!
Output:
- First item
- Second item
- Third item
::selection
The ::selection pseudo element targets part of the text is that is selected by the user.
::selection {
color: red;
background: rgb(0, 140, 255);
}
Live Demo!
Output:
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.