One thing that always confused me in HTML and i never found satisfying explanation is specifics of image element.

We are generally taught that image element is used to just simply embed an image into a document. And that as element it must not contain any content and due to not containing any content in it and simply linking to image it does not need closing tag at all.

But what confuses me then is that we adjust image height/width itself by referring to the element itself and setting its height and width as is case with any other normal element and adjusting the content it wraps up. But image element supposedly only links to the image and thats it.

So how does image element work exactly then, how is it implemented?

  • 1
    "[an image element] must not contain any content" isn't completely accurate. It can't contain HTML tags because it is a "void" element, but that isn't the same as "content." May 9, 2023 at 18:29
  • If you have been taught that an element must not contain any content it is incorrect and you should ask for your money back if you paid money for a course that told you that. An image element SHOULD have an alt tag with the text describing the image.,
    – davidgo
    May 10, 2023 at 6:24

1 Answer 1


Think of img as a "replaced element". (Key phrase for a web search.) Rather than containing content within opening and closing tags, it defines what external content is placed inside that block.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.