HTMLs Tutorial

HTML Tutorial HTML Tags HTML Basic Tags HTML Attributes HTML Elements HTML Formatting HTML Text Format HTML body tag HTML samp tag HTML script Tag HTML section tag HTML select tag HTML source tag HTML span tag HTML strike tag HTML strong tag HTML style tag HTML sub tag HTML summary tag HTML sup Tag HTML svg tag HTML table tag HTML u tag HTML Headings HTML Paragraphs HTML wbr tag HTML Anchor HTML Image HTML Lists HTML Ordered List HTML Unordered List HTML Form HTML Form input HTML with CSS HTML Layouts HTML References HTML Frames HTML Links Fieldset Tag in HTML Basic HTML Tags Br Tag in HTML Free HTML Templates How to Create a Table in HTML HTML Calendar HTML Card HTML Cellspacing HTML Center Image HTML Checkbox Read-only HTML Cleaner HTML Code for a Tab HTML Comment HTML Compiler HTML Nested Forms HTML Overlay Text on the Image HTML Select Option Default HTML Snake Game HTML Subheader HTML Tab Character dd Tag in HTML How Many HTML Tags are There HTML Align Tag HTML Responsive HTML Tab Code HTML Table Alternate Row Color HTML Table Fix Column Width Contact HTML DL Tag in HTML How to Insert Image in HTML HTML Background Color HTML Dark Mode How to Convert HTML to PNG HTML Data Toggle HTML Email Template HTML Font Color HTML Font Family ID and Class in HTML HTML Tab Space HTML Tab Tag HTML Itemprop HTML Itemscope HTML Form Design HTML Input Only Numbers HTML Textarea HTML to JPG HTML to Markdown Python li Tag in HTML MDN HTML What is the Correct HTML for Making a Hyperlink? What is the Root Element of an HTML Document How to Make a Box in HTML How to Save HTML Files in Notepad How to Align Text in HTML How to Change Font Color in HTML? How to Change Font Size in HTML How to Change Image Size in HTML How to Create a HTML Page How to Create a Link in HTML File? How to Create an HTML File? HR Tag in HTML HTML Base Tag HTML Default Attribute HTML Hyperlink HTML Indent HTML Injection Payloads HTML Input Numbers Only HTML Roadmap HTML Row Height HTML Schedule HTML Space HTML Tab HTML vs HTTP HTML5 API HTML5 Video HTML Collection to Array Text Area in HTML

HTML5 Advance

HTML5 Tutorial HTML5 Tags HTML Button Tag HTML canvas Tag HTML caption Tag HTML City tag HTML Tag HTML5 SVG HTML Event Attribute HTML5 Audio HTML5 Youtube HTML5 Button Tag HTML5 Tags

Misc

How to add JavaScript to HTML How to change font in HTML How to change text color in HTML HTML Date HTML Hide Element HTML Nested Table HTML Reset Button What does HTML stand for? HTML Background Image HTML Tag Div Tag in HTML How to insert Image in HTML How to create a link with no underline in HTML How to insert spacestabs in text using HTMLCSS HTML tag HTML Code HTML Tag HTML Canvas Design a tribute page using HTML and CSS What is a Container tag Font tag in HTML Difference between HTML and DHTML Empty Tag in HTML HTML Button Link Html Line Break Img src HTML Nested List in HTML Placeholder in HTML TD in HTML HTML Space Code HTML Target Attribute HTML Tag Markup Meaning in HTML Border-Collapse in HTML HTML Onclick Online HTML Compiler Convert HTML to PDF HTML Formatter HTML5 - Web Storage HTTP – Responses Container Tag in HTML DL Tag in HTML Horizontal Rule HTML HTML Tab Text Html Table Cell Background Color HTML Table Cell Color HTML Col Width How Many HTML Tags are There Convert String to Unicode Characters in Python HTML Runner HTML Style Attribute HTML Superscript Attribute HTML tabindex Marquee Tag in HTML HTML Dynamic Form HTML side Tag HTML Pattern Attribute HTML q Tag HTML Readonly Base 64 Encoding in HTML Documents Enhancing Data Portability and Security Evo Cam Web Cam HTML Free code camp HTML CSS How to Add a JS File in HTML? How to Add Picture in HTML How to Add the Logo in HTML? How to Add Video in HTML HTML Class Attribute HTML Entities HTML Form Elements HTML Form Templates HTML Marquee Tag HTML Radio Buttons HTML Text box HTML to JSX HTML Tooltip Basic HTML Codes How to Align Image Center in HTML HTML Header Tag HTML Image Tag HTML Next Line

