- HTML Tutorial
- HTML Introduction
- HTML Editors
- HTML Basic
- HTML Comments
- HTML Elements
- HTML Attributes
- HTML Id & Classes
- HTML Skeletal Tags
- HTML Heading Tags
- HTML Paragraph Tag
- HTML Line Break Tag
- HTML Pre Tag
- HTML Anchor Tag
- HTML Image Tag
- HTML Horizontal Line Tag
- HTML Inline & Block
- HTML Inline
- HTML Block
- HTML LInks
- HTML Images
- HTML Formatting
- HTML Head
- HTML Head
- HTML Title
- HTML Meta Elements
- HTML Favicon
- HTML Style
- HTML List
- HTML Lists
- HTML Unordered List
- HTML Ordered List
- HTML Description List
- HTML Table
- HTML Tables
- HTML Table Headers
- HTML Table Styling
- HTML Table Colgroup
- HTML Form
- HTML Forms
- HTML Form Elements
- HTML Form Attributes
- HTML Input Types
- HTML Input Attributes
- HTML Form Actions
- HTML Semantic
- HTML Semantics
- HTML Graphics & Media
- HTML Canvas
- HTML SVG
- HTML Video & Audio
- HTML Plug-ins
- iFrames in HTML
- HTML Miscellaneous Tags
- HTML Code Tag
- HTML Entities
- HTML Quotation
- HTML Global Attributes
- HTML Obsolete Tags
- HTML Emojis
- HTML Symbols
- HTML Events
- HTML Colors
HTML Links
In web development, links are the "glue" that hold the internet together. Created using the <a> (anchor) element, links allow users to navigate between pages, jump to specific sections of a document, or even trigger actions like downloading a file or sending an email.
- Basic Link:
The most common use of a link is to send a user to another website. This is done using the href (hypertext reference) attribute, which tells the browser exactly where the user should go when they click the text.
<a href="https://www.example.com">Visit Example Website</a>
- Linking to a Different Page on the Same Site:
When you are building a multi-page website, you don't need to type the full URL (absolute path) for every page. Instead, you can use a relative path to point to a file within your own project folder.
<a href="/about">About Us</a>
/contact instead of https://mysite.com/contact) for internal links. This ensures your links continue to work even if you change your domain name or move from a local staging environment to a live server.
- Linking to a Specific Section on a Page:
Sometimes called "bookmarks" or "anchor links," these allow users to jump to a specific part of the current page. This is incredibly useful for long-form articles or "Back to Top" buttons. To make this work, the target element must have a unique id.
<!-- The link -->
<a href="#section-id">Jump to Section</a>
<!-- The target -->
<div id="section-id">This is where the user will land.</div>
#) in the href attribute. If you write href="section-id", the browser will look for a page named "section-id" instead of jumping to the ID on the current page.
- Opening Links in a New Tab:
By default, links open in the same tab. If you want to keep the user on your site while they view an external resource, you can use the target="_blank" attribute.
<a href="https://www.example.com" target="_blank">Visit Example Website</a>
target="_blank" for external sites or when a user is in the middle of a process (like filling out a form) that shouldn't be interrupted.
- Linking an Email Address:
You can create a link that automatically opens the user's default email program (like Outlook or Gmail) with your email address already filled in the "To" field by using the mailto: prefix.
<a href="mailto:[email protected]">Email Us</a>
mailto:[email protected]?subject=Inquiry to save your users even more time.
- Linking to a File (e.g., PDF, Image):
Links aren't just for HTML pages. You can link directly to PDF files, ZIP archives, or images. Browsers will usually try to open PDFs in a new tab, while other files might trigger a download automatically.
<a href="document.pdf">Download PDF</a>
- Using Images as Links:
In modern UI design, we often use logos or icons as clickable elements. To do this, simply wrap your <img> tag inside an <a> tag.
<a href="https://www.example.com">
<img src="logo.png" alt="Company Logo">
</a>
alt attribute of the image describes where the link goes. If the image is a logo, the alt text should be "Home" or "Company Name Home" so screen readers can narrate the destination.
- Link with a Title Attribute:
The title attribute provides extra information about a link. When a user hovers their mouse over the link, a small tooltip appears after a short delay.
<a href="https://www.example.com" title="Visit Example Website">Visit Example Website</a>
HTML links are the foundation of the web's structure. Whether you are building a simple navigation menu, a table of contents for a blog post, or a call-to-action button, mastering these attributes ensures your website is functional, accessible, and user-friendly.