HTML & CSS - Mastery / CSS Selectors

Pseudo-elements selectors (select and style a part of an element)

✅ Common Pseudo-element Selectors

Selector

Description

::first-letter

Styles the first letter of a block

::first-line

Styles the first line of a block

::before

Inserts content before an element

::after

Inserts content after an element

::placeholder

Styles the placeholder text in <input>/<textarea>

🔸 Double colons (::) are standard, but old browsers still accept a single colon (:).


✅ Example with Separate HTML and CSS Files

🖥️ Output Summary

  • The first letter of the paragraph is big and red.

  • The first line is blue.

  • The <h1> has a sparkle emoji before it.

  • The button says “Click Me 👉” using ::after.

  • The placeholder in the input is gray and italic.


🚀 Try and Play Around