Member-only story

CSS decoded ::before and ::after

Tapajyoti Bose
2 min readFeb 28, 2021

What is a Pseudo Element in CSS?

A CSS Pseudo Element is a keyword added to a selector that lets you style a specific part of the selected element(s). For example, ::first-line can be used to style the first line of a paragraph, ::before can be used to prepend an element and style it as well, etc.

The main utility of the Pseudo Element is for cosmetic purpose only.

In CSS3 the Pseudo Elements are represented by ::<pseudo-element>, even though the CSS2 syntax :<pseudo-element> still works on most browsers for the Pseudo Elements that were available in CSS2.

What is the use of ::before and ::after?

In CSS, ::before and ::after creates pseudo-elements that is the prepended and appended to the selected element respectively.

How do I use ::before and ::after in my website?

One really important thing to keep in mind while using ::before and ::after is to set content property in the CSS

selector::before{
/* without content the pseudo-elements will not work */
content: "";
}

After adding the content, you can style them just like any other element

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Tapajyoti Bose
Tapajyoti Bose

Written by Tapajyoti Bose

Top Rated Freelancer || Blogger || Cross-Platform App Developer || Web Developer || Open Source Contributor || FIRE Enthusiast

No responses yet

Write a response

I was gonna say that I think "steroids" are a bad analogy. But after I actually bothered to read up on them, I think the analogy is perfect.
Steroids just make you look tougher without making you tough. From my experience using TS for a couple of…

A steroid is a biologically active organic compound with four rings arranged in a specific molecular configuration. Steroids have two principal biological functions: as important components of cell membranes which alter membrane fluidity; and as signaling molecules.