Performance: Layer organization (base, components, utilities)
This affects how quickly styles are applied and how efficiently the browser processes CSS during page load and rendering.
@layer base { body { margin: 0; } } @layer components { .card { @apply shadow-lg p-6; } .btn { @apply px-4 py-2 bg-blue-500; } } @layer utilities { .text-shadow { text-shadow: 1px 1px 2px black; } }@layer utilities { .btn { @apply px-4 py-2 bg-blue-500; } } @layer base { body { margin: 0; } } @layer components { .card { @apply shadow-lg p-6; } }| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Mixed layer order | N/A | Multiple style recalculations | Higher paint cost due to unstable styles | [X] Bad |
| Ordered layers: base, components, utilities | N/A | Single style recalculation | Lower paint cost with stable styles | [OK] Good |
base layer in Tailwind CSS?body and h1 -> Option Ccomponents layer.@layer components with a class and @apply, which is correct.h2 element?@layer base {
h2 { color: blue; }
}
@layer components {
.title { color: red; }
}
@layer utilities {
.text-green { color: green; }
}<h2 class='title text-green'>Hello</h2>h2 has classes title (red, components) and text-green (green, utilities). Utilities override components..btn styles are not applied:@layer utilities {
.btn { @apply px-4 py-2 bg-blue-500; }
}components layer.components layer, not utilities -> Option A.text-shadow that adds a subtle shadow to text. Where should you place this style in Tailwind's layer system and why?@layer ??? {
.text-shadow {
text-shadow: 1px 1px 2px rgba(0,0,0,0.3);
}
}.text-shadow class is a small helper that adds a single CSS property.utilities layer, not base or components.utilities because it is a small helper class -> Option DPass the test and this pattern moves unknown