What Is the Correct HTML for Creating a Hyperlink ? - Scaler Topics (2024)

What is the Correct HTML for Creating a Hyperlink ?

In HTML, the correct way of creating a hyperlink is to use the anchor tag which is represented by the <a> symbol. The hyperlink is used for redirecting to a new URL which can be a web page, file, or the same location within the web page. The content that we write in the <a> tag defines the location of the hyperlink. The URL should be written inside the href attribute of the anchor tag.

How to Insert Hyperlink in HTML Page ?

To insert a hyperlink we use the anchor tag represented by <a> and the text is inserted in the <a> and </a> tags. The href attribute is used to write the URL. The anchor tag should be used within the body tag.

Syntax :

Example

If we want to create a hyperlink to Google's website, we will insert its URL in the href attribute. The content that we want to show will be written between the anchor tag which will be displayed on the webpage.

Output :What Is the Correct HTML for Creating a Hyperlink ? - Scaler Topics (1)

We can see that a hyperlink is created that redirects to the URL mentioned in the href attribute when clicked.

Default Appearance of the HTML Anchor Tag

  • The visited link is marked as purple.
  • The unvisited link is marked as blue which is the default color of a hyperlink.
  • An active link is marked as red.

Attributes

Global Attributes

Global attributes include those attributes which can be used with all the elements in HTML.

The anchor tag supports the global attributes in HTML.

Event Attributes

The event attributes are used to define event actions in HTML.The anchor tag supports all the Event Attributes in HTML.

The other attributes are :

AttributeDescription
hrefThis attribute is used to specify the URL or the hyperlink.
hreflangThis attribute is used to specify the language of the linked URL.
typeThis attribute is used to specify the media type of the linked URL.
targetThis attribute is used to specify the location where the linked hyperlink should be opened.
downloadThis attribute is used to download the mentioned URL. The user needs to click the hyperlink to download it.
pingThis attribute is used for a list of URLs separated by a space. When the link is clicked, the browser will send POST requests with the body PING to the given hyperlinks. This command is used for tracking.
relThis command is used to specify the relation between the current document and the linked document.
referrerpolicyThis attribute is used to specify which referrer information should be sent with the URL.
mediaThis attribute is used to specify the media or device for which the URL is optimized.

Properties

Content Categories :

  • Flow Content :
    It is a broad category that contains all those elements that can be used inside the body tag. It includes elements like heading elements, interactive elements, embedding elements, phrasing elements, sectioning elements, and form-related elements.
    For example, an anchor tag is included in the category of flow content elements.
  • Phrasing Content :
    Phrasing content is a subset of flow content that is used to define the text and the markup it contains, and it can be used where the flow content is expected. The anchor tag belongs to this category if it contains only the phrasing content.
  • Interactive Content :
    Interactive content is another subset of flow content that includes those elements that are particularly designed for user interaction, and are used where the flow content is expected. The anchor tag belongs to this category as well.

Tag Omission :
Not allowed. Both opening and closing tags are compulsory.

Allowed Parents :
Other <a> elements are not allowed but elements accepting phrasing content or flow content are allowed.

DOM Interface :
HTMLAnchorElement

More Examples

Example : 1 - Linking to an Absolute URL

An absolute URL contains the entire address of the site and has HTTP/HTTPS protocol added to the domain name.

Output :What Is the Correct HTML for Creating a Hyperlink ? - Scaler Topics (2)

Example : 2 - Linking to Relative URLs

The relative URL does not contain the full web address and only contains the location following the domain. It assumes that the URL that we have added is on the same site and is part of the same root domain.

It starts with the forward-slash and makes the browser stay within the current site.

Output :What Is the Correct HTML for Creating a Hyperlink ? - Scaler Topics (3)

Example : 3 - Linking to an Element on the Same Page

To link the URL to an element on the same page, we set the href attribute to an id of an element to where we want to navigate.

Before clicking on the link :

What Is the Correct HTML for Creating a Hyperlink ? - Scaler Topics (4)

After clicking on the link :
When we click on the link, the page focus goes down and points where the id of that element matches the set id. In our example, when we click the link href is set as #divs, and the focus goes to the paragraph where the id matches #divs.

