The alt
attribute (not tag) is by definition plain text, so whatever you insert there will be taken as plain text (not markup) by browsers. If you mess around with code that inserts strings that look like HTML tags into an alt
attribute value and then parse and process them as markup, this is no different with similar play with other attributes.
The alt
attribute has a well-defined job, to act as a textual replacement for the image when the image is not displayed but e.g. spoken, rendered with a Braille device, or displayed as text. It is thus unproductive to try to use it for other purposes.
Similar considerations apply to the title
attribute.
To use data that will be parsed as HTML, it is thus much better to use a custom attribute, specifically a data-*
attribute, like data-desc
, or whatever you prefer. They have no default processing in browsers or search engines, so they are safe to use for private purposes.