HTML alt-Attribut
Das HTML alt-Attribut wird in HTML- und XHTML-Dokumenten verwendet. Es gibt einen alternativen Text an, der gerendert werden muss, wenn das Element aus irgendeinem Grund nicht angezeigt werden kann. Das alt-Attribut kann auch von Screenreadern verwendet werden, um sehbehinderten Nutzern die Interaktion mit einer Webseite zu ermöglichen. Für Barrierefreiheit muss ein Bild ein alt-Attribut haben. Es kann jedoch für dekorative Bilder, bei denen kein alternativer Text benötigt wird, leer gelassen werden (alt="").
Sie können das alt-Attribut für die folgenden Elemente verwenden: <area>, <img>, <input>.
DANGER
Es ist erforderlich, das alt-Attribut für das <img>-Element zu verwenden. Für <input>-Elemente können Sie das alt-Attribut nur mit <input type="image"> verwenden.
Syntax
Syntax des "alt"-Attributs
<img alt="alternative text">
<area alt="alternative text">Beispiel für die Verwendung des HTML alt-Attributs auf dem <area>-Element:
HTML alt-Attribut
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
</head>
<body>
<p>Click on the logo or on one of the logo item to watch it closer:</p>
<img src="https://de.w3docs.com/uploads/media/news_gallery/0001/01/thumb_316_news_gallery_list.jpeg" width="250" height="150" alt="block" usemap="#blockmap" />
<map name="blockmap">
<area shape="circle" coords="50,32,25" alt="html" href="https://de.w3docs.com/uploads/media/book_gallery/0001/01/d450f0358f947dffb3af91195c3002600d74101b.png" />
<area shape="circle" coords="218,115,25" alt="css" href="https://de.w3docs.com/uploads/media/book_gallery/0001/01/25521e981b34da57c8f51baddc5b76351b855818.png" />
<area shape="circle" coords="195,32,28" alt="php" href="https://de.w3docs.com/uploads/media/book_gallery/0001/01/4bbee6698c4884f25c46010d61b658dd62d2c04f.png" />
<area class="homepage" shape="rect" coords="90,90,35,55" alt="php" href="https://www.w3docs.com/" />
</map>
</body>
</html>Beispiel für die Verwendung des HTML alt-Attributs auf dem <img>-Element:
HTML alt-Attribut
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
</head>
<body>
<img src="https://de.w3docs.com/uploads/media/default/0001/01/25acddb3da54207bc6beb5838f65f022feaa81d7.jpeg" alt="Aleq" width="200" height="185"/>
</body>
</html>Beispiel für die Verwendung des HTML alt-Attributs auf dem <input>-Element:
Beispiel für die Verwendung des HTML "alt"-Attributs auf dem <input>-Element
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
<style>
input {
vertical-align: middle;
}
</style>
</head>
<body>
<form action="/form/submit">
Email:
<input type="email" name="Email" />
<input type="image" src="https://i7.pngguru.com/preview/278/823/594/computer-icons-button-clip-art-green-submit-button-png.jpg" alt="Submit button" width="60" height="60" />
</form>
</body>
</html>Praxis
What is the purpose of the 'alt' attribute in HTML?