</> Code Corner

CSS · CSS Tutorial · Lesson 30

CSS Pseudo-elements

::before, ::after, ::first-letter and more.

A pseudo-element styles a specified part of an element — for example the first letter, or content inserted before or after it.

Example

<style>
p.intro::first-letter { font-size: 200%; color: #04AA6D; }
p.intro::first-line { font-weight: bold; }
h2::before { content: "\2605 "; color: gold; }
h2::after { content: " (new)"; color: gray; font-size: 60%; }
::selection { background: #04AA6D; color: white; }
</style>
<h2>Pseudo-elements</h2>
<p class="intro">You can style the first letter and the first line of a paragraph. Select some text to see the custom selection color.</p>
Tip: Pseudo-elements use a double colon (::). ::before and ::after require the content property.

Keep reading “CSS Pseudo-elements”

Sign up to read the full lesson, try every example in the live editor, and take the 5-question quiz.

Chat with us 👋