Bird
Raised Fist0
Tailwindmarkup~10 mins

Layer organization (base, components, utilities) in Tailwind - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add a base style for all paragraphs using Tailwind's @layer directive.

Tailwind
@layer [1] {
  p {
    @apply text-base text-gray-700;
  }
}
Drag options to blanks, or click blank then click option'
Abase
Bstyles
Cutilities
Dcomponents
Attempts:
3 left
💡 Hint
Common Mistakes
Using @layer components instead of base for default element styles
Using @layer utilities for element styles
2fill in blank
medium

Complete the code to create a custom button component style inside the correct Tailwind layer.

Tailwind
@layer [1] {
  .btn-primary {
    @apply bg-blue-600 text-white px-4 py-2 rounded;
  }
}
Drag options to blanks, or click blank then click option'
Acomponents
Bbase
Cutilities
Dthemes
Attempts:
3 left
💡 Hint
Common Mistakes
Putting component styles inside base layer
Using utilities layer for component classes
3fill in blank
hard

Fix the error in this utility class definition by choosing the correct layer.

Tailwind
@layer [1] {
  .text-shadow {
    text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
  }
}
Drag options to blanks, or click blank then click option'
Acomponents
Bbase
Cstyles
Dutilities
Attempts:
3 left
💡 Hint
Common Mistakes
Placing utility classes inside components or base layers
Using a non-existent layer name
4fill in blank
hard

Fill both blanks to define a custom component and a utility class in the correct layers.

Tailwind
@layer [1] {
  .card {
    @apply bg-white shadow-md rounded p-6;
  }
}

@layer [2] {
  .text-glow {
    text-shadow: 0 0 8px rgba(255,255,255,0.8);
  }
}
Drag options to blanks, or click blank then click option'
Acomponents
Bbase
Cutilities
Dstyles
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up layers for components and utilities
Using base layer for utility classes
5fill in blank
hard

Fill all three blanks to organize base styles, components, and utilities correctly.

Tailwind
@layer [1] {
  h1 {
    @apply text-4xl font-bold;
  }
}

@layer [2] {
  .btn-secondary {
    @apply bg-gray-300 text-gray-800 px-3 py-1 rounded;
  }
}

@layer [3] {
  .border-fancy {
    border-image: linear-gradient(to right, red, orange) 1;
  }
}
Drag options to blanks, or click blank then click option'
Abase
Bcomponents
Cutilities
Dstyles
Attempts:
3 left
💡 Hint
Common Mistakes
Putting base element styles in components or utilities
Confusing components and utilities layers

Practice

(1/5)
1. What is the main purpose of the base layer in Tailwind CSS?
easy
A. To add small helper classes for margin and padding
B. To create reusable UI components like buttons and cards
C. To set default styles for HTML elements like body and h1
D. To write JavaScript functions for styling

Solution

  1. Step 1: Understand the role of base layer

    The base layer sets default styles for basic HTML elements to ensure consistent look.
  2. Step 2: Differentiate from components and utilities

    Components are reusable UI parts, utilities are small helper classes, so they differ from base.
  3. Final Answer:

    To set default styles for HTML elements like body and h1 -> Option C
  4. Quick Check:

    Base layer = default element styles [OK]
Hint: Base layer styles HTML elements directly [OK]
Common Mistakes:
  • Confusing base with components
  • Thinking utilities set default HTML styles
  • Mixing JavaScript with CSS layers
2. Which of the following is the correct way to add a custom component style in Tailwind's layer system?
easy
A. @layer components { .card { @apply shadow-lg p-6; } }
B. @layer utilities { .btn { @apply px-4 py-2; } }
C. @layer base { h1 { font-weight: bold; } }
D. @layer utilities { body { margin: 0; } }

Solution

  1. Step 1: Identify the correct layer for components

    Custom reusable UI parts like cards belong in the components layer.
  2. Step 2: Check syntax correctness

    @layer components { .card { @apply shadow-lg p-6; } } uses @layer components with a class and @apply, which is correct.
  3. Final Answer:

    @layer components { .card { @apply shadow-lg p-6; } } -> Option A
  4. Quick Check:

    Components layer = reusable UI styles [OK]
Hint: Put reusable UI styles in components layer [OK]
Common Mistakes:
  • Putting components styles in utilities or base
  • Using element selectors in utilities layer
  • Incorrect @layer usage
3. Given this Tailwind CSS snippet, what will be the color of the 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>
medium
A. Red
B. Green
C. Blue
D. Black (default)

Solution

  1. Step 1: Understand CSS layer priority in Tailwind

    Utilities have the highest priority, then components, then base.
  2. Step 2: Check applied classes and their colors

    The h2 has classes title (red, components) and text-green (green, utilities). Utilities override components.
  3. Final Answer:

    Green -> Option B
  4. Quick Check:

    Utilities override components and base [OK]
Hint: Utilities override components and base styles [OK]
Common Mistakes:
  • Thinking base styles override utilities
  • Ignoring class order and layer priority
  • Assuming first declared style wins
4. You wrote this Tailwind CSS code but the .btn styles are not applied:
@layer utilities {
  .btn { @apply px-4 py-2 bg-blue-500; }
}

What is the most likely reason?
medium
A. Custom styles for buttons should be in the components layer, not utilities
B. You must use @layer base for all custom classes
C. The @apply directive cannot be used inside @layer
D. You forgot to add !important to the styles

Solution

  1. Step 1: Identify correct layer for button styles

    Buttons are reusable UI components, so they belong in the components layer.
  2. Step 2: Understand layer purpose

    Utilities are for small helper classes, not full component styles.
  3. Final Answer:

    Custom styles for buttons should be in the components layer, not utilities -> Option A
  4. Quick Check:

    Components layer = reusable UI parts [OK]
Hint: Put button styles in components, not utilities [OK]
Common Mistakes:
  • Putting components styles in utilities layer
  • Misusing @apply directive
  • Forgetting layer purpose
5. You want to create a custom utility class .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);
  }
}
hard
A. In base because it sets default text styles
B. In components because it is a reusable UI part
C. Directly in HTML style attribute, not in any layer
D. In utilities because it is a small helper class

Solution

  1. Step 1: Classify the style type

    The .text-shadow class is a small helper that adds a single CSS property.
  2. Step 2: Match style type to layer

    Small helper classes belong in the utilities layer, not base or components.
  3. Final Answer:

    In utilities because it is a small helper class -> Option D
  4. Quick Check:

    Utilities layer = small helper classes [OK]
Hint: Small helper classes go in utilities layer [OK]
Common Mistakes:
  • Putting small helpers in components or base
  • Confusing reusable UI parts with utilities
  • Using inline styles instead of layers
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard