Open In App

How to Insert an Image from Folder in HTML

Last Updated : 23 Oct, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Share
Report
News Follow

The <img> src attribute is used to insert an image from folder in HTML. The src attribute accepts absolute and relative file path.

Insert Image from Folder using HTML <img> src Attribute

The <img> tag is used to insert an image in HTML. The src attribute specifies the path to the image file, and other attributes like alt, width, and height can be used to customize the display. The folder image specifies with the folder name with image name. For example - "./images/logo/logo.png".

Syntax

<img src="folder_path/image.jpg" alt="description" width="value" height="value">

Example: Inserting an image form folder in HTML.

HTML
<h3>Insert an Image in HTML from a Folder</h3>

<img src="Geeks/HTML-tutorial.jpg" alt="HTML Tutorial"
        width="350px" height="230px">

Output

image-from-folder-1

Insert Image from Folder in CSS

Insert an image from folder can also be done with CSS. CSS set an image as the background of HTML element. It is useful for setting images as backgrounds for various sections.

Syntax

.element {
background-image: url('path/to/image.jpg');
background-size: cover;
}

Example: Inserting an Image from folder using CSS.

HTML
<!DOCTYPE html>
<html>

<head>
    <style>
        .background-image {
            width: 350px;
            height: 230px;
            background-image: url('Geeks/HTML-tutorial.jpg');
            background-size: cover;
        }
    </style>
</head>

<body>
    <h3>Insert an Image in HTML from a Folder</h3>

    <div class="background-image"></div>
</body>

</html>

Output

image-from-folder-1


Next Article

Similar Reads

three90RightbarBannerImg
  翻译: