HTML-Tag img: So fügen Sie Bilder auf Ihrer Website ein (2024)

HTML-Tag img: So fügen Sie Bilder auf Ihrer Website ein (1)

Das img-Tag erlaubt es Ihnen, ganz einfach Bilder auf Ihrer Website einzubauen. Dabei werden zahlreiche Formate unterstützt. Durch eine Vielzahl unterschiedlicher Attribute fügt sich das img-Tag in HTML noch besser ein.

Inhaltsverzeichnis

  1. Wozu wird der img-Tag benötigt?
  2. Wie sieht die Syntax des HTML-Tags img aus?
  3. Welche Attribute können für den img-Tag in HTML verwendet werden?

SSL-Zertifikate von IONOS!

Wahren Sie dank SSL-Zertifikaten die Geheimhaltung Ihres Online-Verkehrs und stärken Sie das Vertrauen Ihrer Kunden in die Sicherheit Ihrer Webseite.

Geprüfte Sicherheit

Bis zu 256-bit Verschlüsselung

Einfache Aktivierung

Wozu wird der img-Tag benötigt?

Das HTML-Tag img fügt Bilder und Grafiken in Websites ein. Dabei fungiert das img-Tag quasi als Platzhalter. Wird eine Website aufgerufen, verlinkt das hinterlegte src-Attribut auf den eigentlichen Speicherort der Grafik. Diese wird dann in die Website eingebettet. Neben dem src-Attribut benötigt das img-Tag ein alt-Attribut, das einen alternativen Text hinterlegt für den Fall, dass das Bild nicht angezeigt werden kann. Unterstützt werden mit dem img-Tag bei HTML u.a. JPEG, GIF und PNG.

Wie sieht die Syntax des HTML-Tags img aus?

Die Syntax eines img-Tags ist sehr übersichtlich und benötigt nur wenige Komponenten. Die einfachste Variante ist diese:

<img src="rotesauto.png" alt="Roter Sportwagen an einer Ampel">

Es ist allerdings sicherer, wenn Sie bei der Verwendung eines img-Tags immer auch zumindest die Höhe und Breite des Bildes auf der Website definieren. So können Sie sicherstellen, dass die Grafik richtig angezeigt wird. Diese Einstellungen nehmen Sie über die HTML-Attribute width und height vor. Der passende Code sieht beispielsweise so aus:

<img src="rotesauto.png" width="500" height="200" alt="Roter Kleinwagen an einer Ampel">

Auch das Attribut loading ist für das img-Tag in HTML empfehlenswert. Dadurch wird die entsprechende Grafik erst geladen, wenn Nutzerinnen oder Nutzer bis zu der entsprechenden Stelle scrollen. Dafür stellen Sie den Wert des loading-Attributs auf lazy. So sieht das im Code aus:

<img src="rotesauto.png" width="500" height="200" alt="Roter Kleinwagen an einer Ampel" loading="lazy">

Welche Attribute können für den img-Tag in HTML verwendet werden?

Neben den genannten Attributen width, height und loading gibt es zahlreiche weitere Attribute, die durch das img-Tag in HTML unterstützt werden. Dazu gehören sämtliche globalen, Event- und weitere spezifische Attribute. Hier ein Auszug der Attribute, die mit dem img-Tag verwendet werden können:

Attribut

Wert

Beschreibung

alt

"Text"

Obligatorisch; gibt einen Alternativtext für das Bild an.

crossorigin

anonymus, use-credentials

Legt fest, welche fremden Websites durch ein Skript auf das entsprechende Bild zugreifen können.

decoding

auto, sync, async

Definiert, wie und ob ein Bild decodiert werden darf.

height

Pixel oder Prozent

Legt fest, wie hoch das Bild auf der Website sein soll.

ismap

true, false

Regelt den Zugriff des Bildes auf eine serverseitige Image-Map.

loading

auto, eager, lazy

Bestimmt, wann ein Bild geladen werden soll.

referrerpolicy

no-referrer, no-referrer-when-downgrade, origin, origin-when-cross-origin, unsafe-url

Legt fest, ob das Bild auch aus einer unsicheren Quelle stammen darf.

sizes

sizes

Definiert Bildgrößen für unterschiedliche Seitenlayouts.

src

URL

Obligatorisch; gibt die URI-Adresse des Bildes an.

srcset

URL-Listen

Hinterlegt eine Liste von Bildern für verschiedene Einsatzzwecke, z.B. unterschiedliche Geräte und Größen.

usemap

#mapname

Verknüpft das Element mit einer bestimmten Image-Map.

width

Pixel oder Prozent

Gibt die Breite des Bildes an.

Während die oben genannten Attribute alle nach wie vor Verwendung in einem img-Tag finden können, gibt es auch einige Attribute, die seit HTML5 und HTML 5.1 als veraltet gelten. Dazu gehören align, border, hspace, longdesk und vspace.

Tipp

Auf dem Weg zur individuellen und professionellen Website ist der Homepage-Baukasten von IONOS genau das richtige Werkzeug. Dieser erlaubt es Ihnen, eine eigene Onlinepräsenz ganz nach Ihren Vorstellungen zu erstellen – auch ohne großes Vorwissen. Möchten Sie diese Aufgabe doch lieber den Profis überlassen, stehen Ihnen unsere erfahrenen Expertinnen und Experten sehr gerne zur Verfügung.

  • Web-Entwicklung
  • HTML
  • Tutorials

Ähnliche Artikel

HTML-Tag img: So fügen Sie Bilder auf Ihrer Website ein (2)

div in HTML: Alles Wichtige zur Verwendung des div-Containers

Da das div-Tag keine eigenen semantischen Merkmale hat, wird seit der Einführung von HTML5 sein Einsatz nur dann empfohlen, wenn keine passenderen Elemente verfügbar sind. Hier erfahren Sie alles über den div-Container, lernen anhand praktischer Beispiele, wie er eingesetzt wird, und warum div in HTML kaum noch eine Rolle spielt.

div in HTML: Alles Wichtige zur Verwendung des div-Containers

HTML-Tag img: So fügen Sie Bilder auf Ihrer Website ein (3)

HTML-Tag style: So gestalten Sie das Aussehen von Elementen

Das HTML-Tag style ist die beste Möglichkeit, das Aussehen einzelner Elemente auf einer Website zu gestalten und die Seite so optimal aufzubauen. Hier erfahren Sie, wofür das style-Tag in HTML genau verwendet wird, wie es aufgebaut ist und welche HTML-Attribute mit ihm kompatibel sind. Damit können Sie das Tag einfach in Ihren Code einbetten.

HTML-Tag style: So gestalten Sie das Aussehen von Elementen

HTML-Tag img: So fügen Sie Bilder auf Ihrer Website ein (4)

_target: Linkziele definieren in HTML

Möchten Sie Verlinkungen auf Ihrer Website einbauen, können Sie mit dem HTML-Attribut target festlegen, wo der Link geöffnet werden soll. Dabei entscheiden Sie, ob die Nutzer und Nutzerinnen auf Ihrer Onlinepräsenz bleiben oder zur nächsten Website weitergehen sollen. Hier erfahren Sie, wie Sie _target verwenden und was Sie dabei beachten sollten.

_target: Linkziele definieren in HTML
HTML-Tag img: So fügen Sie Bilder auf Ihrer Website ein (2024)

FAQs

What does the IMG tag do in HTML? ›

Definition and Usage

The <img> tag is used to embed an image in an HTML page. Images are not technically inserted into a web page; images are linked to web pages. The <img> tag creates a holding space for the referenced image.

How to fix image error in HTML? ›

Make sure that the file type is supported by the browser (e.g. supported types include PNG, JPEG, and GIF). Additionally, check if the filename is spelled correctly and its case-sensitivity is correct. Finally, try adding a '/' at the beginning of the src path.

How to insert image using img tag in HTML? ›

First, the title attribute is title =”(your title)”. Next, set your alt attribute, which explains the image in detail. Finally, set the height and width of your image. Use the code <img src=”(your title)” alt=”Image” height=”(your image height)” width=”(your image width)”>.

Why is my img not working in HTML? ›

There are several possible reasons why your images are not showing up on your pages as expected: The image file is not located in the same location that is specified in your IMG tag. The image does not have the same file name as specified in your IMG tag. The image file is corrupt or damaged.

