How to add image inside table cell in HTML
In this article, you will look at how to add images inside a table cell in HTML.
Use the <img> tag to add an Image inside the <td> element in HTML.
Add image inside table cell
Name
Location
Photo
Apu Gorai
India
Try it Yourself »
- Create a table using the <table> tag and give it a border of 4 px using the border attribute so that the table will visible to us.
<table border="4"> </table>
- Then , inside the table element, create two rows using the <tr> tag. The first <tr> for the table header <th> and the second <tr> for the table data <td>.
<table border="4"> <tr></tr> <tr></tr> </table>
- Inside the first row <tr> , create three <th> elements. The first one is for the name, second is for the location and the last one is for the image.
<table border="4"> <tr> <th>Name</th> <th>Location</th> <th>Image</th> </tr> <tr></tr> </table>
- Next, inside the second row <tr>, create three <td> elements. Then specify the Name as Apu Gorai, Location as India and inside the last <td> element, create a <img> tag to add an image inside this cell.
<table border="4"> <tr> <th>Name</th> <th>Location</th> <th>Photo</th> </tr> <tr> <td>Apu Gorai</td> <td>India</td> <td><img src="https://app.3schools.in/logo.png" height="100" width="100"></td> </tr> </table>
A <td> tag defines each cell in a table. Any data inside the <td> </td> are the content of a table cell. - Give a height using the height attribute and also a width using the width attribute to the image.
Click on the Try it Yourself » button to see the output of the code.
All code together
<table border="4">
<tr>
<th>Name</th>
<th>Location</th>
<th>Photo</th>
</tr>
<tr>
<td>Apu Gorai</td>
<td>India</td>
<td><img src="https://app.3schools.in/logo.png" height="100" width="100"></td>
</tr>
</table>
Try it Yourself »
In below example, you can find a responsive HTML table and inside the table cell, there is an image. Click on the Try it Yourself » button to look at the table.
Conclusion
In this article, you have learned how to add an image inside a table cell in HTML. We may use an online table generator to create a table dynamically.
save
listen
AI Answer
How to add image inside table cell in HTML
7
In this article, you will look at how to add images inside a table cell in HTML. Use the &…
asked
Apu
7 answers
2915
In this article, you will look at how to add images inside a table cell in HTML. Use the &…
Answer Link
answered
Apu
.table td{
border:1px solid black;
}
</style>
<div class="container">
<table class="table" style="width:100%;height: 100%">
<tr>
<td style="width: 35%">
<img src="https://app.3schools.in/img/bg.png" style="height: 100%;width: 100%"/>
</td>
<td>Everyone</td>
</tr>
</table>
</div>
Sometimes the image is not visible in html page when you want to display from a folder 📂. How to solve image not showing in html
<tr>
<th>Name</th>
<th>Location</th>
<th rowspan="2">
<img src="https://app.3schools.in/logo.png" height="50" width="50">
</th>
</tr>
<tr>
<td>John</td>
<td>USA</td>
</tr>
</table>
Live Demo
Example:
<table>
<tr>
<th>Product</th>
<th>Image</th>
<th>Description</th>
</tr>
<tr>
<td>Product 1</td>
<td><img src="/product.jpg" alt="Product 1" width="100" height="100"></td>
<td>Description of Product</td>
</tr>
</table>