Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for HTML - Creating hyperlinks
Lachelle Zhang
Lachelle Zhang

Posted on

     

HTML - Creating hyperlinks

Creating hyperlinks

<a> element

A basic link is created by wrapping the text or other content inside an<a> element and using thehref(hypertext Reference) attribute that contains the web address.

<p>I'm creating a link to<ahref="www.google.com">the Google homepage</a>.</p>
Enter fullscreen modeExit fullscreen mode

This gives us the following result:

I'm creating a link tothe Googlehomepage.

  • title attributeThe title contains additional information about the link, such as which kind of information the page contains, or things to be aware of on the web site.Hovering over the link displays the title.
<p>    I'm creating a link to<ahref="www.google.com"title="The best place for searching information">the Google homepage</a>.</p>
Enter fullscreen modeExit fullscreen mode
<p>I'm creating a link to <a href="www.google.com" title="The best place for searching information">the Google homepage</a>.</p>
Enter fullscreen modeExit fullscreen mode
  • download attributeWhen you are linking to a resource that's to be downloaded rather than opened in the browser, you can use thedownload attribute to provide a default save filename. Here's an example with a download link to the latest Windows version of Firefox:
<ahref="https://download.mozilla.org/?product=firefox-latest-ssl&os=win64&lang=en-US"download="firefox-latest-64bit-installer.exe">    Download Latest Firefox for Windows (64-bit) (English, US)</a>
Enter fullscreen modeExit fullscreen mode

This gives us the following result:
Download Latest Firefox for Windows (64-bit) (English, US)

  • E-mail linksIt's possible to create links or buttons that, when clicked, open a new outgoing email message rather than linking to a resource or page. This is done using the<a> element and themailto: URL scheme. In its most basic and commonly used form, amailto: link indicates the email address of the intended recipient.
<ahref="mailto:nowhere@gmail.com">Send email to nowhere</a>
Enter fullscreen modeExit fullscreen mode

This results in a link that looks like this:Send email to nowhere
In fact, the email address is optional. If you omit it and yourhref is "mailto:", a new outgoing email window will be opened by the user's email client with no destination address.
Specifying details
In addition to the email address, you can provide other information. The most commonly used of these are "subject", "cc", and "body".

<ahref="mailto:nowhere@mozilla.org?cc=name2@rapidtables.com&bcc=name3@rapidtables.com&subject=The%20subject%20of%20the%20email&body=The%20body%20of%20the%20email">    Send mail with cc, bcc, subject and body</a>
Enter fullscreen modeExit fullscreen mode

%20 represents space.

Document fragments

It's possible to link to a specific part of an HTML document, known as adocument fragment, rather than just to the top of the document. To do this you first have to assign anid attribute to the element you want to link to. To link to that specificid, you'd include it at the end of the URL, preceded by a hash symbol(#).

<h1id="h1">I am h1</h1><ahref="#h1">Heading to h1</a>
Enter fullscreen modeExit fullscreen mode

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Front-end | Web development | Fullstack | Music nerd
  • Education
    Ochanomizu University
  • Work
    Student
  • Joined

More fromLachelle Zhang

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp