What is Pseudo Element?
Pseudo-elements are used to select and apply the styles to the particular element or part of elements in the DOM.
Pseudo-elements denoted by ( :: ) symbol.
Multiple Pseudo-elements can be used for a single element.
selector::pseudo-element {
property: value;
}
Example :
Pseudo-elements help to apply the style to the first letter or first line of your HTML elements.
There are six types of Pseudo-elements let's see each pseudo-element with an example.
1) ::first-line
The::first-line pseudo-element helps to select and apply the style to the first line of text and paragraph and heading.
The::first-line element we can only use these property font,color,background,word-spacing,letter-spacing,text-decoration,vertical-align,text-transform,line-height and clear.
Note::first-line pseudo-element works only on block-level elements.
Example:
HTML
<p> The::first-line pseudo-element helps to select and apply the style to the first line of text and paragraph and heading.</p>
CSS
p::first-line {
color: green;
}
Output:
The::first-line pseudo-element helps to select and apply the style to
the first line of text and paragraph and heading.
2) ::first-letter
The::first-letter pseudo-element helps to select and apply the style to the first letter of text and paragraph and heading.
The::first-line element we can only use these property font,color,background,margin,padding,border,text-decoration,vertical-align (only if "float" is "none"),text-transform,line-height,float and clear.
Example:
HTML
<p> The::first-line pseudo-element helps to select and apply the style to the first line of text and paragraph and heading.</p>
CSS
p::first-letter {
color: red;font-size: 18px;
}
Output:
The::first-line pseudo-element helps to select and apply the style to
the first line of text and paragraph and heading.
3) ::before
The::before pseudo-element helps to add or insert content to the before the content of an element.
Example:
HTML
<p> The::before pseudo-element helps to add or insert content to the before the content of an element.</p>
CSS
p::before {
content: url(smiley.gif);
}
Output
😀The::before pseudo-element helps to add or insert content to the before the content of an element.
4) ::after
The::after pseudo-element helps to add or insert content to the after the content of an element.
Example:
HTML
<p> The::after pseudo-element helps to add or insert content to the after the content of an element.</p>
CSS
p::after {
content: url(smiley.gif);
}
Output
The::before pseudo-element helps to add or insert content to the before the content of an element.😀
5) ::marker
The:: marker pseudo-element helps to apply the style to the order and un-order list.
Example:
HTML
<ul>
<li>Attractive Aurora</li>
<li>Attractive</li>
<li>Aurora</li>
</ul>
CSS
::marker {
color: red;
}
Output
6) ::selection
The:: selection pseudo-element helps to apply the style to the user-selected text.The::selection pseudo-element accepts the minimum number of CSS properties.
The ::selection pseudo-element supports colors,background,outline and cursor.
Example:
HTML
<p> The ::selection pseudo-element helps to apply style to the user selection text.</p>
CSS
::selection {
color: red;
background: yellow;
}
Output
The:: selection pseudo-element helps to apply the style to the user-selected text
I think this information is helpful to you.
Thanks for reading - Don't Forgot To Share & Comment
Any suggestion or queries please comment, our team will response asps.
You may like this :
CSS Selectors That Every Developer Must Know
Javascript Web API's That Every Developer Should Know
HTML API's That Every Developer Should Know
Best Chrome Extensions for Front End Developers - Part 2
Best Chrome Extensions for Front End Developers