Advertisement
Home Open Editor ❯

HTML <a> href Attribute

Example

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

Try this code ❯

Meaning

Hyperlink of the page used to navigate.

Notes: You can use href="#" to link to the top of the current page!


Standard Syntax

<a href="URL">


Advertisement

Attribute Values

Value Description
URL

Value can be

  • An absolute URL - navigate to within or another web site ( href="http://www.example.com/index.html")
  • A relative URL - navigate to within a web site ( href="index.html")
  • Link to an element with a specified id within the page ( href="#section")
  • Protocols ( https://, ftp://, mailto:, file:, etc..)
  • A JavaScripts ( href="javascript:alert('Hello');")

More Examples

How to use an image as a hyperlink

Example

<a href="https://www.google.com">
<img alt="Google" src="img/image.jpeg" width="200" height="200">
</a>

Try this code ❯

How to open a hyperlink in a new browser window.

Example

<a href="https://www.google.com" target="_blank">Visit google.com!</a>

Try this code ❯

How to hyperlink to an email address

Example

<a href="mailto:username@email.com">Send email</a>

Try this code ❯

How to hyperlink to on the same page

Example

<a href="#chapter2">Go to Chapter 2</a>

Try this code ❯

How to hyperlink to a JavaScript

Example

<a href="javascript:alert('Hello World!');">Click me to Execute.</a>

Try this code ❯

Home Open Editor ❯
Advertisement