# How to Create a Link in HTML: A Complete Guide Links are the backbone of the web. Every time you click a word or image and land somewhere new, an HTML anchor tag made that happen. Understanding how to build links correctly — and the options available to you — is one of the most foundational skills in web development. ## The Basic HTML Link Structure Every hyperlink in HTML uses the **anchor element**, written as ` `. The minimum working version looks like this: ```html Visit Example ``` Breaking that down: - ` ` — opens the anchor element - `href` — stands for **hypertext reference**; this is the destination URL - The text between the tags — this is the **clickable link text** (also called anchor text) - `` — closes the element That single line is all you need to create a functional link. ## Types of Links You Can Create Not all links point to external websites. HTML supports several link types, and which one you use depends entirely on what you're linking to. ### External Links These point to pages on a different domain: ```html Wikipedia ``` Always use the full URL including `https://` for external destinations. ### Internal Links These link to other pages within your own site. You can use a **relative path** instead of a full URL: ```html About UsContact ``` Relative paths are shorter and easier to maintain — if your domain changes, the links still work. ### Anchor Links (Same-Page Navigation) These jump to a specific section on the same page using an **ID attribute**: ```html Jump to Features
` tag and the entire image becomes clickable: ```html
``` Always include a descriptive `alt` attribute on the image — it's essential for **accessibility** and screen readers. ## Common Mistakes and How to Avoid Them **Missing or broken `href`** — An anchor tag without a valid `href` won't function as a link. Double-check your paths, especially relative ones. **Vague anchor text** — "Click here" tells neither the user nor search engines what the destination is. Descriptive anchor text like "View pricing plans" improves both usability and SEO. **Forgetting the closing tag** — Unlike some HTML elements, ` ` always needs a closing ``. Without it, everything after the tag may become part of the link. **Using `http://` instead of `https://`** — Most modern sites require `https://`. Linking to an insecure URL may produce warnings in browsers or cause the link to fail. **Absolute paths for internal links** — Using your full domain for every internal link works, but relative paths are more portable and easier to manage as a site grows. ## How Links Interact With CSS and JavaScript By default, browsers style links with an underline and blue color for unvisited links, purple for visited. These are purely visual defaults you can override entirely with CSS: ```css a { color: #007bff; text-decoration: none; } a:hover { text-decoration: underline; } ``` JavaScript can also intercept link clicks — useful for single-page applications (SPAs) where you want to navigate without a full page reload. Frameworks like React and Vue have their own link components that wrap this behavior, but the underlying HTML ` ` element remains the foundation. ## Variables That Affect How You Should Write Links 🔗 The right approach to linking isn't universal — it shifts depending on several factors: - **Site type** — A static HTML site, a CMS like WordPress, or a JavaScript framework each handles links differently - **Audience** — Mobile-heavy audiences benefit more from `tel:` links; global audiences may need careful `hreflang` attributes for multilingual SEO - **SEO goals** — Whether you're managing `nofollow`, `sponsored`, or `ugc` attributes matters at scale - **Accessibility requirements** — Sites serving users with disabilities need to prioritize meaningful anchor text and ARIA labels - **Security posture** — Sites handling sensitive data may have stricter rules around external linking A developer building a personal portfolio has very different linking needs than someone managing an e-commerce platform with thousands of product pages and affiliate relationships. The mechanics of the `` tag are simple and consistent. What varies is how you apply them once your use case, audience, and technical environment are factored in.
Features
``` This is how table-of-contents navigation and "back to top" buttons work. ### Email and Phone Links HTML supports `mailto:` and `tel:` as link types: ```html Email UsCall Us ``` Clicking a `mailto:` link opens the user's default email app. A `tel:` link is especially useful on mobile devices. ## Key Attributes That Change Link Behavior Beyond `href`, several attributes give you control over how links behave. | Attribute | What It Does | |---|---| | `target="_blank"` | Opens link in a new tab or window | | `target="_self"` | Opens in the same tab (default behavior) | | `rel="noopener noreferrer"` | Security best practice when using `target="_blank"` | | `rel="nofollow"` | Tells search engines not to pass link authority | | `title="..."` | Adds a tooltip on hover | | `download` | Triggers a file download instead of navigation | ### Why `rel="noopener noreferrer"` Matters 🔒 When you open a link in a new tab using `target="_blank"`, the new page can technically access the original page via JavaScript. Adding `rel="noopener noreferrer"` blocks that access: ```html Open in New Tab ``` This is a widely accepted security best practice for any externally-opening link. ## Linking Images Instead of Text The anchor element isn't limited to wrapping text. Wrap it around an `
``` Always include a descriptive `alt` attribute on the image — it's essential for **accessibility** and screen readers. ## Common Mistakes and How to Avoid Them **Missing or broken `href`** — An anchor tag without a valid `href` won't function as a link. Double-check your paths, especially relative ones. **Vague anchor text** — "Click here" tells neither the user nor search engines what the destination is. Descriptive anchor text like "View pricing plans" improves both usability and SEO. **Forgetting the closing tag** — Unlike some HTML elements, ` ` always needs a closing ``. Without it, everything after the tag may become part of the link. **Using `http://` instead of `https://`** — Most modern sites require `https://`. Linking to an insecure URL may produce warnings in browsers or cause the link to fail. **Absolute paths for internal links** — Using your full domain for every internal link works, but relative paths are more portable and easier to manage as a site grows. ## How Links Interact With CSS and JavaScript By default, browsers style links with an underline and blue color for unvisited links, purple for visited. These are purely visual defaults you can override entirely with CSS: ```css a { color: #007bff; text-decoration: none; } a:hover { text-decoration: underline; } ``` JavaScript can also intercept link clicks — useful for single-page applications (SPAs) where you want to navigate without a full page reload. Frameworks like React and Vue have their own link components that wrap this behavior, but the underlying HTML ` ` element remains the foundation. ## Variables That Affect How You Should Write Links 🔗 The right approach to linking isn't universal — it shifts depending on several factors: - **Site type** — A static HTML site, a CMS like WordPress, or a JavaScript framework each handles links differently - **Audience** — Mobile-heavy audiences benefit more from `tel:` links; global audiences may need careful `hreflang` attributes for multilingual SEO - **SEO goals** — Whether you're managing `nofollow`, `sponsored`, or `ugc` attributes matters at scale - **Accessibility requirements** — Sites serving users with disabilities need to prioritize meaningful anchor text and ARIA labels - **Security posture** — Sites handling sensitive data may have stricter rules around external linking A developer building a personal portfolio has very different linking needs than someone managing an e-commerce platform with thousands of product pages and affiliate relationships. The mechanics of the `` tag are simple and consistent. What varies is how you apply them once your use case, audience, and technical environment are factored in.