CSS Pseudo Class vs Pseudo Element

By Xah Lee. Date: .

CSS Pseudo-Class

A CSS “pseudo-class” is a keyword that matches state of selected element. example: :hover.

Example:

a:visited, a:link {text-decoration:none}
a:hover {background-color:pink}

Here's complete list of pseudo-class:

  1. :active
  2. :any
  3. :any-link
  4. :checked
  5. :default
  6. :defined
  7. :dir()
  8. :disabled
  9. :empty
  10. :enabled
  11. :first
  12. :first-child
  13. :first-of-type
  14. :fullscreen
  15. :focus
  16. :focus-visible
  17. :host
  18. :host()
  19. :host-context()
  20. :hover
  21. :indeterminate
  22. :in-range
  23. :invalid
  24. :lang()
  25. :last-child
  26. :last-of-type
  27. :left
  28. :link
  29. :not()
  30. :nth-child()
  31. :nth-last-child()
  32. :nth-last-of-type()
  33. :nth-of-type()
  34. :only-child
  35. :only-of-type
  36. :optional
  37. :out-of-range
  38. :read-only
  39. :read-write
  40. :required
  41. :right
  42. :root
  43. :scope
  44. :target
  45. :valid
  46. :visited

CSS Pseudo-Element

A CSS “pseudo-element” is a keyword that control style of part of the selected element. example: ::first-line matches the first line of a paragraph.

Example:

p.e74775:first-letter {font-size:40px}

[see CSS: Match first-letter and first-line]

Note: in CSS 2, pseudo-element syntax is with 1 single colon. example: p:first-letter But in CSS 3, it's changed to 2 colons, example: p::first-letter, to distinguish it from pseudo-class.

Single colon is still supported in browsers.

As of 2018, most websites still use 1 single colon.

Here's a complete list of pseudo-element:

  1. ::after
  2. ::before
  3. ::cue
  4. ::first-letter
  5. ::first-line
  6. ::selection
  7. ::slotted
Like it? Help me by telling your friends. Or, Put $5 at patreon.

Or, Buy JavaScript in Depth

CSS Basics

  1. Basics
  2. Tag Matching Tutorial
  3. Selector Syntax
  4. Units

Color

  1. Color Syntax
  2. Color Names
  3. Opacity
  4. Linear Gradient
  5. Radial Gradient

Font

  1. font-family
  2. Standard Web Fonts
  3. font-size
  4. Meaning of Font Size
  5. Font Weight
  6. Chinese Font Names

Box Model

  1. Border
  2. Outline
  3. Margin vs Padding
  4. Box Sizing

Layout

  1. Layout Tutorial
  2. Display Property
  3. Position: static, relative, fixed, absolute
  4. Pure CSS Table
  5. Tabbed Menu
  6. 3 Columns Page Layout
  7. Multi-Column Layout for Text Flow
  8. Fix Element to Window
  9. Centering
  10. Flowing List
  11. z-index
  12. Text Over Image
  13. Text Flow Around Image
  14. OverFlow, Scrollbar

Transform/Animation

  1. 2D Transform
  2. Transition
  3. Animation

Line Wrap, Justification

  1. Line Wrap
  2. Text Alignment, Justification
  3. Match first-letter and first-line
  4. “:before”, “:after”
  5. Text Decoration: Underline, Overline, Line-Through
  6. Letter Spacing, Word Spacing

Box Decoration

  1. Box Shadow
  2. Text Shadow
  3. Round Corners
  4. Background Image
  5. Image Rollover

Misc

  1. Computed Style
  2. Pseudo Class vs Pseudo Element
  3. Media Query
  4. Variable
  5. calc
  6. Reset
  7. user-select
  8. Data URI Scheme
  9. protocol-relative URL
  10. Default Unit
  11. Declaring Character Set in CSS File
  12. Jargons Explained: Tag, Element, Node, Object, Attribute, Property, Method
  13. Display Table on Small Screen
  14. Fixed Aspect Ratio
  15. Add Icon to Links
  16. Progress Bar Example

If you have a question, put $5 at patreon and message me.

Web Dev Tutorials

  1. HTML
  2. CSS
  3. JavaScript
  4. JS Obj Ref
  5. DOM
  6. SVG
  7. Blog