What Is the Correct HTML for Creating a Hyperlink ? - Scaler Topics (5)

Example : 4 - Linking to an Email Address

To create links that open externally in the user's email program , we use the mailto: scheme.

Output :
On clicking the link, a pop-up comes.What Is the Correct HTML for Creating a Hyperlink ? - Scaler Topics (6)

Example : 5 - Linking to Telephone Numbers

If we want to link a phone number, we will insert it in the href attribute. The content that we want to show will be written between the anchor tag which will be displayed on the webpage.

Output :

What Is the Correct HTML for Creating a Hyperlink ? - Scaler Topics (7)

We can see that a hyperlink is created that redirects to the number mentioned in the href attribute when clicked.

Note :

The tel : link behavior varies with device capabilities :

  • If the device is a cellular device, it auto-dials the number.
  • Many operating systems make calls using Skype or FaceTime.
  • Other behaviors can include number saving and sharing.

Example : 6 - Linking to a JavaScript

If we want to link our URL to a JavaScript page, we will insert the text in the href attribute. The content that we want to show will be written between the anchor tag which will be displayed on the webpage.

Output :
On clicking on the link, an alert comes up.

What Is the Correct HTML for Creating a Hyperlink ? - Scaler Topics (8)

Example : 7 - Linking to a Non-HTML Resource

If we want to link to a non-HTML resource like an external file like a word document or PowerPoint, we will insert its path in the href attribute. The content that we want to show will be written between the anchor tag which will be displayed on the webpage.

Output :

What Is the Correct HTML for Creating a Hyperlink ? - Scaler Topics (9)

When we click on the link, it will redirect to the word document whose path we have provided.

Example : 8 - Using the Download Attribute to Save a "canvas" as a PNG

If we want to download a canvas that we have painted, we will handle it using the 'download' attribute which tells us by what name the painting will be saved on the device. A canvas is created.

HTML:

CSS:

In the following code, we are setting the background color of the canvas and the color of the a tag.

JavaScript:

First, we decide the color of the ink, then add some action listeners for specific actions and write a function to fill the arc.

Output :What Is the Correct HTML for Creating a Hyperlink ? - Scaler Topics (10)

Example : 9 - Using an Image as a Link

If we want to link to an image, we will insert its details using an img tag nested inside the anchor tag. The details of the image that we want to show will be written between the anchor tag which will be displayed on the webpage. The src attribute of the img tag is used to write the path name of the image.

Output :

What Is the Correct HTML for Creating a Hyperlink ? - Scaler Topics (11)

Example : 10 - Opening a Link in a New Browser Window

If we want the URL to open in a new browser window, we will insert its path in the href attribute and set the target attribute as _blank. The content that we want to show will be written between the anchor tag which will be displayed on the webpage.

Output :
On clicking the link, it gets opened in a new window.What Is the Correct HTML for Creating a Hyperlink ? - Scaler Topics (12)

Skip Links

Skip links take the user to the main content, past the various elements like the logo, search, and navigation. It is usually hidden until it receives focus.

Skip links are used to skip the repeated content like headers, paragraphs, etc. It is useful for those who navigate through the pages with the help of assistive technology like switch control, voice command, etc. as moving through the repetitive links can be tedious.

HTML:

CSS:

Default CSS Settings

The default CSS setting of the "a" tag for most of the browsers is :

Size and Proximity

Links should provide a large area so that it is easy to activate them. This not only helps those with motor control issues but also touchscreen users. A size of at least 44×44 pixels is expected.

Links should have proper spacing between them. When there are multiple links nearby, the wrong link might get clicked, so it is recommended to have proper spacing between the links.

Security and Privacy

In order to open the link in a new window, target = "blank" is used. But this can lead to a window.opener API exploration attack. It is recommended to use rel = "noreferrer" and rel = "noopener" so that the threat can be protected.

Accessibility

Accessibility is to make the websites usable by as many people as we can in different ways like :

  • tablets, mobile phones.
  • alternating browsing devices like TV, and smartwatches.
  • phones using old browsers.
  • by including features for various people having visual, hearing, mobility, and cognitive impairments so that they can access the page.

