Display modes control how elements appear and behave on a webpage. They help organize content so it looks good and works well on all devices.
Why display modes matter in Tailwind
Start learning this pattern below
Jump into concepts and practice - no test required
class="block" class="inline" class="inline-block" class="flex" class="grid" class="hidden"
Use these classes on HTML elements to change how they display.
Tailwind makes it easy to switch display modes with simple class names.
<div class="block">Block element</div><span class="inline">Inline element</span><div class="flex">Flex container</div><div class="hidden">Hidden element</div>This page shows different display modes using Tailwind classes. You see block, inline, flex, and hidden elements with colors to help you notice their behavior.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Display Modes Example</title> <script src="https://cdn.tailwindcss.com"></script> </head> <body class="p-6"> <h1 class="text-xl font-bold mb-4">Display Modes Matter</h1> <div class="block bg-blue-200 p-2 mb-2">Block: full width, new line</div> <span class="inline bg-green-200 p-2">Inline: flows with text</span> <span class="inline bg-green-300 p-2">Another inline</span> <div class="flex bg-yellow-200 p-2 mt-4"> <div class="bg-yellow-400 p-2 mr-2">Flex item 1</div> <div class="bg-yellow-500 p-2">Flex item 2</div> </div> <div class="hidden bg-red-200 p-2 mt-4">You cannot see me!</div> </body> </html>
Remember that block elements take full width and start on a new line.
inline elements flow with text and do not break lines.
flex helps arrange items easily in rows or columns.
Display modes control how elements appear and arrange on the page.
Tailwind classes like block, inline, flex, and hidden make it easy to change display.
Using the right display mode helps your page look good and work well on all devices.
Practice
Solution
Step 1: Understand block display behavior
A block element takes the full width available and starts on a new line.Step 2: Match Tailwind class to behavior
Theblockclass in Tailwind applies this block display mode.Final Answer:
<code>block</code> -> Option AQuick Check:
Block display =blockclass [OK]
block class for full width [OK]- Confusing
inlinewith block display - Thinking
flexis block by default - Assuming
hiddenshows the element
Solution
Step 1: Identify the class that hides elements
Thehiddenclass in Tailwind setsdisplay: none;, hiding the element.Step 2: Confirm other classes show elements
visibleis not a Tailwind display class,blockandflexshow elements.Final Answer:
<code>hidden</code> -> Option AQuick Check:
Hide element =hiddenclass [OK]
hidden to hide elements in Tailwind [OK]- Using
visiblewhich is not a Tailwind display class - Confusing
blockorflexas hiding classes - Trying to hide with opacity or visibility classes only
inline flex?Solution
Step 1: Understand Tailwind display class precedence
Tailwind applies the last display class in the list, soflexoverridesinline.Step 2: Check combined classes effect
However, if both are applied, the element behaves as a flex container, but ifinlineis applied first andflexsecond, it becomes a flex container with block behavior.Step 3: Clarify the question's class order
Since classes areinline flex,flexoverridesinline, so element behaves as flex container (block-level).Final Answer:
The element behaves as a flex container and takes full width. -> Option BQuick Check:
Last display class wins = flex container [OK]
- Thinking multiple display classes combine effects
- Assuming
inlineandflexcan coexist - Ignoring class order importance
block and children stack vertically. What is the mistake?Solution
Step 1: Understand display modes for layout
blockmakes container stack children vertically by default.Step 2: Use
To arrange children horizontally, container must haveflexfor horizontal layoutflexdisplay.Final Answer:
Usingblockinstead offlexon the container -> Option DQuick Check:
Horizontal layout needsflexcontainer [OK]
flex on container for horizontal layout [OK]- Applying
flexto children instead of container - Thinking
inlinearranges children horizontally - Not understanding
blockstacks vertically
Solution
Step 1: Make button inline with text
Theinline-flexclass makes the button flow inline with text.Step 2: Apply flex layout inside button
Theinline-flexclass makes the button a flex container for its children.Step 3: Center icon and label vertically
items-centeraligns children vertically center inside flex container.Final Answer:
<code>inline-flex items-center</code> -> Option CQuick Check:
Inline + flex + center items =inline-flex items-center[OK]
inline-flex items-center for inline flex centering [OK]- Using
blockmakes button block-level, breaking inline flow - Wrong order or missing
items-centerfor vertical alignment - Using
justify-betweeninstead of centering
