Pseudo-elements ::before and ::after.
Summary of characteristics of the ::before selector
Description of pseudo-elements ::before and ::after.
Very different from the other selectors, the ::before and ::after pseudo-elements are able to add
an item before or after the targeted item. The contents of this added element are defined by the content property.
The example below adds an element containing the text "-->" to paragraphs in the note class. The added element
is of type inline: no line breaks are added, either before or after the element.
p.note::before {content:'--> ';}
This first paragraph is not associated with any class.
This second paragraph has the class="note" attribute.
The content property is therefore required to define the content of the added element, but all other properties
can be used to format this new item.
Animations or transitions can also be applied, although browser compatibility is less good in this respect.
This is the item with the description description2. It consists of 2 paragraphs.
Second paragraph.
Be careful! The ::before and ::after pseudo-elements are only operational if they are applied to an element
likely to contain others. They therefore have no effect on a number of tags such as img, br,
input, textarea, etc. ::before and ::after are also ineffective if applied
to select because this tag only accepts option elements.
Note: Text in elements added with the ::before pseudo-element are taken into account by other pseudo-elements
::first-letter and ::first-line.
We can see that the content property is inseparable from the pseudo-elements ::before and ::after.
We recommend that you also check the content property page to find out what can be inserted
before or after an element: the value of a counter, an image, consecutive points, etc.

Examples of how to use ::before and ::after.
Add a finial after each paragraph.
Elements inserted by ::before or ::after are by default of the inline type, but it is quite
possible to redefine them as a block so that they are preceded and followed by a line break.
This is what was done in the example below, to add a floret (a decoration) after each paragraph.
Quisque at dolor nec lorem pellentesque congue id id diam. Vestibulum efficitur suscipit elit et tincidunt. In pharetra malesuada neque a egestas. Nullam id tortor leo. Proin vitae placerat tellus. Duis ultrices dolor at nisi vulputate, non tincidunt metus dictum.
Suspendisse potenti. Aliquam sit amet elit nec sem hendrerit volutpat. Curabitur rhoncus nisi pharetra lorem vehicula, ut consectetur turpis facilisis. Ut pulvinar lobortis dui in consequat. Morbi suscipit rhoncus elit at pharetra.
Donec sed varius mi. Morbi imperdiet elit in scelerisque tincidunt. Donec aliquam erat aliquam sem auctor consequat. Curabitur aliquam sem odio, tincidunt commodo tellus mollis id. Aliquam hendrerit mattis risus, sit amet bibendum mi porttitor vel.
Browser compatibility.
Support for the ::before and ::after pseudo-elements is no problem with current browsers,
including when it comes to applying animations or transitions to these pseudo-elements.
::before and ::after used to insert content and style it before or after the element.::before and ::after.::before
::afterselectors
::before and ::afterBrowsers on computers :
Mobile browsers :
Outdated or marginal browsers :

Internet Explorer

KaiOS Browser

Opéra Mobile

Chrome

Firefox

Opéra

Samsung Internet

Baidu Browser

QQ Browser

UC Browser pour Androïd

Edge

Safari sur IOS

Androïd Brower

Safari

Chrome pour Androïd

Firefox pour Androïd

Opéra mini
Pseudo-elements ::before and ::after history.
-
Cascading Style Sheets Level 2 - Revision 1 Specification
Introduction of::beforeand::afterpseudo-elements in CSS version 2.November 04, 1997Working Draft.March 24, 1998Proposed for recommendation.May 11, 1998Recommendation . -
CSS Pseudo-Elements Module Level 4
Since this version, pseudo-element names begin with a double colon (::). The old names, with a single colon, are still recognized.January 15, 2015Working Draft.
Others pseudo-elements.
Selectors:




placeholder attribute).





