MaraHTML
Coding resources, tutorials and more.
HTML Links
Share this page:
Links are created with the <a> element which has an attribute called href. The value of this attribute is the url of the page you're linking to. Users can click on anything (be it text or an image), between the opening <a> and closing </a> tags.
If you want to style links based on if they've been visited, or are active, please see the pseudo class tutorial. (You need to know CSS for this first).
Linking to other sites
<a href="http://www.marapets.com/">Marapets</a>
Linking to other pages on the same site
Note, this doesn't work on marasites, it's only for if you have your own site.
When linking to pages within the same site, you don't need to specify the domain name in the URL. You can use a shorthand known as a relative URL. If the page of the site is in the same folder, the relative URL is simply the file name. If it's in a different folder you have to include the file path.
<a href="htmlintro.html">HTML Intro</a>
Linking to a specific part of a page
Note: Previously this was done with using the name attribute, with the <a> element, this is not supported by HTML5.
Before you do this you need to use the id attribute on the element you want to the link to go to.
You can also link to a specific part of a different page, provided it has an id attribute.
Lists
Opening links in a new tab/window
To do this you use the target attribute, and assign it the value of '_blank'.