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
- CSS :scope pseudo-class
- How to override the CSS properties of a class using another CSS class ?
- Difference between bootstrap.css and bootstrap-theme.css
- How to prevent parents of floated elements from collapsing in CSS?
- CSS | Centering Elements
- CSS | Positioning Elements
- How to select all child elements recursively using CSS?
- How to select elements by data attribute using CSS?
- How to get specific number of child elements using CSS?
- How to set flexbox having unequal width of elements using CSS ?
- How to hide elements in responsive layout using CSS ?
- How to select all elements that contains some specific CSS property using jQuery ?
- How to Shift Inline Elements When Text Bold on Hover using CSS ?
- How to stack elements in CSS ?
- CSS Float
- CSS | Selectors Complete Reference
- CSS | Margins and Padding
- CSS | table-layout Property
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.


