DEV Community

Discussion on: CSS can help improve your HTML⁉ - Ep 2: buttons and links.

Collapse
 
ashleyjsheridan profile image
Ashley Sheridan

Link tags are allowed to have missing or empty href attributes in the case that their resulting action would be not allowed. The idea is that the page would consist of dynamic content, but the link is left in as an effective placeholder. Assistive tech following the spec will ignore these links, but they're still perfectly valid. The links are, effectively, in a disabled state.

Might also be worth considering the 3 <input> button types: button, submit, and reset.

Also, while lesser used, there are other patterns that apply button styles to elements, such as <label>s attached to radio buttons and checkboxes, with the corresponding role and aria- attributes added for better accessibility. These sorts of markups are infrequently used, but they're still valid.

Collapse
 
grahamthedev profile image
GrahamTheDev • Edited

Some great points here, I will see about adjusting the article and examples to account for these and downgrade them to warnings rather than errors.

I can’t see a valid use case for applying button styles to labels though as those would effectively be custom controls at that stage (so I would argue a separate class for clarity - even if it does go against DRY principles?) what do you think?

Update

I added a new section to account for the items mentioned here.

See if you think that covers it well enough or if there is anything else to add, I will work on updating the fiddles to incorporate that.

Thanks for the suggestions! ❤

Collapse
 
ashleyjsheridan profile image
Ashley Sheridan

My point about the <a> without an href attribute wasn't about anchors, but still links. Imagine something like this:

<a>You can find your purchased download here.</a>
Enter fullscreen mode Exit fullscreen mode

This would create the link as a placeholder, which might be useful for visual reasons, but it wouldn't yet be an active control. Then, based on some sort of event, you could make it active by giving it a valid href value using Javascript.

It's not a common pattern, but it's a completely one.

Thread Thread
 
grahamthedev profile image
GrahamTheDev

I used "anchors" for all <a> elements, perhaps the wording wasn't clear but I was talking about <a name="" would then be a warning in addition to allowing for <a>some text</a> to be a warning rather than an error (just in case you did want to do something like you suggest).

I think we are in agreement! lol!

Collapse
 
oskargrosser profile image
Oskar Grosser • Edited

I did not know that href may be left out to let anchor elements behave as placeholders, thank you! I should definitely read the specs more instead of relying on tools' complaints (i.e. Lighthouse lead me to believe that missing the href attribute is invalid or inaccessible HTML).

Collapse
 
ashleyjsheridan profile image
Ashley Sheridan

Lighthouse is not really that good for accessibility testing, it misses a lot and throws up a fair few false positives. The a11y tool in Firefox is better, but better than both of those is the aXe tool, which is available as a plugin for all the major browsers.