Although it may seem fine on most browsers, your use of the <a>
element is incorrect as it lacks a meaningful label inside. The correct approach would be to enclose the entire <h1>
in the link, or place the <a>
within the <h1>
(both compliant with HTML5).
<a href="[absolute url]">
<span></span> <h1>page name</h1>
</a>
Based on your comments, it appears premature for you to delve into image replacement techniques and web semantics when still grappling with syntax.
Why should we avoid using an empty <a>
tag and what's the significance of image replacement techniques?
The Gilder/Levin technique involves adding non-semantic elements like <span>
and using CSS to display them as icons. This ensures these elements are disregarded by screen readers, thus improving accessibility. While an icon might enhance visibility for sighted users, it becomes redundant for those who rely on screen readers. It can also aid search engine indexing.
In the original code snippet, the lack of a label inside the <a>
tag makes it confusing for both screen readers and web crawlers to interpret the link's purpose. To address this, the entire text should be enclosed within the <a>
tags to allow the whole line to function as the clickable link. Using an empty <a>
tag is discouraged, even if a <span>
is nested inside.
Given the semantically nonsensical nature of leaving an empty <a>
tag, there is limited documentation on how various browsers handle such instances.