What is the Correct HTML for Making a Hyperlink?

Introduction

The anchor tag, denoted by the <a> sign in HTML, is appropriate for constructing a hyperlink. A hyperlink is used to reroute traffic to another URL, which could be another website, file, or even another position on the same website. The hyperlink's position is specified by the text we enter in the <a> tag. The URL should be written inside the anchor tag's href attribute.

How to Insert Hyperlink in HTML Page?

The text is placed between the <a> and </a> tags when inserting a hyperlink, which is represented by the anchor tag <a>. To write the URL, employ the href attribute. Use of the anchor tag inside the body tag is recommended.

Syntax

<a href=""></a>

Example

We shall include Google's URL in the href property if we wish to make a hyperlink to their website. The text we wish to display will be put in between the anchor tags the webpage displays.

<a href="https://www.javatpoint.com">Javatpoint</a>

Output

What is the Correct HTML for Making a Hyperlink?

Thus, we can observe that an anchor element has been built that, when clicked, goes to the page defined by the href attribute.

Default Appearance of the HTML Anchor Tag

  • The hyperlink that has been visited is indicated in purple.
  • The hyperlink's default colour of blue is used to indicate the unvisited link.
  • A link that is currently active is indicated in red.

Attributes

Global Attributes

The properties compatible with all HTML elements are referred to as global attributes.

In HTML, the global attributes are supported by the anchor tag.

Event Attributes

Event attributes define event actions in HTML. The anchor element supports all of the HTML Event Attributes.

The other attributes are:

Attribute    Description
href   The hyperlink or URL is specified using this attribute.
hreflangThe referenced URL's language can be specified using this property.
typeThe media type of the connected URL is specified using this attribute.
targetThis attribute specifies the location at which the hyperlinked link should open.
downloadTo download the specified URL, use this property. For the user to download it, they must click the hyperlink.
pingA list of URLs with spaces between them is used with this property. Upon clicking the hyperlink, the browser will send POST requests and a body PING to the specified URLs. Tracking is the purpose of this command.
relWith this command, you can indicate the relationship between the linked document and the current document.
referrer policySelecting which referrer information to send along with the URL is done using this attribute.
mediaSpecifying the medium or device for which the URL is optimized is done with this property.

Properties

Content Categories:

1. Flow Content:

This wide category includes every element that can be employed within a body tag. It has components such as form-related elements, header elements, interactive elements, embedding elements, phrasing elements, and sectioning elements.

The group of flow content components includes, for instance, anchor tags.

2. Phrasing Content:

Phrasing content can be used anywhere flow content is required. It is a subset of flow content that defines the text and the markup it contains. If the anchor tag has the phrase content, it falls under this type.

3. Interactive Content:

Another subset of flow content is interactive content, which consists of elements specifically created for user interaction and used in contexts where flow content is expected. This also includes the anchor tag.

4. Tag Omission:

Not consented to. It is required to have both the opening and closing tags.

5. Allowed Parents:

Elements that take phrase or flow material are permitted; other <a> elements are not.

6. DOM Interface:

HTMLAnchorElement

More Examples

Example 1: Linking to an Absolute URL

An absolute URL is an address of a domain that also contains the protocol of http/https and the website's full address.

<body>

    <a href="http://www.facebook.com">Facebook</a>

</body>

Output

What is the Correct HTML for Making a Hyperlink?

Example 2: Linking to Relative URLs

The location after the domain is all that is included in the relative URL; the entire web address is absent. It is assumed that the URL we entered is part of the same root domain and is located on the same website.

It causes the browser to remain on the current page and begins with the forward slash.

<body>

    <a href="//site.com">Example 1</a>

    <br>

    <a href="./index.html">Example 2</a>

</body>

Output

