Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What does the Tailwind CSS class truncate do?
The <code>truncate</code> class makes text cut off with an ellipsis (...) when it is too long to fit in its container. It hides overflow and prevents wrapping.
Click to reveal answer
beginner
Which Tailwind CSS classes are needed to make text truncate with an ellipsis?
You need overflow-hidden to hide extra text, whitespace-nowrap to prevent wrapping, and truncate to add the ellipsis.
Click to reveal answer
beginner
How does overflow-hidden help with text truncation?
It hides any text that goes outside the container's width, so the extra text is not visible beyond the box edges.
Click to reveal answer
beginner
What is the role of whitespace-nowrap in truncating text?
It prevents the text from breaking into multiple lines, forcing it to stay on one line so truncation can happen.
Click to reveal answer
intermediate
Why is it important to set a fixed width or max-width when using text truncation?
Without a fixed width, the container can grow with the text, so truncation won't happen. Setting width limits the space so overflow triggers truncation.
Click to reveal answer
Which Tailwind class adds an ellipsis to overflowing text?
Awhitespace-normal
Boverflow-visible
Ctruncate
Dtext-ellipsis
✗ Incorrect
The truncate class adds an ellipsis (...) to text that overflows its container.
What does whitespace-nowrap do in Tailwind CSS?
APrevents text from wrapping to new lines
BAllows text to wrap to multiple lines
CAdds space between words
DMakes text bold
✗ Incorrect
whitespace-nowrap keeps text on one line by preventing wrapping.
Which combination of classes is needed to truncate text properly?
Aoverflow-visible, whitespace-normal, truncate
Boverflow-hidden, whitespace-nowrap, truncate
Coverflow-scroll, whitespace-nowrap, truncate
Doverflow-hidden, whitespace-normal, truncate
✗ Incorrect
You need overflow-hidden, whitespace-nowrap, and truncate together for proper truncation.
Why must the container have a fixed width for truncation to work?
ATo center the text
BTo allow text to wrap
CTo make text bold
DTo limit space so overflow triggers truncation
✗ Incorrect
A fixed width limits the container size, causing overflow and enabling truncation.
What happens if you omit overflow-hidden when truncating text?
AText will overflow visibly outside container
BText will be centered
CText will be bold
DText will wrap to next line
✗ Incorrect
Without overflow-hidden, extra text will spill outside the container instead of being hidden.
Explain how to use Tailwind CSS classes to truncate a long text string with an ellipsis.
Think about how to keep text on one line and hide extra text with dots.
You got /4 concepts.
Describe why setting a fixed width is important when truncating text in Tailwind CSS.
Consider what happens if the container can grow freely.
You got /4 concepts.
Practice
(1/5)
1. What does the Tailwind CSS class truncate do to text inside an element?
easy
A. It centers the text horizontally.
B. It cuts off overflowing text and adds an ellipsis (…) at the end.
C. It changes the text color to gray.
D. It makes the text bold and larger.
Solution
Step 1: Understand the purpose of truncate
The truncate class in Tailwind applies CSS rules to hide overflow text and show an ellipsis.
Step 2: Recognize the visual effect
This means long text that doesn't fit the container ends with dots (…) instead of wrapping or overflowing.
Final Answer:
It cuts off overflowing text and adds an ellipsis (…) at the end. -> Option B
Quick Check:
truncate = text cut off with dots [OK]
Hint: Remember: truncate means cut off with dots [OK]
Common Mistakes:
Thinking truncate changes text style like bold or color
Confusing truncate with text alignment classes
Assuming truncate wraps text instead of cutting it
2. Which Tailwind CSS class combination correctly truncates text inside a fixed-width box?
easy
A. truncate text-center
B. truncate max-w-full
C. overflow-visible truncate
D. truncate w-48
Solution
Step 1: Identify required classes for truncation
Truncation needs truncate plus a fixed width like w-48 to limit container size.
Step 2: Check each option
truncate w-48 uses truncate and a fixed width, so it works. Others either lack fixed width or have conflicting overflow.
Final Answer:
<code>truncate w-48</code> -> Option D
Quick Check:
truncate + fixed width = truncation works [OK]
Hint: Always add fixed width with truncate for effect [OK]
Common Mistakes:
Using truncate without fixed width or max-width
Setting overflow-visible which disables truncation
Confusing text alignment with truncation
3. Given this HTML snippet:
<div class="w-32 truncate">This is a very long text that should be cut off.</div>
What will the user see in the browser?
medium
A. "This is a very long text that shoul…" with an ellipsis at the end
B. "This is a very long text that should be cut off" wrapped on multiple lines
C. "This is a very long text that should be cut off." fully visible
D. An empty box with no text
Solution
Step 1: Analyze container width and truncate class
The container has fixed width w-32 and truncate which cuts off overflow text with ellipsis.
Step 2: Predict visible text
Text longer than container width is cut and ends with (…) showing partial text.
Final Answer:
"This is a very long text that shoul…" with an ellipsis at the end -> Option A
Quick Check:
Fixed width + truncate = partial text + dots [OK]
Hint: Fixed width + truncate = text ends with dots [OK]
Common Mistakes:
Expecting full text to show without wrapping
Thinking text wraps instead of truncates
Assuming empty box means truncation
4. You want to truncate text but it is not working. Which Tailwind class is likely missing or incorrect?
medium
A. Missing a fixed width or max-width class on the container
B. Using truncate without text-center
C. Adding overflow-visible to the container
D. Using font-bold on the text
Solution
Step 1: Understand truncation requirements
Truncation needs a fixed width or max-width to limit container size; otherwise text won't cut off.
Step 2: Identify common mistakes
Missing width means text expands fully. Options B, C, D do not affect truncation as directly.
Final Answer:
Missing a fixed width or max-width class on the container -> Option A
Quick Check:
Width needed for truncate to work [OK]
Hint: Check container width if truncate fails [OK]
Common Mistakes:
Forgetting to set container width or max-width
Adding overflow-visible which disables truncation
Confusing text alignment with truncation
5. You have a card with a title that might be very long. You want to truncate the title with an ellipsis but also ensure screen readers can read the full title. Which Tailwind and HTML approach is best?
hard
A. Wrap the title in a <marquee> tag with truncate
B. Use truncate and hide the full text with display:none
C. Use truncate on the title and add aria-label with full text on the same element
D. Use truncate and add a tooltip with the full text using title attribute
Solution
Step 1: Understand accessibility needs
Screen readers need full text, so use aria-label with full title on truncated element.
Step 2: Evaluate options for best practice
Use truncate on the title and add aria-label with full text on the same element uses truncate visually and aria-label for accessibility, which is correct. Use truncate and add a tooltip with the full text using title attribute is helpful but less reliable for screen readers.
Final Answer:
Use <code>truncate</code> on the title and add <code>aria-label</code> with full text on the same element -> Option C
Quick Check:
Truncate + aria-label = visible dots + accessible full text [OK]
Hint: Add aria-label with full text for accessibility [OK]
Common Mistakes:
Hiding full text with display:none removes it from screen readers