Links are necessary for users to jump from one page to another or inside the same page. An anchor element <a>
is used to define a link.
Link can be:
A link does not have to link to another HTML file, it can link to any file anywhere on the web.
The basic structure of a link element is:
<a href="https://developer.mozilla.org/he/docs/Web/Tutorials">MDN tutorial website</a>
Some of the common attributes used with a element are:
href
- Defines a hypertext source link. Omitting this attribute creates a placeholder link. The link can be absolute, such as “https://www.google.co.il”, or it can be relative to the current page. <p id="top">my text</p>Then, href specifies the id like:
<a href="#top">Go to top id</a>Selecting this link will scroll the page straight to the element with that ID.
target
- Specifies where to display the linked resource (_self, _blank, _parent ...)For relative links the HTML <base>
element can be used. It specifies the default base URL and the default target to use for all relative URLs contained within a document. There can be only one <base> element in a document.
The base element has to be written in the <head> section. For example:
<head> <base target="_blank" href="http://www.w3schools.com/images/"> </head> <body> <img src="my-image.gif" alt="#"> <a href="http://www.w3schools.com">W3Schools</a> </body>