Anchor tags are also used as buttons by setting their href attribute as javascript:void(0) or "#" to prevent the page from refreshing and then listening to the click events. This causes unexpected behavior when links are copied/dragged, opened in a new tab or window, bookmarked, etc. So it is not recommended to use the href attribute as a button.

While writing the code, for the anchor tag, the content inside it should indicate where the link goes.

Specifications

As mentioned above, it supports flow content, phrasing content, and interactive content. It also supports the global and event attributes in HTML.

Browser Support

The anchor tag in HTML is supported by the following browsers :

  • Google Chrome 12
  • Microsoft Edge 79
  • Safari 6
  • Opera 15
  • Mozilla Firefox 49
  • Samsung Internet

Conclusion

  • In HTML, the correct way of creating a hyperlink is to use the anchor tag which is represented by the <a> symbol.
  • The hyperlink is used for redirecting to a new URL which can be a web page, file, or the same location within the web page.
  • To insert a hyperlink we use the anchor tag represented by <a> and the text is inserted in the <a> and </a> tags.
  • It supports flow content, phrasing content, and interactive content. It also supports the global and event attributes in HTML.
  • Links should provide a large area so that it is easy to activate them. It should also have spacing between them.
What Is the Correct HTML for Creating a Hyperlink ? - Scaler Topics (2024)

FAQs

What Is the Correct HTML for Creating a Hyperlink ? - Scaler Topics? ›

In HTML, the correct way of creating a hyperlink is to use the anchor tag which is represented by the <a> symbol. The hyperlink is used for redirecting to a new URL which can be a web page, file, or the same location within the web page. The content that we write in the <a> tag defines the location of the hyperlink.

What is correct HTML for creating a hyperlink? ›

To make a hyperlink in an HTML page, use the <a> and </a> tags, which are the tags used to define the links. The <a> tag indicates where the hyperlink starts and the </a> tag indicates where it ends. Whatever text gets added inside these tags, will work as a hyperlink. Add the URL for the link in the <a herf=" ">.

How to create a hyperlink in HTML? ›

Chapter Summary
  1. Use the <a> element to define a link.
  2. Use the href attribute to define the link address.
  3. Use the target attribute to define where to open the linked document.
  4. Use the <img> element (inside <a> ) to use an image as a link.

Which of the following is a correct way to create a hyperlink in HTML? ›

The a href=" " tag defines a hyperlink, which is used to link from one page to another.

What is the correct HTML for creating a hyperlink to a Google search? ›

The correct HTML for creating a hyperlink is the <a> tag. In its simplest form, an <a> (anchor) tag requires two attributes: href and text. The href attribute specifies the URL to which the link points, and the text is the clickable text that appears on the page.

Which tag is correct for creating a hyperlink? ›

In HTML, the correct way of creating a hyperlink is to use the anchor tag which is represented by the <a> symbol. The hyperlink is used for redirecting to a new URL which can be a web page, file, or the same location within the web page. The content that we write in the <a> tag defines the location of the hyperlink.

What is hyperlink types in HTML? ›

To make a hyperlink in HTML, use the anchor tag: <a href="URL" title="Description of link">link text</a> . There are three different types of hyperlinks on the web, absolute, relative, and inline links.

What is the correct way to create a hyperlink? ›

Create a hyperlink to a location on the web

Select the text or picture that you want to display as a hyperlink. Link. You can also right-click the text or picture and click Link on the shortcut menu. In the Insert Hyperlink box, type or paste your link in the Address box.

What is a link tag in HTML? ›

Definition and Usage

The <link> tag defines the relationship between the current document and an external resource. The <link> tag is most often used to link to external style sheets or to add a favicon to your website. The <link> element is an empty element, it contains attributes only.

How do I convert HTML to hyperlink? ›

Use <a> tag to turn your html into a link. For example: Text as a link: <a href="abcd.com"><h1>Click me</h1></a>

Which HTML tag creates a hyperlink? ›

The <a> HTML element (or anchor element), with its href attribute, creates a hyperlink to web pages, files, email addresses, locations in the same page, or anything else a URL can address. Content within each <a> should indicate the link's destination.

Which one is correct to create a hyperlink? ›

