Тег IMG

We can add image as a link and other HTML elements as a link. A link is a connection from one Web page to another web page.

To make page links in an HTML page, use the and tags, with href attribute used to define the links. We should use the … tags inside … tags.

Syntax

Following is the syntax to add image as a link on the web page.

Example

Following is the example program to make image as a link.

DOCTYPE html> html> body> p>a href="https://www.Youtube.com/">img src="https://www.tutorialspoint.com/assets/questions/media/426142-1668760872.png" style="width:50px;height:50px;">a>p> body> html>

Following is the output for the image as a link, clicking on the image will navigate us to google home page.

Example

Following is the example program to make image as a link.

DOCTYPE html> html> body> center> h2>Image as a Linkh2> a href="https://www.tutorialspoint.com">img src="https://www.tutorialspoint.com/assets/questions/media/426142-1668760765.png" alt="Tutorialspoint" style="width:50px;height:60px;">a> center> body> html>

Following is the output for the image as a link, clicking on the image will navigate us to destination webpage.

Example

Following is another example program to make image as a link.

DOCTYPE html> html> head> title>HTML Image as linktitle> head> body> The following image works as a link:br> a href="https://www.qries.com/"> a> body> html>

After clicking on the image, it will redirect to the destination webpage.

Источник

HTML Images

Images can improve the design and the appearance of a web page.

Example

Italian Trulli

Example

Girl in a jacket

Example

Flowers in Chania

HTML Images Syntax

The HTML tag is used to embed an image in a web page.

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

The tag is empty, it contains attributes only, and does not have a closing tag.

The tag has two required attributes:

Syntax

The src Attribute

The required src attribute specifies the path (URL) to the image.

Note: When a web page loads, it is the browser, at that moment, that gets the image from a web server and inserts it into the page. Therefore, make sure that the image actually stays in the same spot in relation to the web page, otherwise your visitors will get a broken link icon. The broken link icon and the alt text are shown if the browser cannot find the image.

Example

Flowers in Chania

The alt Attribute

The required alt attribute provides an alternate text for an image, if the user for some reason cannot view it (because of slow connection, an error in the src attribute, or if the user uses a screen reader).

The value of the alt attribute should describe the image:

Example

Flowers in Chania

If a browser cannot find an image, it will display the value of the alt attribute:

Example

Tip: A screen reader is a software program that reads the HTML code, and allows the user to «listen» to the content. Screen readers are useful for people who are visually impaired or learning disabled.

Image Size — Width and Height

You can use the style attribute to specify the width and height of an image.

Example

Girl in a jacket

Alternatively, you can use the width and height attributes:

Example

Girl in a jacket

The width and height attributes always define the width and height of the image in pixels.

Note: Always specify the width and height of an image. If width and height are not specified, the web page might flicker while the image loads.

Width and Height, or Style?

The width , height , and style attributes are all valid in HTML.

However, we suggest using the style attribute. It prevents styles sheets from changing the size of images:

Example

Images in Another Folder

If you have your images in a sub-folder, you must include the folder name in the src attribute:

Example

Images on Another Server/Website

Some web sites point to an image on another server.

To point to an image on another server, you must specify an absolute (full) URL in the src attribute:

Example

W3Schools.com

Notes on external images: External images might be under copyright. If you do not get permission to use it, you may be in violation of copyright laws. In addition, you cannot control external images; they can suddenly be removed or changed.

Animated Images

HTML allows animated GIFs:

Example

To use an image as a link, put the tag inside the tag:

Example

Image Floating

Use the CSS float property to let the image float to the right or to the left of a text:

Example

The image will float to the right of the text.

The image will float to the left of the text.

Tip: To learn more about CSS Float, read our CSS Float Tutorial.

Common Image Formats

Here are the most common image file types, which are supported in all browsers (Chrome, Edge, Firefox, Safari, Opera):

Abbreviation File Format File Extension
APNG Animated Portable Network Graphics .apng
GIF Graphics Interchange Format .gif
ICO Microsoft Icon .ico, .cur
JPEG Joint Photographic Expert Group image .jpg, .jpeg, .jfif, .pjpeg, .pjp
PNG Portable Network Graphics .png
SVG Scalable Vector Graphics .svg

Chapter Summary

  • Use the HTML element to define an image
  • Use the HTML src attribute to define the URL of the image
  • Use the HTML alt attribute to define an alternate text for an image, if it cannot be displayed
  • Use the HTML width and height attributes or the CSS width and height properties to define the size of the image
  • Use the CSS float property to let the image float to the left or to the right

