Careeroza
Pseudo-elements
What are Pseudo-elements?
A pseudo-element styles a specific part of an element, written with two colons: p::first-line.
| Pseudo-element | Styles |
|---|---|
::before / ::after | generated content before / after the element's content (needs content) |
::first-letter | the first letter |
::first-line | the first line |
::placeholder | placeholder text of inputs |
::selection | text selected by the user |
::marker | list 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