Is it Compliant?
Placing an image inside a heading is compliant syntax.
After researching and testing (using W3C Markup Validation Service), the conclusion is that putting an image inside a heading is 100% compliant syntax. Heading tags can accept inline elements, and <img>
is an inline element, so it can be placed within heading tags.
Is it a Good Practice?
Although there is much debate online, Google Search Central’s response is: “This is a good practice🔗”!
This means that the following syntax is valid and a good practice:
Since the alt
attribute for images has some recommended rules to follow, I can imagine that separating decorative images from headings and using CSS to hide the heading text could also be a good choice. For example, Bootstrap has visually-hidden and Tailwind has sr-only to make text visually hidden but semantically present.