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.
0
0
Why display modes matter in Tailwind
Introduction
When you want to show items side by side or stacked.
When you need to hide or show parts of a page on different screen sizes.
When you want to create flexible layouts that adjust automatically.
When you want to center content horizontally or vertically.
When you want to switch between block and inline styles for text or images.
Syntax
Tailwind
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.
Examples
This element takes full width and starts on a new line.
Tailwind
<div class="block">Block element</div>This element flows with text and does not start a new line.
Tailwind
<span class="inline">Inline element</span>This container arranges its children in a flexible row or column.
Tailwind
<div class="flex">Flex container</div>This element is not visible on the page.
Tailwind
<div class="hidden">Hidden element</div>Sample Program
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.
Tailwind
<!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>
OutputSuccess
Important Notes
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.
Summary
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.