html ::before ::after pseudo-elements

Sometimes, when I inspect an element on a webpage by right-clicking the element and choosing the “Inspect Element” menu item, I can find an interesting element “::before” or “::after” inside the element like the following:

 But when I right-click on the page and select the “View Page Source” menu item, I cannot find the string “::before” or “::after” inside the element in the source code.

What are ::before and ::after? Well, they are called pseudo-elements. Pseudo-elements are part of CSS which allow you to insert content before/after the actual content of an element(but still inside the element).

Since pseudo-elements belong to CSS, you cannot write them in html as ordinary elements, but write them using CSS syntax, i.e., using a selector such as “p::before” followed by css properties contained in {}. The following is a pseudo-element example

p::before
{
    content:"before actual element content";
}

The content of the pseudo-element will be shown before the real content of the element in your browser, but not shown in the Inspector window in your browser(such as firefox) when you inspect the element(see the above image).  Fortunately, you can click the pseudo-element (shown as “::before” or “::after”) and the definition of the pseudo-element will be shown in the css panel next to the html panel in the Inspector window.

The pseudo-elements can be not only text but also an image.

Did you like this?
Tip admin with Cryptocurrency

Donate Bitcoin to admin

Scan to Donate Bitcoin to admin
Scan the QR code or copy the address below into your wallet to send some bitcoin:

Donate Bitcoin Cash to admin

Scan to Donate Bitcoin Cash to admin
Scan the QR code or copy the address below into your wallet to send bitcoin:

Donate Ethereum to admin

Scan to Donate Ethereum to admin
Scan the QR code or copy the address below into your wallet to send some Ether:

Donate Litecoin to admin

Scan to Donate Litecoin to admin
Scan the QR code or copy the address below into your wallet to send some Litecoin:

Donate Monero to admin

Scan to Donate Monero to admin
Scan the QR code or copy the address below into your wallet to send some Monero:

Donate ZCash to admin

Scan to Donate ZCash to admin
Scan the QR code or copy the address below into your wallet to send some ZCash:

Leave a Reply