Open In App

How to Add Image in HTML Table ?

Adding images to an HTML table can enhance the visual appeal and functionality of your webpage. Whether it is for displaying product images in an e-commerce website or adding profile pictures in a user list, images in tables are a common requirement. In this article, we will explore two methods to add images to an HTML table i.e. using plain HTML and using HTML with inline CSS for styling.

Add Image in HTML Table

In this method, we’ll add images to each row of the table using the <img> tag within plain HTML.






<!DOCTYPE html>
<html>
  
<head>
    <title>Table with Images</title>
    <style>
        table {
            margin: auto;
        }
    </style>
</head>
  
<body>
    <table border="1">
        <tr>
            <th>Image</th>
            <th>Name</th>
            <th>Email</th>
        </tr>
        <tr>
            <td><img src=
                alt="GFG Logo" width="100" 
                height="100">
            </td>
            <td>XYZ</td>
            <td>xyz@geeksforgeeks.org</td>
        </tr>
        <tr>
            <td><img src=
                alt="GFG Logo" width="100" 
                height="100">
            </td>
            <td>ABC</td>
            <td>abc@geeksforgeeks.org</td>
        </tr>
    </table>
</body>
  
</html>

Output:



Explanation

Add Image in HTML Table using HTML and Inline CSS

In this method, we’ll add images to the table and use inline CSS to style the images for better presentation.




<!DOCTYPE html>
<html>
  
<head>
    <title>Styled Table with Images</title>
  
    <style>
        table {
            margin: auto;
        }
    </style>
</head>
  
<body>
    <table border="1">
        <tr>
            <th>Image</th>
            <th>Name</th>
            <th>Email</th>
        </tr>
        <tr>
            <td><img src=
                alt="GFG Logo" 
                style="width: 100px; height: 100px; border-radius: 50%;">
            </td>
            <td>XYZ</td>
            <td>xyz@geeksforgeeks.org</td>
        </tr>
        <tr>
            <td><img src=
                alt="GFG Logo" 
                style="width: 100px; height: 100px; border-radius: 50%;">
            </td>
            <td>ABC</td>
            <td>abc@geeksforgeeks.org</td>
        </tr>
    </table>
</body>
  
</html>

Output:

Explanation


Article Tags :