What deep selector pierces Vue scoped styles, and why use it cautiously?
This tests Vue scoped CSS encapsulation. Use :deep() to target child internals from a scoped block, but it breaks encapsulation and creates brittle coupling. A red flag is recommending deprecated /deep/ or unscoped global styles.
WHAT THIS TESTS: This question probes whether you understand Vue single-file component scoped style encapsulation and know the modern, supported escape hatch for piercing that boundary. It also checks if you appreciate the architectural trade-off between convenience and component isolation.
A GOOD ANSWER COVERS: First, name the :deep() pseudo-class as the current Vue 3 convention for reaching into child components from a scoped style block. Second, explain the compilation mechanics: Vue uses PostCSS to add a scoped attribute selector like data-v-f3f3eg9 to the ancestor in the rule, so .a :deep(.b) becomes .a[data-v-f3f3eg9] .b, which lets the descendant selector match elements inside a child component without leaking the attribute onto the child itself. Third, articulate the caution: every use of :deep() creates an implicit contract between parent and child markup, so if the child refactors its internal class names or DOM structure, the parent style breaks. Fourth, mention that it should be reserved for layout or theme overrides, not as a default styling strategy, and note that Vue also provides :slotted() for slot content and :global() for truly global rules.
COMMON WRONG ANSWERS: A major red flag is citing /deep/ or >>> as the primary answer without noting they are deprecated or loader-dependent. Another is suggesting an unscoped style tag as the fix, which abandons encapsulation entirely and risks global collisions. Some candidates propose !important or inline styles, which miss the point of the question and reveal a lack of familiarity with Vue's SFC toolchain. Finally, confusing :deep() with v-deep, the old Vue 2 directive-like syntax, shows outdated knowledge.
LIKELY FOLLOW-UPS: An interviewer might ask how :deep() differs from :slotted() or :global(), or when CSS Modules would be a better choice than scoped styles with deep selectors. They may also ask about performance implications of attribute selectors, since scoped styles rely on them and descendant selectors in recursive components can match more nodes than intended.
ONE CONCRETE EXAMPLE: Imagine a parent PageLayout component with scoped styles that needs to adjust the padding inside a reusable Sidebar child. Instead of adding a prop for every spacing variant, the parent writes .page-layout :deep(.sidebar-inner) { padding: 2rem; }. This works because the scoped attribute is attached only to .page-layout, allowing the rule to reach .sidebar-inner inside the child. However, if Sidebar later renames .sidebar-inner to .sidebar-body, the layout silently breaks, illustrating why :deep() should be used sparingly and documented clearly.
Read the original → vuejs.org
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.