HTML href Attribute

❮ HTML Attributes

Example

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

Meaning

The Hyperlink of the page used to navigate.




Standard Syntax

<element href="URL">



Browser Support




Status




Applies to:

The href attribute can be used on the following element:

Element Attribute
<a> href
<area> href
<base> href
<link> href






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');")



<area> Example

The Hyperlink of the page used to navigate.

Note: If the href attribute is not exist and the <area> tag will not be a hyperlink.

<img src="img/desk.jpg" usemap="#image-map">

<map name="image-map">
    <area target="_blank" alt="Computer" title="Computer" href="img/computer.png" coords="365,99,905,783" shape="rect">
    <area target="_blank" alt="Cup" title="Cup" href="img/cup.png" coords="1047,672,97" shape="circle">
    <area target="_blank" alt="Mobile" title="Mobile" href="img/mobile.png" coords="960,385,1040,541" shape="rect">
    <area target="_blank" alt="Book" title="Book" href="img/book.png" coords="175,426,96,527,20,664,232,755,298,628,364,505" shape="poly">
</map>



<base> Example

The Hyperlink of the page used to all relative URLs in the page.

<head>
	<base href="img/" target="_blank">
</head>
<body>
	<img src="image.jpeg" width="50" height="50" alt="demo">
</body>



<link> Example

The href attribute specifies the URL of the linked resource. A URL might be absolute or relative.

<head>
	<link rel="stylesheet" href="demo/demo.css">
</head>
❮ HTML Attributes