In many websites, we can see a lot of call-to-action such as click here, know more, buy now, etc. When users click the "buy now", it will direct to a shopping page. So, "buy now" is linking to another page web address.
How can we add hyperlink on the text? It is simple, all we need to insert attributes inside the element.
Attributes are adding extra information to tags, but they are not showing in the actual content.
How can we add hyperlink on the text? It is simple, all we need to insert attributes inside the element.
Attributes
Attributes are adding extra information to tags, but they are not showing in the actual content.
<tag name="value"></tag>
The name="value" part is the attribute. It is inside a tag and includes an attribute name, followed by an "=" sign, and an attribute value.
In the example below, <a></a> stands for "anchor" and will make the text into a hyperlink.
And the href="https://www.google.com" is a link attribute, which will direct to Google Homepage when someone click on "my favorite website".
As we can see, the google web address does not show on the live output. It is hided in "my favorite website". And "my favorite website" text turn to blue and have an underline, which become a clickable content.
If we want to go to a specific page and open to a new tab, what should we do?
We will need to add "title" and "target" attributes in the <a></a> tag, following by href attribute.
According to MDN, title attribute specifies extra information about the link, such as "homepage", "shopping page".
Target attribute specifies the browsing context which will be sued to display the link. For example, target="_blank" will display the link in a new tab.
For example, if I want to link my favorite website to Zara Woman Page, I would do the following steps:
- Go to Zara Woman page, and copy the web address, then paste it in the href attribute.
- Write the title attribute, which is title="Zara Woman Page".
- Put target="_blank" attribute in order to open the link to a new tab.
- Test the link
As the result, when you click on "my favorite website", the Zara Woman page will show in a new tab.
At the end, just remember, always write double quotes to present the attribute value.
Comments
Post a Comment