What is the Correct HTML for Making a Hyperlink?

Example 3: Linking to an Element on the Same Page

The href attribute is assigned to the ID of an element that we wish to visit to link the URL to an element on the same page.

<body>

<p><a href="#divs"> Click me to go down</a>

</p>
<p> HTML or HyperText Markup Language is used to design web pages. It was released in 1993. The HTML file extension is named ".html". CSS and JavaScript are used to construct an HTML file. In other words, HTML explains the skeleton body of the webpage or how the page is formed. The codes have been written as elements. Another name for these components is HTML tags. The tags make use of HTML markup. All of the major tags in HTML have to be opened and closed. This is known as the golden rule. Each tag in a series of several tags needs to be closed. </p>

<p>Using a markup language such as HTML, we can

Make connections to other documents, arrange the information in our document, and provide the information context and significance. There are two components to an HTML document. It includes hypertext links (HyperText) and structured information (Markup) to other documents. </p>

<p> The anchor tag, denoted by the <a> sign in HTML, is appropriate for constructing a hyperlink. A hyperlink is used to reroute traffic to another URL, which could be another website, file, or even another position on the same website. The URL should be written inside the anchor tag's href attribute. </p>

<p id="divs">You will land here when clicked on the first link</p>

</body>

Output

Before clicking on the link

What is the Correct HTML for Making a Hyperlink?

After clicking on the link

The page focus shifts downward and points to the location where the element's ID matches the configured ID when we click the link. In our example, the attention shifts to the paragraph where the id matches #divs when we click the link with the href set to #divs.

What is the Correct HTML for Making a Hyperlink?

Example 4: Linking to an Email Address

We use the mailto: method to build links that open externally in the user's email program.

<body>

    <a href="mailto:[email protected]">Send email</a>

</body>

 Output

What is the Correct HTML for Making a Hyperlink?

A pop-up appears when you click on the link.

Example 5: Linking to Telephone Numbers

The phone number will be inserted in the href property if we wish to link to it. The text we wish to display will be put in between the anchor tags the webpage displays.

<body>

    <a href="tel:+48.397.7986">+48 397 7986</a>

</body>

Output

What is the Correct HTML for Making a Hyperlink?

The hyperlink has been created, and when it is clicked, it directs to the number provided as the value of the attribute href.

Note

The device capabilities affect the behavior of the tel: link.

  • When using a cellular device, the number is automatically called.
  • Skype and FaceTime are popular phone apps for operating systems.
  • Sharing and storing numbers are examples of additional behaviors.

Example 6: Linking to a JavaScript

We shall add text to the href attribute to link our URL to a JavaScript page. The text we wish to display will be put in between the anchor tags the webpage displays.

<body>

    <a href="javascript:alert('This is an alert');">Click me</a>

</body>

Output

What is the Correct HTML for Making a Hyperlink?

An alert appears when you click on the link.

Example 7: Linking to a Non-HTML Resource

The path of the external file, such as a Word document or PowerPoint, should be inserted into the href property if we wish to link to a non-HTML resource. The text we wish to display will be put in between the anchor tags the webpage displays.

<body>

    <a href="chapter1.docx">Word Document</a>

</body>

Output

What is the Correct HTML for Making a Hyperlink?

The Word document with the specified path will open when we click the link.

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

Using the 'download' attribute, which indicates the name by which the painting will be saved on the device, we can download a canvas we have painted. We make a canvas.

HTML

<body>

    <p>Paint by moving the mouse.

        <a href="" download="photo.png">Download image</a>

    </p>

    <canvas width="300" height="300"></canvas>

    <script src="main.js"></script>

</body>

CSS

The background color of the canvas and the color of the tag are set in the following code.

canvas {

  background: #fff;

  border: 1px solid black;

}

a {

  display: inline-block;

  color: dark blue;

}

JavaScript (javascript):

First, we choose the ink color. Next, we construct a function to fill the arc and add certain action listeners for particular activities.

let canvas = document.querySelector('canvas'),

  c = canvas.getContext('2d')

c.fillStyle = 'light green'

function pen(x, y) {

  if (isDrawing) {

    c.beginPath()

    c.arc(x, y, 4, 0, Math.PI * 2)

    c.closePath()

    c.fill()

  }

}

