Introduction to <a> anchor tags

The HTML <a> element, commonly referred to as the anchor tag, is a foundational element in web development used to create hyperlinks. These hyperlinks can navigate users to various destinations, such as other web pages, downloadable files, email addresses, specific sections within the same page, or any URL-accessible resource.

Copy to clipboard
 <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Styled Code Blocks</title>
</head>
<body>
<h1>Hello, World!</h1>
<p>The code illustrates the use of the HTML `<a>` tag to create hyperlinks with custom classes. Each link redirects users to the URL `https://www.levoriclearn.com/` and is styled using the `<button>` class for a consistent and professional appearance.</p>
<a href="https://www.levoriclearn.com" class="button">Link 1</a>
<a href="https://www.levoriclearn.com/" class="button">Link 2</a>
<a href="https://www.levoriclearn.com/" class="button">Link 3</a>
<a href="https://www.levoriclearn.com/" class="button">Link 4</a>
<a href="https://www.levoriclearn.com/" class="button">Link 5</a>
<a href="https://www.levoriclearn.com/" class="button">Link 6</a>
<a href="https://www.levoriclearn.com/" class="button">Link 7</a>
<a href="https://www.levoriclearn.com/" class="button">Link 8</a>
<a href="https://www.levoriclearn.com/" class="button">Link 9</a>
<a href="https://www.levoriclearn.com/" class="button">Link 10</a>
</body>
</html>
Copy to clipboard
 .button {
    display: inline-block;
    padding: 10px 20px;
    font-size: 16px;
    color: white;
    background-color: #007bff;
    text-align: center;
    text-decoration: none;
    border-radius: 5px;
    margin: 5px;
    transition: background-color 0.3s;
}
.button:hover {
    background-color: #0056b3;
}

Attributes

AttributesDescription
hrefSpecifies the URL of the page the link goes to
targetSpecifies where to open the linked document
relSpecifies the relationship between the current document and the linked document
downloadSpecifies that the target will be downloaded when the user clicks on the hyperlink
hreflangSpecifies the language of the linked document
typeSpecifies the media type (MIME type) of the linked document
referrerpolicySpecifies the referrer information to be included with the request
pingSpecifies a space-separated list of URLs to be notified if the user follows the hyperlink
mediaSpecifies what media/device the linked document is optimized for
Copy to clipboard
 
<!DOCTYPE html>
    <html lang="en">
      <head>
        <meta charset="UTF-8">
          <meta name="viewport" content="width=device-width, initial-scale=1.0">
            <title>Styled Code Blocks</title>
          </head>
        <body>
      <a href="https://www.levoriclearn.com/" target="_blank">visit url Or visit examples site</a>
    <p>This is an example of a preformatted text block.</p>
  </body>
</html>
TargetDescription
_self (default)Opens the link in the same tab or window.
_blankOpens the link in a new tab or window.
_parentOpens the link in the parent frame.
_topOpens the link in the full body of the window.
Copy to clipboard
 
<!DOCTYPE html>
  <html lang="en">
    <head>
      <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
          <title>Styled Code Blocks</title>
        </head>
      <body>
    <a href="https://www.levoriclearn.com/" target="_blank" rel="noopener noreferrer">visit url Or visit examples site</a>
  <p>This is an example of a preformatted text block.</p>
</body>
</html>
Rel AttributeDescription
noopenerPrevents the new page from being able to access the window.openerproperty.
noreferrerPrevents the browser from sending the HTTP referer header.
nofollowTells search engines not to follow the link.

Global Attributes

AttributesDescription
accesskeySpecifies a shortcut key to activate or focus an element.
autocapitalizeControls whether and how text input is automatically capitalized.
classSpecifies one or more class names for the element, allowing CSS styling and JavaScript manipulation.
contenteditableSpecifies whether the content of an element is editable or not.
contextmenuSpecifies a context menu for the element.
dirDefines the text direction. Possible values are "ltr" (left-to-right), "rtl" (right-to-left), and "auto".
draggableSpecifies whether an element is draggable. Possible values are "true" or "false".
enterkeyhintSpecifies the action label or icon to be shown for the enter key on virtual keyboards.
hiddenIndicates that the element is not yet, or is no longer, relevant. The browser does not display elements that have the `hidden` attribute set.
idSpecifies a unique identifier for the element.
inputmodeProvides a hint to browsers for which virtual keyboard configuration to use when editing this element or its descendants.
isAllows you to specify the type of custom element.
langSpecifies the language of the element's content.
nonceA cryptographic nonce ("number used once") that can be used by Content Security Policy (CSP) to determine whether or not a given fetch will be allowed to proceed.
partSpecifies the element’s part in the shadow DOM.
slotAssigns a slot in a shadow DOM shadow tree.
spellcheckIndicates whether the element is subject to spell checking.
styleProvides inline CSS styling for the element.
tabindexSpecifies the tab order of the element.
titleAdds extra information about the element, displayed as a tooltip when hovering over the element.
translateSpecifies whether the content of the element should be translated. Possible values are "yes" or "no".
HTML AttributesGlobal AttributesEvent Attributes
To view the full list
To view the full list
To view the full list
elements Chrome BrowsersMicrosoft Edge BrowserFirefox BrowsersSafari BrowserOpera Browser
<a>YesYesYesYesYes