The correct answer to the question “What is the correct HTML for creating a hyperlink” is option (4). <a href=http://www.intellipaat.com> intellipaat.com</a>. And all the other options are incorrect HTML tags for creating a hyperlink.

What is the correct HTML code for inserting an image? ›

The <img> tag is used to embed an image in an HTML page. Images are not technically inserted into a web page; images are linked to web pages. The <img> tag creates a holding space for the referenced image.

What is the correct way to hyperlink in HTML? ›

The <a> tag defines a hyperlink, which is used to link from one page to another. The most important attribute of the <a> element is the href attribute, which indicates the link's destination. By default, links will appear as follows in all browsers: An unvisited link is underlined and blue.

What is the correct HTML for creating a hyperlink to an email address? ›

While using <a> tag as an email tag, you will use mailto: email address along with href attribute.

What is the correct HTML tag for creating a hyperlink to an external website? ›

The correct way to create a hyperlink is by using the <a> (anchor) tag. The href attribute inside the anchor tag specifies the destination URL or location that the link points to.

What is the correct HTML for an email hyperlink? ›

Write “<a href=” to add a link to the HTML code. 3. Insert the “mailto:” tag to send the link to an email address. Place the closing tag.

What is the correct HTML element for inserting a link break? ›

The <br> tag inserts a single line break.

Which of the following is the correct syntax for creating a hyperlink with an image in HTML? ›

By adding the <img> tag inside an <a> tag the browser can see that the image should be clickable. You have turned the image into a link!

Top Articles
Passive vs. active investing: What's the difference?
How Safe Are TASER Weapons? - Axon.com
Bashas Elearning
Rabbits Foot Osrs
Cumberland Maryland Craigslist
Emmalangevin Fanhouse Leak
Acbl Homeport
Richmond Va Craigslist Com
Brutál jó vegán torta! – Kókusz-málna-csoki trió
More Apt To Complain Crossword
This Modern World Daily Kos
Puretalkusa.com/Amac
Craigslist Missoula Atv
Copart Atlanta South Ga
Jbf Wichita Falls
Strange World Showtimes Near Roxy Stadium 14
Persona 5 Royal Fusion Calculator (Fusion list with guide)
Acts 16 Nkjv
How many days until 12 December - Calendarr
If you have a Keurig, then try these hot cocoa options
Which Sentence is Punctuated Correctly?
480-467-2273
Co10 Unr
Craigslist Sf Garage Sales
Rlcraft Toolbelt
Palmadise Rv Lot
Craigslist Ludington Michigan
Exploring TrippleThePotatoes: A Popular Game - Unblocked Hub
Supermarkt Amsterdam - Openingstijden, Folder met alle Aanbiedingen
Federal Student Aid
Panchitos Harlingen Tx
Muma Eric Rice San Mateo
Why The Boogeyman Is Rated PG-13
Obsidian Guard's Skullsplitter
The Bold And The Beautiful Recaps Soap Central
3302577704
Priscilla 2023 Showtimes Near Consolidated Theatres Ward With Titan Luxe
Kelley Blue Book Recalls
Craigslist Pets Plattsburgh Ny
Brandon Spikes Career Earnings
No Boundaries Pants For Men
Sams Gas Price Sanford Fl
Chubbs Canton Il
Spreading Unverified Info Crossword Clue
German American Bank Owenton Ky
Buildapc Deals
Appsanywhere Mst
Festival Gas Rewards Log In
What Is The Gcf Of 44J5K4 And 121J2K6
Ff14 Palebloom Kudzu Cloth
Coors Field Seats In The Shade
Latest Posts
Article information

Author: Nicola Considine CPA

Last Updated:

Views: 5599

Rating: 4.9 / 5 (49 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Nicola Considine CPA

Birthday: 1993-02-26

Address: 3809 Clinton Inlet, East Aleisha, UT 46318-2392

Phone: +2681424145499

Job: Government Technician

Hobby: Calligraphy, Lego building, Worldbuilding, Shooting, Bird watching, Shopping, Cooking

Introduction: My name is Nicola Considine CPA, I am a determined, witty, powerful, brainy, open, smiling, proud person who loves writing and wants to share my knowledge and understanding with you.