Questions
4 of 45
1What is a pseudo-element in CSS?
2How are pseudo-elements different from pseudo-classes?
3What is the syntax of a pseudo-element?
4Name some commonly used pseudo-elements.
5What does the ::before pseudo-element do? What does the ::after pseudo-element do?
6How can you insert content using pseudo-elements?
7What is the difference between :before and ::before? Why were pseudo-elements changed from one colon (:) to two (::) in CSS3?
8What does the ::first-letter pseudo-element do?
9What does the ::first-line pseudo-element do?
10How can you style the first line of a paragraph differently?
11Can pseudo-elements be styled with animations or transitions?
12What’s the difference between using ::before and ::after?
13Can pseudo-elements be positioned using CSS positioning properties? Can pseudo-elements have background images or colors? How can you use pseudo-elements to create shapes or icons?
14Can you use multiple pseudo-elements on the same element?
15What is the ::selection pseudo-element used for?
16How does stacking and z-index affect pseudo-elements?
17Can pseudo-elements have child elements or content inside them?
18Can you apply pseudo-elements to replaced elements (like <img>)?
19How do pseudo-elements interact with display and overflow properties?
20What’s the difference between using pseudo-elements and real elements for decoration?
21How does inheritance work with pseudo-elements?
22Can pseudo-elements trigger JavaScript events (like click)?
23How can you control the generated content with pseudo-elements using attr()?
24Can pseudo-elements be used inside flex or grid layouts?
25How do you control the stacking order of ::before and ::after pseudo-elements?
26How can you create a tooltip using pseudo-elements?
27How can you make a custom underline or highlight effect using ::after?
28How can you make a quotation mark appear before a paragraph using pseudo-elements?
29How do you create a triangle or arrow shape using only CSS pseudo-elements?
30How can you use pseudo-elements to add icons without extra markup?
31How can you create a button hover animation using ::before or ::after?
32How can pseudo-elements help in implementing skeleton loaders or shimmer effects?
33How can you use ::before and ::after to clear floats?
34How can you create a border animation using pseudo-elements?
35How can pseudo-elements be used in responsive design?
36What is the ::marker pseudo-element and when is it used?
37What does the ::placeholder pseudo-element do?
38How does ::cue work with media elements?
39What is ::backdrop, and where is it used?
40What is the difference between ::file-selector-button and other input pseudo-elements?
41How does the ::part() pseudo-element work in Web Components?
42How is ::slotted() different from ::part() in shadow DOM styling?
43Can you style text highlights with pseudo-elements?
44How can ::selection be customized for accessibility and branding?
45What are the limitations of pseudo-elements compared to actual DOM elements?
04 / 45

Name some commonly used pseudo-elements.

Commonly Used Pseudo-Elements in CSS

Pseudo-elements allow you to style specific parts of an element or insert content without modifying the HTML. Some pseudo-elements are widely used for text formatting and decorative purposes.

Common Pseudo-Elements
  1. 1

    ::before - Inserts content before an element's content.

  2. 2

    ::after - Inserts content after an element's content.

  3. 3

    ::first-letter - Styles the first letter of a block-level element.

  4. 4

    ::first-line - Styles the first line of a block-level element.

  5. 5

    ::selection - Styles the portion of text selected by the user.

  6. 6

    ::placeholder - Styles the placeholder text of input elements.

  7. 7

    ::marker - Styles the marker of list items (li).

Example: Using Multiple Pseudo-Elements

In this example, ::first-letter styles the first letter, ::before and ::after add decorative content, ::placeholder styles the input placeholder, and ::selection changes the appearance of selected text.

Best Practices
  1. 1

    Use pseudo-elements for decorative or structural styling without extra HTML.

  2. 2

    Combine them with CSS properties like content, color, font-size, and background.

  3. 3

    Test across browsers to ensure consistent behavior.

  4. 4

    Avoid using pseudo-elements for interactive content that requires JavaScript functionality.

Difficulty: 3/10
Topics: ::before, ::after, ::first-line

Scenario Questions

0-2 years experience
  1. 1

    How would you add a star icon before every review rating using CSS without changing the HTML?

  2. 2

    What happens if you try to style ::content or ::text — why won’t it work?

  3. 3

    You’re trying to add a tooltip arrow using ::after, but it’s not showing up — what’s the most likely missing CSS rule?

2-5 years experience
  1. 1

    A designer wants a decorative border around a quote block using ::before and ::after, but it’s breaking on mobile — how would you debug this?

  2. 2

    Your team’s CSS library uses ::before for icons, but now accessibility testers say screen readers are reading the content — how do you fix that without removing the visual effect?

  3. 3

    A button’s ::after hover effect works in Chrome but not Safari — what’s your debugging process?

5-8 years experience
  1. 1

    You’re building a scalable component library where pseudo-elements are used for state indicators — how do you ensure they don’t conflict with user-defined content or break in shadow DOM?

  2. 2

    A legacy component uses ::before to inject loading spinners via CSS content — but now we’re migrating to a framework that dynamically renders content. How do you refactor this without breaking existing styles?

  3. 3

    How would you optimize a UI with dozens of elements using ::before/::after for icons, and what performance tradeoffs should you consider in a high-traffic app?

8+ years experience
  1. 1

    Your company’s design system relies heavily on pseudo-elements for visual states across 50+ components — how do you architect a migration to CSS custom properties or a modern alternative without breaking thousands of downstream usages?

  2. 2

    Pseudo-elements are used for accessibility-enhanced tooltips in a legacy enterprise app, but they’re causing reflow issues on low-end devices. How do you propose a long-term architectural shift while maintaining backward compatibility?

  3. 3

    How would you evaluate whether to deprecate pseudo-element-based UI patterns in favor of SVG or web components in a large codebase with multiple teams and no centralized style governance?

Follow-up Questions

  • What happens if you forget to set the content property on ::before?
  • Can you style ::first-letter differently from ::first-line?
  • Why might a pseudo-element not render even when the CSS looks correct?