canvas.addEventListener('mousemove', (event) =>

  pen(event.offsetX, event.offsetY),

)

canvas.addEventListener('mousedown', () => (isDrawing = true))

canvas.addEventListener('mouseup', () => (isDrawing = false))

document

  .querySelector('a')

  .addEventListener(

    'click',

    (event) => (event.target.href = canvas.toDataURL()),

  )

Example 9: Using an Image as a Link

The img tag, which is nested inside the anchor tag, is used to input the details of an image when we want to connect to it. The information we wish to display about the image will be written between the anchor tag on the webpage. The src attribute of the img tag is used to indicate the path of the image.

<body>

    <a href="https://www.google.com">

        <img border="0" alt="google" src="img.png" width="90" height="70">

    </a>

</body>

Output

What is the Correct HTML for Making a Hyperlink?

Example 10: Opening a Link in a New Browser Window

The URL's path should be put into the href property, and the target attribute should be set to _blank if we want the URL to open in a new browser window. We will set all the content we want to appear between the head and end anchor tags that the webpage displays.

<body>

    <a href="https://www.linkedin.com" target="_blank">LinkedIn</a>

</body>

Output

What is the Correct HTML for Making a Hyperlink?

When you click the link, a new window opens.

Skip Links

By using skip links, users can avoid navigation, search, and logo elements and get to the main content by double-clicking. It is usually buried before getting to draw attention.

Skip links can speed up frequent information, including headers and paragraphs. Thus, it is easier for people who access the pages through devices, including voice commands or switch controls, to click twice on the same link.

HTML

<body>

    <a href="#content" class="skip-link">Click to skip to the main content</a>

    <header>

        ---------

    </header>

    <main id="content"> </main> <!-- The link jumps here -->

</body>

CSS

.skip-link {

  position: absolute;

  top: -9em;

}

.skip-link:focus {

  top: 0;

}

Default CSS Settings

The majority of browsers have the "a" tag's default CSS setting set to:

a:link,

a:visited {

  color: (internal value);

  text-decoration: underline;

  cursor: auto;

}

a:link:active,

a:visited:active {

  color: (internal value);

}

Size and Proximity

Links must have a substantially large opening so that the connection mechanism works easily. It is convenient for both touchscreen users and individuals with motor difficulties. The size of the icon should be at least 44x44.

The spaces between anchors should be correct. Spacing the links is recommended because if they are crowded, then the person can click on the wrong one, and it serves as another way to make the page look clean.

Security and Privacy

Target = "blank" is an action that makes the link open in a new window. Nevertheless, the operation is mostly carried out through a Windows attack. Opener can also be one of the outcomes of this management renewal. For safety purposes, one advised to use rel = "noreferrer" and rel = "noopener".

Accessibility

The goal of accessibility is to enable as many people as possible to use websites in a variety of ways, like:

  • Smartphones and tablets.
  • Browsing on the smartwatches or TV set, keep switching them.
  • A relatively old version of phone browsers.
  • Giving an environment on the page for physical disabilities such as those of hearing, vision, movement, and cognitive.

Setting the href property of anchor tags to javascript: void(0) or "#" can be used as buttons by observing the click events. Copying, dragging, opening in a new window or tab, bookmarking and so on leads to removal of benefits from the links. Hence, a href tag should not be used instead of a button.

Ensure the anchor tag code contains the link's destination titles to help visitors understand the content.

Specifications

The platform is designed to offer advertisements and interactive, phrase, and flow content, as pointed out above. Furthermore, it keeps any HTML's event and global attributes.

Conclusion

Links will be linked to the text in a way that allows the user to activate the link seamlessly. Moreover, the gap should also be relevant.

The anchor tag, whose attributes are defined by the sign in HTML, is the appropriate one in case you want to construct a hyperlink.

A hyperlink is a redirection that takes traffic to a different URL, which could be another website, file, or the same page, only in a different spot.

The text is placed between the <a> and </a> tags when inserting a hyperlink, which is represented by the anchor tag <a>.

The listening and speaking skills are applicable on interactive, continue, and sentence levels. The HTML global and event properties are supported, too.