t - Web APIs | MDN

  • Skip to main content
  • Skip to search
HTMLImageElement: alt property Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨July 2015⁩.

  • Learn more
  • See full compatibility
  • Report feedback

The alt property of the HTMLImageElement interface provides fallback (alternate) text to display when the image specified by the <img> element is not displayed, whether because of an error, because the user has disabled the loading of images, or because the image hasn't finished loading yet. It reflects the <img> element's alt content attribute.

There are important accessibility implications of providing appropriate alt text, and the requirements may differ based on the purpose of the image. See the HTML <img> reference for more information.

In this article

  • Value
  • Examples
  • Specifications
  • Browser compatibility

Value

A string.

Examples

Setting the alt attribute

jsconst img = new Image(); img.src = "example.png"; img.alt = "An example picture";

Specifications

Specification
HTML# dom-img-alt

Browser compatibility

Help improve MDN

Was this page helpful to you? Yes No Learn how to contribute

This page was last modified on ⁨Nov 7, 2025⁩ by MDN contributors.

View this page on GitHub • Report a problem with this content Filter sidebar
  1. The HTML DOM API
  2. HTMLImageElement
  3. Constructor
    1. Image()
  4. Instance properties
    1. align Deprecated
    2. alt
    3. attributionSrc Deprecated
    4. border Deprecated
    5. complete
    6. crossOrigin
    7. currentSrc
    8. decoding
    9. fetchPriority
    10. height
    11. hspace Deprecated
    12. isMap
    13. loading
    14. longDesc Deprecated
    15. name Deprecated
    16. naturalHeight
    17. naturalWidth
    18. referrerPolicy
    19. sizes
    20. src
    21. srcset
    22. useMap
    23. vspace Deprecated
    24. width
    25. x
    26. y
  5. Instance methods
    1. decode()
  6. Inheritance
    1. HTMLElement
    2. Element
    3. Node
    4. EventTarget
  7. Related pages for HTML DOM
    1. BeforeUnloadEvent
    2. DOMStringMap
    3. ErrorEvent
    4. HTMLAnchorElement
    5. HTMLAreaElement
    6. HTMLAudioElement
    7. HTMLBRElement
    8. HTMLBaseElement
    9. HTMLBodyElement
    10. HTMLButtonElement
    11. HTMLCanvasElement
    12. HTMLDListElement
    13. HTMLDataElement
    14. HTMLDataListElement
    15. HTMLDialogElement
    16. HTMLDivElement
    17. HTMLDocument
    18. HTMLElement
    19. HTMLEmbedElement
    20. HTMLFieldSetElement
    21. HTMLFormControlsCollection
    22. HTMLFormElement
    23. HTMLFrameSetElement Deprecated
    24. HTMLHRElement
    25. HTMLHeadElement
    26. HTMLHeadingElement
    27. HTMLHtmlElement
    28. HTMLIFrameElement
    29. HTMLInputElement
    30. HTMLLIElement
    31. HTMLLabelElement
    32. HTMLLegendElement
    33. HTMLLinkElement
    34. HTMLMapElement
    35. HTMLMediaElement
    36. HTMLMenuElement
    37. HTMLMetaElement
    38. HTMLMeterElement
    39. HTMLModElement
    40. HTMLOListElement
    41. HTMLObjectElement
    42. HTMLOptGroupElement
    43. HTMLOptionElement
    44. HTMLOptionsCollection
    45. HTMLOutputElement
    46. HTMLParagraphElement
    47. HTMLPictureElement
    48. HTMLPreElement
    49. HTMLProgressElement
    50. HTMLQuoteElement
    51. HTMLScriptElement
    52. HTMLSelectElement
    53. HTMLSourceElement
    54. HTMLSpanElement
    55. HTMLStyleElement
    56. HTMLTableCaptionElement
    57. HTMLTableCellElement
    58. HTMLTableColElement
    59. HTMLTableElement
    60. HTMLTableRowElement
    61. HTMLTableSectionElement
    62. HTMLTemplateElement
    63. HTMLTextAreaElement
    64. HTMLTimeElement
    65. HTMLTitleElement
    66. HTMLTrackElement
    67. HTMLUListElement
    68. HTMLUnknownElement
    69. HTMLVideoElement
    70. HashChangeEvent
    71. History
    72. ImageData
    73. Location
    74. MessageChannel
    75. MessageEvent
    76. MessagePort
    77. Navigator
    78. PageRevealEvent
    79. PageSwapEvent
    80. PageTransitionEvent
    81. Plugin Deprecated
    82. PluginArray Deprecated
    83. PromiseRejectionEvent
    84. RadioNodeList
    85. TimeRanges
    86. UserActivation
    87. ValidityState
    88. Window
    89. WorkletGlobalScope
  8. Guides
    1. Using microtasks in JavaScript with queueMicrotask()
    2. In depth: Microtasks and the JavaScript runtime environment

Từ khóa » Html Image Alt Text Color