How to Insert an Image in HTML Page? (2024)

'; var adpushup = adpushup || {}; adpushup.que = adpushup.que || []; adpushup.que.push(function() { adpushup.triggerAd(ad_id); });

Images make content more interesting by helping readers understand the content better on the web page.

We can insert images into the HTML page. To insert image in an HTML page, use the <img> tags. It is an empty tag, containing only attributes since the closing tag is not required.

We should use the <img> tag inside <body>…</body> tag. The <img> tag specifies an image to be displayed in an HTML document.

The src attribute is used to add the image source which is the URL of the image(location of the file).

The alt attribute is for adding alternate text, width is for adding width, and height is for adding the height of the image.

Images are not technically inserted into a web page; images are linked to web pages. The <img> tag creates a holding space for the image.

The <img> tag has two attributes −

  • src − Specifies the path to the image(location of the file)

  • alt − Specifies an alternate text for the image

Syntax

Following is the syntax to insert an image in an HTML page.

<img src="url" alt="alternatetext">

Example

Following is the example program to add an image to an HTML page.

<!DOCTYPE html><html><body> <h2>HTML Article on Inserting image to the web page</h2> <img src="https://www.tutorialspoint.com/javafx/images/javafx-mini-logo.jpg"></body></html>

Now let’s see how the alt attribute (alternate text) works if the user for some reason cannot view, it because of slow connection, or an error in the src attribute. Then the value of the alt attribute describes the image property.

Example

In the following example program, we will specify an incorrect path for the image to be inserted in an HTML page and see how the alt attribute works.

<!DOCTYPE html><html><body> <h2>HTML Article on Inserting image to the web page</h2> <img src="https://www.tutorialspoint.com/opencv/images/opencv-mini-logo.jpg" alt="search engine image" ></body></html>

The text "search engine image" is the alternate text for the image when there occurs some problem to view the image.

Example: Changing the size of an image

We can also use style attribute to make changes in the size of the image that is height and width of the image. Following is the example program to make changes in the size of the image.

<!DOCTYPE html><html><body> <h2>HTML Article on Inserting image to the web page</h2> <img src="https://www.tutorialspoint.com/opencv/images/opencv-mini-logo.jpg" height="50px" width="50px"></body></html>

Kickstart Your Career

Get certified by completing the course

Get Started

How to Insert an Image in HTML Page? (31)

Advertisem*nts

'; adpushup.triggerAd(ad_id); });

I'm an expert in web development and programming with extensive knowledge in the topics mentioned. My expertise is demonstrated by my in-depth understanding of various concepts such as data structures, networking, RDBMS (Relational Database Management Systems), operating systems, Java, MS Excel, iOS development, HTML, CSS, Android, Python, C programming, C++, C#, MongoDB, MySQL, JavaScript, PHP, and more.

In the provided article, the focus is on HTML and the insertion of images into web pages. Let me break down the concepts used in the article:

  1. HTML (HyperText Markup Language):

    • HTML is a markup language used to structure content on the web.
    • It consists of elements represented by tags, such as <html>, <body>, <h2>, <img>, etc.
  2. Image Insertion in HTML:

    • Images are inserted using the <img> tag.
    • The src attribute specifies the image source (URL or file location).
    • The alt attribute provides alternate text for the image, useful for accessibility and when the image cannot be loaded.
  3. Syntax for Image Insertion:

    • The syntax for inserting an image is <img src="url" alt="alternatetext">.
  4. Example: Inserting an Image in HTML:

    • The article provides an example program demonstrating how to add an image to an HTML page using the <img> tag.
  5. Handling Incorrect Image Paths:

    • The article illustrates how the alt attribute works when there's an incorrect image path, providing alternate text to describe the image.
  6. Changing Image Size with Style Attribute:

    • The article shows how to use the style attribute to change the size of an image by specifying height and width.
  7. Additional Concepts:

    • The article briefly mentions the use of the style attribute to modify image size (height and width).
    • The publication date ("Updated on: 31-Aug-2023") indicates the relevance of the information.

In conclusion, the article focuses on practical aspects of inserting and styling images in HTML, catering to both basic and more advanced users. If you have any specific questions or need further clarification on these concepts, feel free to ask.

How to Insert an Image in HTML Page? (2024)
Top Articles
Latest Posts
Article information

Author: Kelle Weber

Last Updated:

Views: 5539

Rating: 4.2 / 5 (53 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Kelle Weber

Birthday: 2000-08-05

Address: 6796 Juan Square, Markfort, MN 58988

Phone: +8215934114615

Job: Hospitality Director

Hobby: tabletop games, Foreign language learning, Leather crafting, Horseback riding, Swimming, Knapping, Handball

Introduction: My name is Kelle Weber, I am a magnificent, enchanting, fair, joyous, light, determined, joyous person who loves writing and wants to share my knowledge and understanding with you.