Bird
Raised Fist0
Tailwindmarkup~10 mins

Scroll-snap containers 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 make the container snap horizontally.

Tailwind
<div class="overflow-x-auto [1]">
  <div class="flex">
    <div class="w-64 h-40 bg-blue-500 flex-shrink-0">Item 1</div>
    <div class="w-64 h-40 bg-green-500 flex-shrink-0">Item 2</div>
    <div class="w-64 h-40 bg-red-500 flex-shrink-0">Item 3</div>
  </div>
</div>
Drag options to blanks, or click blank then click option'
Asnap-x
Bsnap-y
Csnap-none
Dsnap-mandatory
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'snap-y' which is for vertical snapping.
Using 'snap-none' which disables snapping.
Using 'snap-mandatory' which is not a valid Tailwind class.
2fill in blank
medium

Complete the code to make each item snap to the start of the container.

Tailwind
<div class="overflow-x-auto snap-x">
  <div class="flex">
    <div class="w-64 h-40 bg-blue-500 flex-shrink-0 [1]">Item 1</div>
    <div class="w-64 h-40 bg-green-500 flex-shrink-0 [1]">Item 2</div>
    <div class="w-64 h-40 bg-red-500 flex-shrink-0 [1]">Item 3</div>
  </div>
</div>
Drag options to blanks, or click blank then click option'
Asnap-center
Bsnap-start
Csnap-end
Dsnap-align
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'snap-center' which centers the snap position.
Using 'snap-end' which snaps to the end edge.
Using 'snap-align' which is not a Tailwind class.
3fill in blank
hard

Fix the error in the code to enable mandatory snapping behavior.

Tailwind
<div class="overflow-x-auto snap-x [1]">
  <div class="flex">
    <div class="w-64 h-40 bg-blue-500 flex-shrink-0 snap-start">Item 1</div>
    <div class="w-64 h-40 bg-green-500 flex-shrink-0 snap-start">Item 2</div>
    <div class="w-64 h-40 bg-red-500 flex-shrink-0 snap-start">Item 3</div>
  </div>
</div>
Drag options to blanks, or click blank then click option'
Asnap-mandatory
Bsnap-strict
C[--tw-scroll-snap-strictness:mandatory]
Dsnap-required
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'snap-mandatory' which is not a Tailwind class.
Using 'snap-strict' which does not exist.
Using 'snap-required' which is invalid.
4fill in blank
hard

Fill both blanks to create a vertical scroll snap container with items snapping to center.

Tailwind
<div class="overflow-y-auto [1] [2] h-64">
  <div class="flex flex-col">
    <div class="h-40 bg-purple-500 snap-center">Item A</div>
    <div class="h-40 bg-pink-500 snap-center">Item B</div>
    <div class="h-40 bg-yellow-500 snap-center">Item C</div>
  </div>
</div>
Drag options to blanks, or click blank then click option'
Asnap-y
Bsnap-x
C[--tw-scroll-snap-strictness:mandatory]
Dsnap-center
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'snap-x' instead of 'snap-y' for vertical scrolling.
Using 'snap-center' on the container instead of items.
Omitting the snapping behavior class.
5fill in blank
hard

Fill all three blanks to create a horizontal scroll snap container with items snapping to end and mandatory snapping enabled.

Tailwind
<div class="overflow-x-auto [1] [2] h-48">
  <div class="flex">
    <div class="w-48 bg-teal-500 flex-shrink-0 [3]">Box 1</div>
    <div class="w-48 bg-orange-500 flex-shrink-0 [3]">Box 2</div>
    <div class="w-48 bg-indigo-500 flex-shrink-0 [3]">Box 3</div>
  </div>
</div>
Drag options to blanks, or click blank then click option'
Asnap-x
B[--tw-scroll-snap-strictness:mandatory]
Csnap-end
Dsnap-start
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'snap-y' instead of 'snap-x' for horizontal snapping.
Using 'snap-start' on items instead of 'snap-end'.
Omitting the mandatory snapping class.

Practice

(1/5)
1. What does the Tailwind class snap-x do in a scroll container?
easy
A. It enables horizontal scroll snapping inside the container.
B. It enables vertical scroll snapping inside the container.
C. It disables scroll snapping inside the container.
D. It sets the scroll snapping to mandatory on all sides.

Solution

  1. Step 1: Understand the snap-x class

    The snap-x class in Tailwind sets scroll-snap-type: x mandatory; which means horizontal snapping.
  2. Step 2: Compare with other options

    Vertical snapping uses snap-y, disabling snapping uses snap-none, and mandatory snapping on all sides is not a valid Tailwind class.
  3. Final Answer:

    It enables horizontal scroll snapping inside the container. -> Option A
  4. Quick Check:

    snap-x = horizontal scroll snap [OK]
