Just like we have pseudo-classes, which allow us to select things without them being HTML itself, we also have pseudo-elements.
While pseudo-classes allow us to select things based on their state, pseudo-elements create entire elements!
While pseudo-classes use a single colon, pseudo-elements use a double colon (::).
There are a lot of pseudo-elements, but the two that you will use the most are:
Almost any element can have a pseudo-element on it (we can’t use them on images and other replaced elements, at least for now).
There is one property that you must use with ::before and ::after, which is the content property. Without content, these pseudo-elements don’t exist.
It also needs to either have a display or position.
position: /* something */
One common misconception with pseudo-elements is that they go before or after the element we’ve selected, but they go before, or after, the content inside of that element.
You can use strings of text as the content, use url() to bring images, use one of the gradient value functions, or just keep it blank to create your own decorations.
Some quick wins that many people don’t know about are features like open and close quotes.
See the Pen
quotes by Kevin (@kevinpowell )
on CodePen .
For a long time, the ::before and ::after pseudo-elements were problematic from an accessibility point of view.
Different assistive technologies would treat them in different ways, and a lot of official guidelines say that using them to insert anything other than decorative content fails certain accessibility guidelines .
Screen readers will read text that’s inserted using ::before and ::after, and these days, we can also supply alternative text, and browser support is reaching decent levels for it.
.toast-notification.error {
content : url ( ' images/exclamation.svg ' ) / ' Error! ' ;
Let’s add a couple to our courses
Let’s add two to our courses, one with some text to let users know a course is on sale, and a second one that has a star that indicates a popular course.
Starting code
If you fell behind or skipped the earlier lessons, you can use this starting code, or the 09-pseudo-elements folder from this GitHub repo .
HTML < meta name = " viewport " content = " width=device-width, initial-scale=1.0 " >
< title > Learn Chess the right way </ title >
< link href = " styles/style.css " rel = " stylesheet " >
< header class = " page-header " >
< div class = " page-header-layout " >
< img src = " images/crown.svg " alt = " Frontend Masters Chess Acadamy " >
< nav class = " primary-nav " >
< li >< a href = " index.html " > Home </ a ></ li >
< li >< a href = " instructor.html " > Instructor </ a ></ li >
< li >< a href = " # " > Start Learning </ a ></ li >
< div class = " hero-content " >
< h1 >< span > Books hard to follow? YouTube letting you down? </ span > Learn Chess the right way. </ h1 >
< p class = " lede " > Chess shouldn't feel like memorizing endless opening variations or sifting through amateur
explanations. Our structured approach breaks down complex strategies into clear, progressive steps with
instruction and personalized feedback. < strong > Stop wasting time with scattered resources and start
< button class = " button " > Start learning today! </ button >
< h2 > Start your journey to grandmaster today </ h2 >
< div class = " three-columns " >
< h3 > Learn the Right Way, in the Right Order </ h3 >
< p > Our curriculum follows proven chess pedagogy, building from fundamentals to advanced strategy. Each
naturally to the next, so you always know what to study. </ p >
< h3 > Train with Expert Instructors </ h3 >
< p > Learn from titled players who break down complex concepts into clear insights. Understand not just what
< h3 > Track Your Progress with Precision </ h3 >
< p > Detailed analytics identify your strengths and weaknesses, then adapt your training to focus on what
for your improvement. </ p >
< h2 > Some of what awaits inside </ h2 >
< div class = " three-columns " >
< h3 class = " course-title " > The Power of Central Control </ h3 >
< span class = " course-tag " > Strategy </ span >
< img class = " course-image " src = " images/central-control.jpg "
alt = " A pawn in the center of the board, with all the pieces around it fallen over. " >
< p class = " course-description " > Control the center, control game. </ p >
< h3 class = " course-title " > Fork, Pin, and Skewer </ h3 >
< span class = " course-tag " > Tactics </ span >
< img class = " course-image " src = " images/fork-pin-skewer.jpg "
alt = " Dramatic shot of a chess board, with the foreground peices out of focus, with a white queen in front of a black king " >
< p class = " course-description " > Learn three essential tactical patterns. </ p >
< h3 class = " course-title " > King and Pawn Endgames </ h3 >
< span class = " course-tag " > Endgames </ span >
< img class = " course-image " src = " images/king-pawn-endgame.jpg "
alt = " A wooden chessboard with only a few pieces left on it. " >
< p class = " course-description " > Master the most fundamental endgame. </ p >
< h3 class = " course-title " > The Italian Opening </ h3 >
< span class = " course-tag " > Opening Theory </ span >
< img class = " course-image " src = " images/italian-opening.jpg "
alt = " A dramatic shot of a black and white chess board showing an advanced position after starting with the Italian Opening " >
< p class = " course-description " > Understand the value of exchanges. </ p >
< h3 class = " course-title " > When to Trade Pieces </ h3 >
< span class = " course-tag " > Strategy </ span >
< img class = " course-image " src = " images/trading-pieces.jpg "
alt = " A person knocking over a knight with their bishop " >
< p class = " course-description " > Understand the value of exchanges. </ p >
< h3 class = " course-title " > Calculating Two Moves Ahead </ h3 >
< span class = " course-tag " > Calculation </ span >
< img class = " course-image " src = " images/calculating.jpg "
alt = " A person deep in thought, contemplating their next move " >
< p class = " course-description " > Improve your visualization and accuracy. </ p >
< footer class = " page-footer " >
< div class = " page-footer-content " >
< h2 > Ready to Improve Your Chess? </ h2 >
< p > Join thousands of students who are already leveling up their game. Start your first lesson today—it's free to
started!. < a href = " instructor.html " > Start learning today! </ a ></ p >
CSS src : local ( " Overlock " ), url ( " ../fonts/Overlock-Regular.ttf " );
src : local ( " Overlock Bold " ), url ( " ../fonts/Overlock-Bold.ttf " );
--clr-accent-300 : hsl ( 39 94 % 57 % );
--clr-accent-400 : hsl ( 39 100 % 41 % );
--clr-neutral-100 : hsl ( 0 0 % 100 % );
--clr-neutral-800 : hsl ( 0 0 % 20 % );
--clr-neutral-900 : hsl ( 0 0 % 0 % );
--ff-base : system-ui , sans-serif ;
--ff-accent : Overlock, serif ;
color : var ( --clr-neutral-800 );
font-size : var ( --fs-400 );
font-family : var ( --ff-base );
color : var ( --clr-accent-400 );
font-family : var ( --ff-accent );
font-size : var ( --fs-800 );
color : var ( --clr-neutral-800 );
font-size : var ( --fs-700 );
font-size : var ( --fs-600 );
color : var ( --clr-accent-400 );
text-transform : uppercase ;
background : var ( --clr-accent-300 );
background : var ( --clr-neutral-800 );
color : var ( --clr-accent-300 );
font-size : var ( --fs-500 );
grid-template-columns : repeat ( 3 , 1 fr );
background : var ( --clr-neutral-900 );
justify-content : space-between ;
color : var ( --clr-neutral-100 );
color : var ( --clr-accent-300 );
background-image : url ( ../images/chess-bg.jpg );
background : hsl ( 0 0 % 100 % / 0.8 );
.hero-content > :first-child {
.hero-content > :last-child {
--transition-duration : 325 ms ;
padding : 100 px 21 px 21 px ;
color : var ( --clr-neutral-100 );
/* background: hsl(0 0% 0%); */
font-size : var ( --fs-300 );
transition: translate var(--transition-duration);
font-family : var ( --ff-accent );
background : var ( --clr-accent-300 );
color : var ( --clr-neutral-900 );
transition : scale var ( --transition-duration );
background-image : linear-gradient ( # 444 , # 000 );
color : var ( --clr-neutral-100 );
margin-block-start : 100 px ;
There are other pseudo-elements
There are a lot of other types of pseudo-elements ! I only talked about ::before and ::after because they’re the ones you’d use the most often.
Most of the others are for fairly specific use cases, though two that you might want to look into more now are ::marker and ::selection .