How to Create A Hyperlink In HTML?

10 minutes read

To create a hyperlink in HTML, you can use the tag along with the href attribute. The href attribute specifies the destination URL or the file path you want to link to.


Here is an example of HTML code to create a hyperlink:

1
<a href="https://example.com">Click here</a>


In the above code, the text "Click here" will be displayed as a clickable link. When clicked, it will take the user to the URL specified in the href attribute, which, in this case, is "https://example.com".


You can also link to local files by providing the file path instead of a URL. For example:

1
<a href="/path/to/file.pdf">Download file</a>


In this case, clicking on the link will prompt the user to download the file "file.pdf" from the specified file path on the server.


Additionally, you can add a target attribute to specify how the linked page should open. For example, you can set it to "_blank" to open in a new browser tab or window:

1
<a href="https://example.com" target="_blank">Open in new tab</a>


This will cause the linked page to open in a new browser tab or window when clicked.


By using the tag and the href attribute, you can easily create hyperlinks in HTML to connect your web pages and files.

Best HTML & CSS Books to Read in 2024

1
Web Design with HTML, CSS, JavaScript and jQuery Set

Rating is 5 out of 5

Web Design with HTML, CSS, JavaScript and jQuery Set

2
HTML and CSS QuickStart Guide: The Simplified Beginners Guide to Developing a Strong Coding Foundation, Building Responsive Websites, and Mastering ... Web Design (QuickStart Guides™ - Technology)

Rating is 4.9 out of 5

HTML and CSS QuickStart Guide: The Simplified Beginners Guide to Developing a Strong Coding Foundation, Building Responsive Websites, and Mastering ... Web Design (QuickStart Guides™ - Technology)

3
HTML, CSS, and JavaScript All in One: Covering HTML5, CSS3, and ES6, Sams Teach Yourself

Rating is 4.8 out of 5

HTML, CSS, and JavaScript All in One: Covering HTML5, CSS3, and ES6, Sams Teach Yourself

4
Head First HTML and CSS: A Learner's Guide to Creating Standards-Based Web Pages

Rating is 4.7 out of 5

Head First HTML and CSS: A Learner's Guide to Creating Standards-Based Web Pages

5
HTML, CSS & JavaScript in easy steps

Rating is 4.6 out of 5

HTML, CSS & JavaScript in easy steps

6
HTML and CSS: Visual QuickStart Guide

Rating is 4.5 out of 5

HTML and CSS: Visual QuickStart Guide

7
HTML & CSS: The Complete Reference, Fifth Edition (Complete Reference Series)

Rating is 4.4 out of 5

HTML & CSS: The Complete Reference, Fifth Edition (Complete Reference Series)

8
Beginning HTML and CSS

Rating is 4.3 out of 5

Beginning HTML and CSS

9
HTML, XHTML and CSS For Dummies

Rating is 4.2 out of 5

HTML, XHTML and CSS For Dummies

10
HTML & CSS: The Good Parts: Better Ways to Build Websites That Work (Animal Guide)

Rating is 4.1 out of 5

HTML & CSS: The Good Parts: Better Ways to Build Websites That Work (Animal Guide)


What is a hyperlink in HTML?

A hyperlink in HTML is a mechanism that allows users to navigate and link to different sections or pages within a website or to external websites. It is typically displayed as clickable text or an image that, when clicked, directs the user to another location specified by its URL (Uniform Resource Locator). Hyperlinks are created using the <a> (anchor) tag and the "href" attribute to specify the destination URL.


How to create a hyperlink that scrolls to a specific point on the current page in HTML?

To create a hyperlink that scrolls to a specific point on the current page in HTML, you can make use of HTML anchor tags along with some CSS and JavaScript code.


Here's an example:

  1. Add an ID to the element you want to scroll to. This can be any HTML element such as a heading or a specific section.
1
2
<h2 id="section-1">Section 1</h2>
<!-- Content of section 1 goes here -->


  1. Create the hyperlink that will trigger the scroll.
1
<a href="#section-1">Go to Section 1</a>


In this example, the href attribute is set to #section-1, which matches the ID of the element defined in step 1.

  1. Apply some CSS to ensure the scrolling effect is smooth.
1
2
3
html {
  scroll-behavior: smooth;
}


  1. (Optional) If the smooth scrolling effect is not supported by all browsers, you may need to add a JavaScript polyfill. You can use the smoothscroll polyfill by adding this JavaScript code in the section of your HTML code.
1
<script src="https://cdnjs.cloudflare.com/ajax/libs/SmoothScroll/1.4.10/SmoothScroll.min.js" integrity="sha512-sdxYtKMz2skwWZsIB6g3G/pNTbtWgkNJ/l24xsSbY2BWd8Pb8BGj8wjf5TjJ5AEhQAPf6M1CAEVdoRFJWqxg7g==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>


That's it! With these steps, you should now have a hyperlink that scrolls to a specific point on the current page when clicked.


How to create a hyperlink that opens a PDF document in HTML?

To create a hyperlink that opens a PDF document in HTML, you can use an <a> tag with the href attribute pointing to the URL of the PDF file. Here is an example:

1
<a href="path/to/your/pdf/document.pdf">Open PDF Document</a>


Replace path/to/your/pdf/document.pdf with the actual file path or URL of your PDF document.


If your PDF file is in the same directory as your HTML file, you can simply specify the file name:

1
<a href="document.pdf">Open PDF Document</a>


Additionally, if you want the PDF document to open in a new browser tab or window, you can add the target="_blank" attribute to the <a> tag:

1
<a href="document.pdf" target="_blank">Open PDF Document</a>


This will ensure that the PDF document opens in a new tab or window instead of replacing the current page.


How to create a link to download a file in HTML?

To create a link to download a file in HTML, you can use the <a> (anchor) element with the download attribute. Here is an example:

1
<a href="path_to_your_file" download>Click here to download the file</a>


Replace "path_to_your_file" with the actual path to your file. Additionally, you can provide a custom name for the downloaded file by adding a value to the download attribute like this:

1
<a href="path_to_your_file" download="custom_filename">Click here to download the file</a>


Replace "custom_filename" with the desired name for the downloaded file.

Facebook Twitter LinkedIn Whatsapp Pocket

Related Posts:

Commenting in HTML: To add comments in HTML, you can use the &lt;!-- --&gt; tags. Anything placed between these tags is considered a comment and will not be visible on the webpage. Comments are useful for adding explanatory notes or reminders within your HTML ...
Creating a table in HTML involves using the &lt;table&gt;, &lt;tr&gt;, &lt;th&gt;, and &lt;td&gt; tags to define the structure and content of the table. Here&#39;s a step-by-step guide on how to create a table in HTML:Start by opening a new HTML document in a ...
To create a parallax background image, follow these steps:Choose an image that you want to use as a background for your website or webpage. Make sure it is suitable for the desired parallax effect. Open your preferred text editor or HTML editor and create a ne...