Note: Loading large images takes time, and can slow down your web page. Use images carefully.

HTML Exercises

HTML Image Tags

Tag Description
Defines an image
Defines an image map
Defines a clickable area inside an image map
Defines a container for multiple image resources

For a complete list of all available HTML tags, visit our HTML Tag Reference.

Источник

Тег предназначен для отображения на веб-странице изображений в графическом формате GIF, JPEG или PNG. Адрес файла с картинкой задаётся через атрибут src . Если необходимо, то рисунок можно сделать ссылкой на другой файл, поместив тег в контейнер . При этом вокруг изображения отображается рамка, которую можно убрать, добавив атрибут border=»0″ в тег .

Рисунки также могут применяться в качестве карт-изображений, когда картинка содержит активные области, выступающие в качестве ссылок. Такая карта по внешнему виду ничем не отличается от обычного изображения, но при этом оно может быть разбито на невидимые зоны разной формы, где каждая из областей служит ссылкой.

Синтаксис

Атрибуты

align Определяет как рисунок будет выравниваться по краю и способ обтекания текстом. alt Альтернативный текст для изображения. border Толщина рамки вокруг изображения. height Высота изображения. hspace Горизонтальный отступ от изображения до окружающего контента. ismap Говорит браузеру, что картинка является серверной картой-изображением. longdesc Указывает адрес документа, где содержится аннотация к картинке. lowsrc Адрес изображения низкого качества. src Путь к графическому файлу. vspace Вертикальный отступ от изображения до окружающего контента. width Ширина изображения. usemap Ссылка на тег , содержащий координаты для клиентской карты-изображения.

Также для этого тега доступны универсальные атрибуты и события.

Закрывающий тег

      

lorem Lorem ipsum dolor sit amet.

Источник

How to Embed a .png Image Into an HTML Page?

The ability to embed images within a message to appear when users view something makes HTML useful for email communication. Since everything is self-contained, you do not need a web server anywhere to host the image. Users can embed any type of image in an HTML document, whether in the form of .png, jpeg, and others.

Let’s get started with embedding a .png image into an HTML page!

Method 1: How to Embedding a “.png” Image in HTML With Tag?

To embed a .png image into an HTML page, use the “ ” tag. Then, insert the “src” attribute and add the “.png” image as the “src” value. For practical implications, follow the steps stated below.

Step 1: Insert Heading

Initially, utilize the HTML “ ” tag to add a heading in the HTML document.

Step 2: Design a div Container

Next, design a div container by adding the “ ” element and insert a class or id attribute according to your choice. Then, set the value of this property for later use.

Step 3: Add “.png” Image

Now, use a “ ” tag to add any type of media file to the HTML page. To do so, the “src” attribute was added inside the “ ” tag, and added a png image as the “src” value. Furthermore, you can apply styling by using the inline “style” attribute and setting the CSS properties which you want to apply:

It can be observed that the specified image has been embedded successfully:

Method 2: How to Embedding a “.png” Image in HTML With CSS Properties?

To embed a “.png” image into an HTML page using CSS properties, the “background-image” property can be utilized. For practical implications, try out the stated instructions.

Step 1: Add Heading

In HTML, add a heading with the help of the heading tag from “” to “ ” tag.

Step 2: Create a “div” Container

Then, use the “ ” tag to create a div container in an HTML document:

Embed .PNG Image < / h1 >
< / div >Output

Step 3: Add “.png” Image

Access the div container by using the attribute selector with a particular attribute value as “.div-img”:

.div-img {
height : 50% px ;
width : 50% px ;
background-size : contain ;
background-image : url ( /spring-flowers.png )
}

After that, apply these CSS properties:

  • height” and “width” properties are utilized for setting the size of the stated element
  • background-size” specifies the size of the background image. For that purpose, the value of this property is set as “contain”.
  • background-image” inserts an image by using the “url()” function.

Output

That’s all about embedding a “.png” image into an HTML page.

Conclusion

To embed a “.png” image into an HTML page, the “ ” tag is utilized. Then, add the “src” attribute and insert the “.png” image as the value of “src”. You can also utilize the “background-image” CSS property to add a “.png” image on an HTML page. This tutorial has demonstrated all about embedding the .png image into an HTML page.

Источник

Читайте также:  Название документа
Оцените статью