Pseudo-elements

What are Pseudo-elements?

A pseudo-element styles a specific part of an element, written with two colons: p::first-line.

Pseudo-elementStyles
::before / ::aftergenerated content before / after the element's content (needs content)
::first-letterthe first letter
::first-linethe first line
::placeholderplaceholder text of inputs
::selectiontext selected by the user
::markerlist bullets and numbers

Example

Example

Select some text to see ::selection:

<!DOCTYPE html>
<html>
<head>
  <title>Page Title</title>
  <style>
    p::first-letter { font-size: 2em; color: #04AA6D; }
    .new::after { content: " NEW"; color: white; background: tomato; font-size: 0.7em; padding: 1px 4px; }
    .req::before { content: "* "; color: red; }
    ::selection { background: #04AA6D; color: white; }
    li::marker { color: #04AA6D; }
  </style>
</head>
<body>

<p>Pseudo-elements style parts of elements.</p>
<p class="req">Required field</p>
<h3 class="new">CSS Course</h3>
<ul><li>Green bullets</li><li>Via ::marker</li></ul>

</body>
</html>

Result