Zed-King Institute

    HTML Image Tag with Alt Text and Width

    easyImages and linksHTML

    Images are added with the <img> tag, which has no closing tag.

    The question

    Insert an image (any src, for example logo.png) with alt text "Kaithal photo" and a width of 300 pixels using the width attribute.

    The code

    index.html

    <img src="logo.png" alt="Kaithal photo" width="300">

    Result

    How it works

    1. 1src is the file name or address of the image.
    2. 2alt is shown if the image cannot load and is read aloud by screen readers.
    3. 3width sets the size in pixels; setting only width keeps the image's proportions.

    Common mistakes

    • Writing </img> — img is an empty element and has no closing tag.
    • Leaving out alt, which examiners and accessibility checkers both mark wrong.

    Now solve a similar question yourself

    A new HTML / CSS / JS question every time, checked instantly.

    Practice questions

    More in Images and links