Questions
35 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?
35 / 45

How can pseudo-elements be used in responsive design?

Using Pseudo-Elements Responsively in CSS

Pseudo-elements like ::before and ::after can be used to add decorative or functional elements without extra HTML. By combining them with relative units and media queries, you can adjust their size, position, and visibility across different screen sizes.

Key Points
  1. 1

    Pseudo-elements can add visual cues or highlights that adapt to screen size.

  2. 2

    Use relative units like %, em, or rem for width, height, and positioning to maintain responsiveness.

  3. 3

    Media queries can modify pseudo-element styles such as size, position, or visibility at different breakpoints.

  4. 4

    Combine with CSS positioning to ensure pseudo-elements align correctly in responsive layouts.

Example: Responsive Decorative Dot with ::after

In this example, a small red dot is added to the .box using ::after. When the screen width is 600px or less, the dot becomes smaller and is repositioned, showing how pseudo-elements can respond to different screen sizes.

Best Practices
  1. 1

    Use relative units to allow pseudo-elements to scale with their parent.

  2. 2

    Use media queries to adjust or hide pseudo-elements for smaller screens.

  3. 3

    Test across devices to ensure pseudo-elements do not disrupt layout.

  4. 4

    Avoid using pseudo-elements for essential content; they should enhance design visually.

Difficulty: 6/10
Topics: pseudo-element positioning, responsive pseudo-content, CSS performance with pseudo-elements

Scenario Questions

0-2 years experience
  1. 1

    How would you use ::before to add a decorative icon next to a link that should hide on screens under 480px?

  2. 2

    What happens if you set content: '•' on a ::after pseudo-element but forget to set display: inline-block on it in a responsive grid?

2-5 years experience
  1. 1

    A tooltip built with ::before and ::after breaks when the page is zoomed to 150% — what’s likely going wrong, and how would you fix it?

  2. 2

    Your team’s button component uses pseudo-elements for hover effects, but QA reports inconsistent rendering on Safari — what would you check first?

5-8 years experience
  1. 1

    You’re optimizing a high-traffic landing page and notice layout thrashing during resize — how would you evaluate whether pseudo-elements are contributing, and what alternatives would you consider?

  2. 2

    How would you design a scalable system for responsive callout banners using pseudo-elements across 20+ components without creating CSS bloat or maintenance nightmares?

8+ years experience
  1. 1

    Your company is migrating from a legacy CSS framework that heavily relied on pseudo-elements for layout — how would you approach deprecating them without breaking existing UIs or introducing accessibility regressions?

  2. 2

    You’re designing a design system for a global product with 12 languages and RTL support — how do pseudo-elements complicate localization and bidirectional text, and what architectural decisions would you make to future-proof it?

Follow-up Questions

  • How would you debug a pseudo-element that disappears on mobile but works on desktop?
  • What accessibility concerns arise when using pseudo-elements for critical UI cues?
  • When would you avoid using pseudo-elements even if the design seems to call for them?