The HTML lang attribute specifies the language of the document's content. It is important for accessibility and search engine optimization. By providing the correct language code, assistive technologies can properly pronounce and interpret the content, while search engines can better understand and index the page.