CSS | Pseudo Elements
Pseudo Elements: Pseudo-element in CSS is used to add style in specified parts of an element. Example: Using style before or after an element.
Syntax:
selector::pseudo-element { property:value; } |
chevron_right
filter_none
Use of Pseudo-Element: Below are some examples to describe the use of pseudo-element.
-
::before Pseudo-element: It is used to add some CSS property before an element when that element is called.
Example:<html><head><title>before</title><style>h1::before {content: "Before element - ";}</style></head><body><h1>GFG</h1><p>It is a paragraph.</p><p>This is another paragraph.</p></body></html>chevron_rightfilter_noneOutput:
-
::after Pseudo-element: It is used to add some CSS property after an element when that element is called.
Example:<html><head><title>after</title><style>h1::after {content: " - after element";}</style></head><body><h1>GFG</h1><p>It is a paragraph.</p><p>This is another paragraph.</p></body></html>chevron_rightfilter_noneOutput:
-
::first-letter Pseudo-element: It is used to make changes to the first letter of an element.
Example:<html><head><title>after</title><style>h1::first-letter {color: #ff0000;}</style></head><body><h1>GFG</h1><p>It is a paragraph.</p><p>This is another paragraph.</p></body></html>chevron_rightfilter_noneOutput:
-
::first-line Pseudo-element: It is used to make changes to the first line of an element.
Example:<html><head><title>after</title><style>h1::first-line {color: #ff0000;}</style></head><body><h1>GFG</h1><p>It is a paragraph.</p><p>This is another paragraph.</p></body></html>chevron_rightfilter_noneOutput:
Recommended Posts:
- CSS | Pseudo-classes
- Use of :even and :odd pseudo-classes with list items in CSS
- XML | Elements
- CSS | Centering Elements
- CSS | Positioning Elements
- HTML | Elements
- jQuery | Remove Elements
- PHP | Check if two arrays contain same elements
- jQuery | Add Elements with Examples
- ReactJS | Rendering Elements
- Find Web Elements using Selenium WebDriver
- How to set flexbox having unequal width of elements using CSS ?
- JavaScript | Add new elements at the beginning of an array
- HTML | Block and Inline Elements
- How to select elements by data attribute using CSS?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




