To display an image (<img>) and a span (<span>) element in a single line within a Bootstrap table cell, you can use Bootstrap's flex utilities or inline display properties. Here are the best approaches:
Method 1: Using d-flex (Flexbox)
Wrap the image and span in a div with d-flex to align them horizontally.
<table class="table">
<tbody>
<tr>
<td>
<div class="d-flex align-items-center">
<img src="your-image.jpg" alt="Image" class="me-2" style="width: 30px; height: 30px;">
<span>Your text here</span>
</div>
</td>
</tr>
</tbody>
</table>
d-flex → Makes the container a flexbox.
align-items-center → Vertically centers the image and text.
me-2 → Adds margin to the right of the image (Bootstrap spacing utility).
Method 2: Using d-inline-block (Inline Block)
If you prefer not to use flexbox, you can make both elements inline-block:
<table class="table">
<tbody>
<tr>
<td>
<img src="your-image.jpg" alt="Image" class="d-inline-block me-2" style="width: 30px; height: 30px;">
<span class="d-inline-block">Your text here</span>
</td>
</tr>
</tbody>
</table>
d-inline-block → Makes both elements stay in the same line.
me-2 → Adds spacing between the image and text.
Method 3: Using text-nowrap (Prevent Line Breaks)
If you want to ensure the content never wraps to a new line:
<table class="table">
<tbody>
<tr>
<td class="text-nowrap">
<img src="your-image.jpg" alt="Image" class="me-2" style="width: 30px; height: 30px;">
<span>Your text here</span>
</td>
</tr>
</tbody>
</table>
text-nowrap → Prevents text from wrapping to a new line.
Best Practice
- Use
d-flex for better alignment control (recommended).
- Use
d-inline-block if you need a simpler approach.
- Use
text-nowrap if you want to prevent line breaks entirely.
Would you like any additional styling adjustments? 😊