2

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?

user3812733
  • 165
  • 1
  • 9
  • While it will still work you want to use anchor, as it will also bind to middle click, show user url before entering and other commonly forgotten things. – Akxe Dec 28 '17 at 11:21

1 Answers1

0

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.

lumio
  • 7,428
  • 4
  • 40
  • 56
  • 1
    As far as I know since HTML5 it is valid to wrap block level elements in anchors: http://html5doctor.com/block-level-links-in-html-5/ – user3812733 Dec 28 '17 at 11:27
  • Nice! Makes more sense as well when speaking of an accessibility point of view – lumio Dec 28 '17 at 11:29