CSS
How to Align Text and Icon on the Same Line with Tailwind CSS
Aligning text and icons on the same line is a common UI pattern—used in buttons, headers, navigation links, and feature lists. With Tailwind CSS, you can easily achieve this with utility classes that control layout, spacing, and alignment.
In this guide, you’ll learn how to:
- Place icons and text side-by-side
- Vertically align them
- Add spacing between them
- Keep them responsive and clean
✅ Basic Alignment Using Flexbox
Flexbox is the go-to solution for aligning inline elements like icons and text.
📌 Example:
<div class="flex items-center space-x-2">
<svg class="w-5 h-5 text-blue-500" fill="currentColor" viewBox="0 0 20 20">
<path d="..." />
</svg>
<span class="text-gray-700">Download</span>
</div>
🔍 Explanation:
flex
: Arranges icon and text in a rowitems-center
: Vertically aligns icon and textspace-x-2
: Adds horizontal spacing between themw-5 h-5
: Sets icon sizetext-blue-500
: Colors the icon
✅ Perfect for buttons, links, tooltips, and navigation.
🎯 Example Use Case: Button with Icon
<button class="flex items-center space-x-2 bg-blue-600 text-white px-4 py-2 rounded">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path d="..." />
</svg>
<span>Submit</span>
</button>
💡 Wrap text and icon in a
flex
container and usespace-x-*
to control spacing.
🪄 Alternative: Using inline-flex
for Inline Elements
If you want the icon-text pair to behave like a single inline element (e.g., inside a paragraph or list), use inline-flex
.
📌 Example:
<p>
Click here
<span class="inline-flex items-center space-x-1 text-blue-600 underline ml-1">
<span>Learn more</span>
<svg class="w-4 h-4" fill="currentColor" viewBox="0 0 20 20">
<path d="..." />
</svg>
</span>
</p>
✅ Best for links or inline messages with icons.
🔁 Flip Order (Icon After Text)
Simply reverse the HTML order or use flex-row-reverse
.
<div class="flex items-center space-x-reverse space-x-2 flex-row-reverse">
<svg class="w-5 h-5" ...></svg>
<span>Next</span>
</div>
🔍 Tailwind Tips for Text + Icon Alignment
Goal | Tailwind Utility |
---|---|
Align vertically | items-center |
Arrange horizontally | flex or inline-flex |
Add spacing | space-x-* |
Control icon size | w-4 h-4 (or any size) |
Change order (icon after) | flex-row-reverse or reorder HTML |
Inline layout inside text | inline-flex |
📝 Conclusion
Tailwind CSS makes it effortless to align text and icons on the same line, vertically and horizontally. Whether you’re building buttons, headers, or lists, flex utilities offer clean, reusable layout solutions that adapt beautifully across screen sizes.