Hint: Remember x means horizontal, y means vertical scroll snap [OK]
Common Mistakes:
  • Confusing snap-x with vertical snapping
  • Thinking snap-x disables snapping
  • Assuming snap-x applies to all directions
2. Which Tailwind class correctly applies scroll snapping alignment to a child element to start at the container's snap point?
easy
A. snap-end
B. snap-center
C. snap-start
D. snap-none

Solution

  1. Step 1: Identify scroll snap alignment classes

    Tailwind uses snap-start, snap-center, and snap-end to align child elements at the start, center, or end of the snap point.
  2. Step 2: Match the requirement

    The question asks for alignment at the container's snap point start, so snap-start is correct.
  3. Final Answer:

    snap-start -> Option C
  4. Quick Check:

    snap-start = align at snap point start [OK]
Hint: snap-start aligns child at container's snap start [OK]
Common Mistakes:
  • Choosing snap-center instead of snap-start
  • Using snap-none which disables snapping
  • Confusing snap-end with snap-start
3. Given this HTML snippet with Tailwind classes:
<div class="overflow-x-auto snap-x">
  <div class="snap-center w-64 h-40 bg-blue-400">Item 1</div>
  <div class="snap-center w-64 h-40 bg-green-400">Item 2</div>
  <div class="snap-center w-64 h-40 bg-red-400">Item 3</div>
</div>
What will happen when you scroll horizontally inside the container?
medium
A. Scrolling will not snap; it scrolls freely.
B. Scrolling will snap horizontally to center each item smoothly.
C. Scrolling will snap vertically to center each item.
D. Scrolling will snap horizontally but align items to start.

Solution

  1. Step 1: Analyze container classes

    The container has overflow-x-auto (horizontal scroll), snap-x (horizontal mandatory snap).
  2. Step 2: Analyze child classes

    Each child has snap-center, so snapping aligns each item centered in the viewport.
  3. Final Answer:

    Scrolling will snap horizontally to center each item smoothly. -> Option B
  4. Quick Check:

    snap-x + snap-center = horizontal center snap [OK]
Hint: snap-x + snap-center means horizontal center snapping [OK]
Common Mistakes:
  • Thinking snap-x snaps vertically
  • Ignoring snap-mandatory effect
  • Assuming snap-start alignment instead of center
4. You wrote this Tailwind code but scroll snapping does not work:
<div class="overflow-y-auto snap-x">
  <div class="snap-start h-40 bg-yellow-300">Item A</div>
  <div class="snap-start h-40 bg-yellow-500">Item B</div>
</div>
What is the main issue preventing scroll snapping?
medium
A. Missing width on child elements.
B. Not setting scroll-padding on the container.
C. Using snap-start instead of snap-center.
D. Using snap-x with vertical scrolling (overflow-y-auto).

Solution

  1. Step 1: Check scroll direction and snap type

    The container scrolls vertically (overflow-y-auto) but uses snap-x which is for horizontal snapping.
  2. Step 2: Understand snapping mismatch

    Scroll snapping only works if the snap axis matches the scroll direction. Here, vertical scroll with horizontal snap causes no snapping.
  3. Final Answer:

    Using snap-x with vertical scrolling (overflow-y-auto). -> Option D
  4. Quick Check:

    Scroll axis must match snap axis [OK]
Hint: Match scroll direction with snap-x or snap-y [OK]
Common Mistakes:
  • Mixing horizontal snap with vertical scroll
  • Ignoring child element sizing
  • Thinking snap-start vs snap-center affects snapping presence
5. You want a vertical scroll container that snaps to each child element's start. Which Tailwind classes should you use on the container and children?
hard
A. Container: overflow-y-auto snap-y snap-mandatory, Children: snap-start
B. Container: overflow-y-auto snap-x snap-mandatory, Children: snap-center
C. Container: overflow-x-auto snap-y snap-proximity, Children: snap-end
D. Container: overflow-y-auto snap-y, Children: snap-start

Solution

  1. Step 1: Identify scroll direction and snapping type

    Vertical scroll requires overflow-y-auto and vertical snap with snap-y.
  2. Step 2: Choose snapping behavior

    Tailwind uses mandatory snapping, so snap-y snap-mandatory is correct.
  3. Step 3: Set child alignment

    Children aligned at the start use snap-start.
  4. Final Answer:

    Container: overflow-y-auto snap-y snap-mandatory, Children: snap-start -> Option A
  5. Quick Check:

    Vertical + start alignment = Container: overflow-y-auto snap-y snap-mandatory, Children: snap-start [OK]
Hint: snap-y enables vertical snapping to snap points [OK]
Common Mistakes:
  • Using snap-x with vertical scroll
  • Confusing snap-mandatory with snap-proximity
  • Misaligning children with snap-center instead of snap-start
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