Search code examples
htmlangularsemanticsrouterlink

Should I use routerLink only with anchors or is it okay to use it on other HTML elements too?


Let's say that I have a logo on my website, should I link it this way:

<a routerLink="/">
    <img src="logo.png" alt="logo">
</a>

or maybe like this:

<img src="logo.png" alt="logo" routerLink="/">

What about headlines?

<a [routerLink]="['/post', post.id]">
    <h3>Post title</h3>
</a>

versus

<h3 [routerLink]="['/post', post.id]">Post title</h3>

What is the proper way of handling this? Does it even matter? Is there any semantic value in adding HTML anchor tag if I'm using routerLink?


Solution

  • Semantically speaking it is better to use an anchor than just an element. For accissibility reasons an anchor is more clear than just linking an element.