Ensuring that all images on your website have descriptive alt attributes is essential for accessibility and SEO. However, sometimes it’s easy to overlook this during development. Here’s a quick JavaScript snippet that will help you identify all <img> elements that either lack an “alt” attribute or have it set to an empty value.

Simply paste the following code into your browser’s console, and it will return a list of images without proper alt attribute value:

[...document.querySelectorAll('img')].filter(img => !img.hasAttribute('alt') || '' === img.getAttribute('alt').trim())