In this lesson we will learn how we can link to other pages, documents, images or even outside websites. A website generally contains more than one HTML document. Every website’s main page is the index file, and from there you can reach the other pages via links. We will learn to refer to other/outside websites, pictures and downloadable documents.
<a> </a> - we include between these tags text (or picture), on which we will be able to click.
The <a> tag stands for anchor tag and has the following attributes:
href – this attribute/property is used to give the path of the file we want to open or the website we want to reach, by clicking on the given text.
target – this attribute is used to define how we want to open the given path in the href attribute: in the same browser tab (target=”_self” or either not defining it at all, as the default behavior is the same browser tab), or in a new one (in this case we need to define it as target=”_blank”).
download – this attribute has no values to be given. Including this keyword, we can express that the document marked by the href attribute needs to be downloaded, not opened in the browser.
The text Read more will appear, on which we can click, because it is written between the <a> tags.
The URL address of the wikipedia.org page is the value given to the href attribute, so if we click on the link, this page will open in a new browser tab, because we gave the target attribute the value _blank.
- If we want to open another webpage with a link, we have to write the full web address in the <a> tag (we have to use the protocol too – ex: http:// or https://). The easiest way to be correct is to open the webpage in a browser and copy the address from there.
- We can recognize the links on a website, by moving the cursor over them. Usually, the cursor switches his shape to a hand, meaning that there is a clickable element.
- We generally open pages belonging to one webpage in the same tab, and pages from other websites in new tabs.
- If a browser cannot open a document referred by a link, the file will be automatically downloaded. If we want a file to be downloaded regardless of the browsers settings, we must add the download attribute to the <a> tag.
- If we have longer content on a website, we can refer its parts with bookmark, so we can directly jump to that section by clicking on a link.
Creating a bookmark – we can mark as bookmark any HTML tag, by adding the attribute id and a value to it, as the unique identifier of that element.
Reference to bookmark – the <a> tags href attribute should get the id of the bookmark preceded by a # symbol.
In this example we jump to the bookmark with the id bm, by clicking on the Jump to the browsers link.
<a href=" https://www.google.com" target="_blank">Search</a>