What is the difference between IMG and picture tag in HTML? ›

The <img> element is required as the last child of the <picture> element, as a fallback option if none of the source tags matches. Tip: The <picture> element works "similar" to <video> and <audio>. You set up different sources, and the first source that fits the preferences is the one being used.

What is the IMG role in HTML? ›

An img can contain captions and descriptive text, as well as multiple image files that when viewed together give the impression of a single image. An img represents a single graphic within a document, whether or not it is formed by a collection of drawing objects.

Why is my HTML file not displaying images? ›

Verify that your HTML source code has the correct path to images. Moving your website or renaming folders may cause the links to images in the code to break. You can use the inspect website elements function of your browser for this.

Why my image is broken in HTML? ›

Broken image links typically occur when the link address is no longer valid, i.e., when someone has deleted, moved, or renamed the page on which your link relied. This generally happens in one of three ways: The image file is no longer located at the location specified in your <IMG SRC=> tag.

Why my image is not fitting in HTML? ›

The problem you are having is caused by leaving the element completely empty. Since there is nothing in the row, content, or forside div the height is 0. To fix this explicitly set the height or min-height using CSS ( height:100px or min-height:100px where 100px is however big your image is).

How to use img tag with local image? ›

To insert a local image into an HTML document, use the <img> tag with the src attribute set to the file path of the image. For example: <img src="images/myimage.

How do you use IMG as a link in HTML? ›

Place the <img> tag inside an <a> tag and provide href . As others mentioned in comments you want to surround the image in an anchor <a> tag and apply the href attribute to the anchor tag as you would a normal hyperlink.

How to get an image URL? ›

Get an image URL
  1. On your Android phone or tablet, open the Google app , Chrome app. , or Firefox.
  2. Go to images.google.com.
  3. Search for the image.
  4. In Images results, tap the image to get a larger version.
  5. Copy the image URL based on your browser: Google app: At the top right of the image, tap More. Share. Copy .

Why is the IMG tag not loading images from URL? ›

The image URL may be incorrect or broken. The image file may be in a format that is not compatible with HTML. The image may not have been uploaded to a server or directory accessible by the HTML code.

How to display an image in HTML? ›

The HTML <img> 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 <img> tag creates a holding space for the referenced image. The <img> tag is empty, it contains attributes only, and does not have a closing tag.

How to set URL for img in HTML? ›

In order to put a simple image on a web page, we use the <img> element. This is a void element (meaning, it cannot have any child content and cannot have an end tag) that requires two attributes to be useful: src and alt . The src attribute contains a URL pointing to the image you want to embed in the page.

What is the IMG in the body of HTML? ›

To insert an image in HTML, use the image tag and include a source and alt attribute. Like any other HTML element, you'll add images to the body section of your HTML file. The HTML image element is an “empty element,” meaning it does not have a closing tag.

Does the img tag need to be closed? ›

The <img> tag is used to insert an image into a document. This element must not contain any content, and does not need a closing tag.

What is the use of IMG ALT in HTML? ›

The required alt attribute specifies an alternate text for an image, if the image cannot be displayed. The alt attribute provides alternative information for an image if a 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).

How do I link an image in HTML? ›

The <a> tag is used to create a hyperlink. Placing an <img> tag inside an <a> tag displays a clickable image that leads to another page. The <a> tag has an attribute, href . The href attribute's value specifies the location of the webpage we want to link.

Top Articles
Latest Posts
Article information

Author: Pres. Lawanda Wiegand

Last Updated:

Views: 5480

Rating: 4 / 5 (71 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Pres. Lawanda Wiegand

Birthday: 1993-01-10

Address: Suite 391 6963 Ullrich Shore, Bellefort, WI 01350-7893

Phone: +6806610432415

Job: Dynamic Manufacturing Assistant

Hobby: amateur radio, Taekwondo, Wood carving, Parkour, Skateboarding, Running, Rafting

Introduction: My name is Pres. Lawanda Wiegand, I am a inquisitive, helpful, glamorous, cheerful, open, clever, innocent person who loves writing and wants to share my knowledge and understanding with you.