 
    
<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>anchor Archives - Complete, Concrete, Concise</title>
	<atom:link href="https://complete-concrete-concise.com/tag/anchor/feed/" rel="self" type="application/rss+xml" />
	<link>https://complete-concrete-concise.com/tag/anchor/</link>
	<description>Practical Information Without The Bloat</description>
	<lastBuildDate>Sun, 12 Mar 2023 13:32:13 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9</generator>
	<item>
		<title>Hyperlinks in HTML</title>
		<link>https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/hyperlinks-in-html/</link>
		
		<dc:creator><![CDATA[richardsplanet]]></dc:creator>
		<pubDate>Mon, 02 Apr 2018 13:52:24 +0000</pubDate>
				<category><![CDATA[Front-End Basics]]></category>
		<category><![CDATA[anchor]]></category>
		<category><![CDATA[front-end]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[hyperlinks]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[webdev]]></category>
		<guid isPermaLink="false">https://complete-concrete-concise.com/?p=3512</guid>

					<description><![CDATA[<p>Hyperlinks were the core idea behind the development of the World Wide Web.</p>
<p>The post <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/hyperlinks-in-html/">Hyperlinks in HTML</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div class="preamble">It has taken a while, but we’ve finally gotten to <strong>hyperlinks</strong> &#8211; the core idea behind the World Wide Web.</div>
<p>Hyperlinks are connections between two resources:</p>
<ol type="1">
<li>the current document</li>
<li>and some other resource the user can either navigate to or download</li>
</ol>
<p>The HTML tag is <span class="kbd">&lt;a&gt;</span> and it stands for <strong>anchor</strong>.</p>
<h2>Contents</h2>
<ol type="1">
<li><a href="#a-element"><span class="kbd">&lt;a&gt;</span> Element</a>
<ol type="1">
<li><a href="#href">href</a></li>
<li><a href="#target">target</a></li>
<li><a href="#download">download</a></li>
</ol>
</li>
<li><a href="#practical-considerations">Practical Considerations</a></li>
<li><a href="#summary">Summary</a></li>
<li><a href="#playing-around">Playing Around</a></li>
<li><a href="#references">References</a></li>
</ol>
<h2 id="a-element"><span class="kbd">&lt;a&gt;</span> Element</h2>
<p>As with most HTML tags, hyperlinks are written with a starting <span class="kbd">&lt;a&gt;</span> and ending <span class="kbd">&lt;/a&gt;</span> tags. Contained between those tags is the content that will serve as a hyperlink. Normally, it is some text, however, it can be an image, or any other part of the document which can be contained between the start and end tags.</p>
<div id="cb1" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb1-1" class="sourceLine" data-line-number="1"></a><span class="kw">&lt;a&gt;</span>This is a hyperlink<span class="kw">&lt;/a&gt;</span></code></pre>
</div>
<p>While the example above is a hyperlink, it is non-functional because it does not link to another resource &#8211; it simply defines a link. To make a link functional, we need to add an <strong>attribute</strong> to the <span class="kbd">&lt;a&gt;</span> tag that specifies the URL of the resource.<br />
Using the <strong>anchor</strong> tag in this way indicates that it is a placeholder for a future hyperlink.</p>
<h3 id="href">href</h3>
<p>The <strong>href</strong> attribute stands for <strong>hyperlink reference</strong> and provides the resource URL:</p>
<div id="cb2" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb2-1" class="sourceLine" data-line-number="1"></a><span class="kw">&lt;p&gt;</span>A safe website to use in examples is
<a id="cb2-2" class="sourceLine" data-line-number="2"></a>  <span class="kw">&lt;a</span><span class="ot"> href=</span><span class="st">"http://example.com"</span><span class="kw">&gt;</span>example.com<span class="kw">&lt;/a&gt;</span>
<a id="cb2-3" class="sourceLine" data-line-number="3"></a><span class="kw">&lt;/p&gt;</span></code></pre>
</div>
<p>The URL can be an absolute URL or a relative URL.<br />
An absolute URL is the complete URL, e.g.:</p>
<ul>
<li>http://example.com</li>
<li>https://complete-concrete-concise.com</li>
</ul>
<p>A relative URL is a partial URL relative to the current document location. Relative paths follow the Unix / Linux convention:</p>
<ul>
<li><strong>/</strong> &#8211; the root directory. This is the same as the domain. For example:
<div id="cb3" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb3-1" class="sourceLine" data-line-number="1"></a><span class="kw">&lt;a</span><span class="ot"> href=</span><span class="st">"/"</span><span class="kw">&gt;</span>Take me to the home page<span class="kw">&lt;/a&gt;</span></code></pre>
</div>
<p>will jump to the home page of the domain.</li>
<li><strong>.</strong> – the current path. The paths <strong>image.jpg</strong> and <strong>./image.jpg</strong> both refer to the file <strong>image.jpg</strong> in the current directory. For example:
<div id="cb4" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb4-1" class="sourceLine" data-line-number="1"></a><span class="kw">&lt;a</span><span class="ot"> href=</span><span class="st">"./image.jpg"</span><span class="kw">&gt;</span>Click to load the image.<span class="kw">&lt;/a&gt;</span>
<a id="cb4-2" class="sourceLine" data-line-number="2"></a><span class="kw">&lt;a</span><span class="ot"> href=</span><span class="st">"image.jpg"</span><span class="kw">&gt;</span>Click to load the image.<span class="kw">&lt;/a&gt;</span></code></pre>
</div>
<p>will both load the file <strong>image.jpg</strong> which is located in the same directory (location) as the <strong>.html</strong> file.</li>
<li><strong>..</strong> – one level up. So <strong>../img/image.jpg</strong> refers to the file <strong>image.jpg</strong> which is located in the <strong>img</strong> folder which can be accessed by going up one directory level. In other words, the current directory and the <strong>img</strong> directory are siblings. For example:
<div id="cb5" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb5-1" class="sourceLine" data-line-number="1"></a><span class="kw">&lt;a</span><span class="ot"> href=</span><span class="st">"../img/image.jpg"</span><span class="kw">&gt;</span>Click to load the image<span class="kw">&lt;/a&gt;</span></code></pre>
</div>
<p>will load the file <strong>image.jpg</strong> which is located in the folder <strong>img</strong> which can be accessed by going up one directory level.</li>
</ul>
<p>You have seen that <strong>anchors</strong> can be used to navigate to another page or resource, however, they can also be used to navigate to locations in a document &#8211; the <strong>Table of Contents</strong> at the top of this article is an example.<br />
To navigate to a portion of a document, you need two things:</p>
<ol type="1">
<li>an <strong>identifier</strong> in the document which identifies the location</li>
<li>a <strong>hyperlink</strong> to that identifier.</li>
</ol>
<p>The <strong>identifier</strong> is an attribute you add to an opening HTML tag:</p>
<div id="cb6" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb6-1" class="sourceLine" data-line-number="1"></a><span class="kw">&lt;p</span><span class="ot"> id=</span><span class="st">"jump-here"</span><span class="kw">&gt;</span>Some text we can jump to.<span class="kw">&lt;/p&gt;</span></code></pre>
</div>
<p>The <strong>id</strong> attribute value is <strong>jump-here</strong> and can be used as the value to the <strong>href</strong> attribute. However, there are a few provisos:</p>
<ol type="1">
<li>The <strong>id</strong> value <strong>must</strong> be unique. It is incorrect to have two ids with the same value in the document.</li>
<li>The <strong>id</strong> value <strong>must not</strong> contain spaces.</li>
<li>The <strong>id</strong> value <strong>must</strong> contain at least one character.</li>
<li>To be safe, use only:
<ul>
<li>letters</li>
<li>digits</li>
<li>underscores (_)</li>
<li>hyphens (-)</li>
</ul>
</li>
<li>To be <em>extra</em> safe, ensure the <strong>id</strong> value begins with a letter or underscore (_)</li>
<li>The <strong>id</strong> value is case-insensitive, so, <strong>jump-here</strong> is the same as <strong>JUMP-HERE</strong><a id="fnref1" class="footnote-ref" href="#fn1"><sup>1</sup></a></li>
</ol>
<p>To reference an internal <strong>id</strong> in a link, you need to preface the name with the pound sign (#):</p>
<div id="cb7" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb7-1" class="sourceLine" data-line-number="1"></a><span class="kw">&lt;a</span><span class="ot"> href=</span><span class="st">"#jump-here"</span><span class="kw">&gt;</span>Jump to interesting part<span class="kw">&lt;/a&gt;</span></code></pre>
</div>
<p>We can put this all together and create a simple table of contents:</p>
<div id="cb8" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb8-1" class="sourceLine" data-line-number="1"></a><span class="kw">&lt;h2&gt;</span>Table of Contents<span class="kw">&lt;/h2&gt;</span>
<a id="cb8-2" class="sourceLine" data-line-number="2"></a><span class="kw">&lt;ol&gt;</span>
<a id="cb8-3" class="sourceLine" data-line-number="3"></a>  <span class="kw">&lt;li&gt;&lt;a</span><span class="ot"> href=</span><span class="st">"#topic1"</span><span class="kw">&gt;</span>Topic 1<span class="kw">&lt;/a&gt;&lt;/li&gt;</span>
<a id="cb8-4" class="sourceLine" data-line-number="4"></a>  <span class="kw">&lt;li&gt;&lt;a</span><span class="ot"> href=</span><span class="st">"#topic2"</span><span class="kw">&gt;</span>Topic 2<span class="kw">&lt;/a&gt;&lt;/li&gt;</span>
<a id="cb8-5" class="sourceLine" data-line-number="5"></a>  <span class="kw">&lt;li&gt;&lt;a</span><span class="ot"> href=</span><span class="st">"#topic3"</span><span class="kw">&gt;</span>Topic 3<span class="kw">&lt;/a&gt;&lt;/li&gt;</span>
<a id="cb8-6" class="sourceLine" data-line-number="6"></a>  <span class="kw">&lt;li&gt;&lt;a</span><span class="ot"> href=</span><span class="st">"#topic4"</span><span class="kw">&gt;</span>Topic 4<span class="kw">&lt;/a&gt;&lt;/li&gt;</span>
<a id="cb8-7" class="sourceLine" data-line-number="7"></a><span class="kw">&lt;/ol&gt;</span>
<a id="cb8-8" class="sourceLine" data-line-number="8"></a>
<a id="cb8-9" class="sourceLine" data-line-number="9"></a><span class="kw">&lt;p&gt;</span>Just some padding text, for no other purpose than
<a id="cb8-10" class="sourceLine" data-line-number="10"></a>  having some text.<span class="kw">&lt;/p&gt;</span>
<a id="cb8-11" class="sourceLine" data-line-number="11"></a>
<a id="cb8-12" class="sourceLine" data-line-number="12"></a><span class="kw">&lt;h2</span><span class="ot"> id=</span><span class="st">"topic1"</span><span class="kw">&gt;</span>Topic 1<span class="kw">&lt;/h2&gt;</span>
<a id="cb8-13" class="sourceLine" data-line-number="13"></a>
<a id="cb8-14" class="sourceLine" data-line-number="14"></a><span class="kw">&lt;p&gt;</span>It is nice for each section to have some content.
<a id="cb8-15" class="sourceLine" data-line-number="15"></a>  It doesn't need to be long, just long enough.<span class="kw">&lt;/p&gt;</span>
<a id="cb8-16" class="sourceLine" data-line-number="16"></a>
<a id="cb8-17" class="sourceLine" data-line-number="17"></a><span class="kw">&lt;h2</span><span class="ot"> id=</span><span class="st">"topic2"</span><span class="kw">&gt;</span>Topic 2<span class="kw">&lt;/h2&gt;</span>
<a id="cb8-18" class="sourceLine" data-line-number="18"></a>
<a id="cb8-19" class="sourceLine" data-line-number="19"></a><span class="kw">&lt;p&gt;</span>The content in <span class="kw">&lt;strong&gt;</span>Topic 2<span class="kw">&lt;/strong&gt;</span> should
<a id="cb8-20" class="sourceLine" data-line-number="20"></a>not be the same as in <span class="kw">&lt;strong&gt;</span>Topic 1<span class="kw">&lt;/strong&gt;</span>.<span class="kw">&lt;/p&gt;</span>
<a id="cb8-21" class="sourceLine" data-line-number="21"></a>
<a id="cb8-22" class="sourceLine" data-line-number="22"></a><span class="kw">&lt;h2</span><span class="ot"> id=</span><span class="st">"topic3"</span><span class="kw">&gt;</span>Topic 3<span class="kw">&lt;/h2&gt;</span>
<a id="cb8-23" class="sourceLine" data-line-number="23"></a>
<a id="cb8-24" class="sourceLine" data-line-number="24"></a><span class="kw">&lt;p&gt;</span>After a while, it gets hard to come up with new
<a id="cb8-25" class="sourceLine" data-line-number="25"></a>content. This is why people use <span class="kw">&lt;i&gt;</span>lorem ipsum<span class="kw">&lt;/i&gt;&lt;/p&gt;</span>
<a id="cb8-26" class="sourceLine" data-line-number="26"></a>
<a id="cb8-27" class="sourceLine" data-line-number="27"></a><span class="kw">&lt;h2</span><span class="ot"> id=</span><span class="st">"topic4"</span><span class="kw">&gt;</span>Topic 4<span class="kw">&lt;/h2&gt;</span>
<a id="cb8-28" class="sourceLine" data-line-number="28"></a>
<a id="cb8-29" class="sourceLine" data-line-number="29"></a><span class="kw">&lt;p&gt;</span>Lorem ipsum dolor sit amet, eum invenire erroribus
<a id="cb8-30" class="sourceLine" data-line-number="30"></a>  id. At solum tamquam voluptatum his. Id ius omnis
<a id="cb8-31" class="sourceLine" data-line-number="31"></a>  labitur adipiscing, ut tollit discere deseruisse per.
<a id="cb8-32" class="sourceLine" data-line-number="32"></a>  Ea accumsan reprimique concludaturque eam, ut sed
<a id="cb8-33" class="sourceLine" data-line-number="33"></a>  suas consetetur. Cum imperdiet referrentur in. Usu
<a id="cb8-34" class="sourceLine" data-line-number="34"></a>  postulant philosophia id.<span class="kw">&lt;/p&gt;</span></code></pre>
</div>
<p>Notice that each topic header has a unique id value and to navigate to those ids, we prepend the pound symbol to the name in the <strong>href</strong> attribute.<br />
You can also use <strong>anchors</strong> and <strong>ids</strong> to create footnotes:</p>
<div id="cb9" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb9-1" class="sourceLine" data-line-number="1"></a><span class="kw">&lt;p&gt;</span>Sometimes, it is nice to be able to put
<a id="cb9-2" class="sourceLine" data-line-number="2"></a>  <span class="kw">&lt;a</span><span class="ot"> id=</span><span class="st">"fnref1"</span><span class="ot"> href=</span><span class="st">"#fn1"</span><span class="kw">&gt;</span>footnotes<span class="kw">&lt;/a&gt;</span> in your
<a id="cb9-3" class="sourceLine" data-line-number="3"></a>  documents because the content doesn't really belong
<a id="cb9-4" class="sourceLine" data-line-number="4"></a>  in the main flow of the document<span class="kw">&lt;/p&gt;</span>
<a id="cb9-5" class="sourceLine" data-line-number="5"></a><span class="kw">&lt;p&gt;</span>To see the effect, you will need to copy the next
<a id="cb9-6" class="sourceLine" data-line-number="6"></a>  few paragraphs a many times, so the footnote scrolls
<a id="cb9-7" class="sourceLine" data-line-number="7"></a>  off the bottom of the page.<span class="kw">&lt;/p&gt;</span>
<a id="cb9-8" class="sourceLine" data-line-number="8"></a><span class="kw">&lt;p&gt;</span>Lorem ipsum dolor sit amet, eum invenire erroribus
<a id="cb9-9" class="sourceLine" data-line-number="9"></a>  id. At solum tamquam voluptatum his. Id ius omnis
<a id="cb9-10" class="sourceLine" data-line-number="10"></a>  labitur adipiscing, ut tollit discere deseruisse per.
<a id="cb9-11" class="sourceLine" data-line-number="11"></a>  Ea accumsan reprimique concludaturque eam, ut sed
<a id="cb9-12" class="sourceLine" data-line-number="12"></a>  suas consetetur. Cum imperdiet referrentur in.
<a id="cb9-13" class="sourceLine" data-line-number="13"></a>  Usu postulant philosophia id.<span class="kw">&lt;/p&gt;</span>
<a id="cb9-14" class="sourceLine" data-line-number="14"></a><span class="kw">&lt;p&gt;</span>In mea sumo disputationi. Te pri quodsi laoreet.
<a id="cb9-15" class="sourceLine" data-line-number="15"></a>  Etiam dicta an vis, nec et mnesarchum incorrupte
<a id="cb9-16" class="sourceLine" data-line-number="16"></a>  constituam, facer mandamus sea ei. Sale assum no
<a id="cb9-17" class="sourceLine" data-line-number="17"></a>  vel, id labores inciderint vix. Diam accusata
<a id="cb9-18" class="sourceLine" data-line-number="18"></a>  appellantur cum te, mel ne ornatus eleifend
<a id="cb9-19" class="sourceLine" data-line-number="19"></a>  adversarium.<span class="kw">&lt;/p&gt;</span>
<a id="cb9-20" class="sourceLine" data-line-number="20"></a><span class="kw">&lt;h2&gt;</span>Footnotes<span class="kw">&lt;/h2&gt;</span>
<a id="cb9-21" class="sourceLine" data-line-number="21"></a><span class="kw">&lt;p&gt;</span>----------<span class="kw">&lt;/p&gt;</span>
<a id="cb9-22" class="sourceLine" data-line-number="22"></a><span class="kw">&lt;p</span><span class="ot"> id=</span><span class="st">"fn1"</span><span class="kw">&gt;&lt;strong&gt;</span>1.<span class="kw">&lt;/strong&gt;</span> This is a footnote and
<a id="cb9-23" class="sourceLine" data-line-number="23"></a>  it has a link to return back to your location in the
<a id="cb9-24" class="sourceLine" data-line-number="24"></a>  document.
<a id="cb9-25" class="sourceLine" data-line-number="25"></a>  <span class="kw">&lt;a</span><span class="ot"> href=</span><span class="st">"#fnref1"</span><span class="kw">&gt;</span>↩<span class="kw">&lt;/a&gt;</span>
<a id="cb9-26" class="sourceLine" data-line-number="26"></a><span class="kw">&lt;/p&gt;</span></code></pre>
</div>
<p>I didn’t do a traditional footnote with the little superscript<a id="fnref2" class="footnote-ref" href="#fn2"><sup>2</sup></a> because we haven’t covered the tag yet. Nevertheless, you can see that it is possible to:</p>
<ol type="1">
<li>create a footnote (or just notes) section in your documents</li>
<li>jump or navigate to those sections</li>
<li>return to the location were the jump was made from.</li>
<li>add <strong>ids</strong> to <strong>anchor</strong> tags and navigate to them</li>
</ol>
<p>You can also navigate to a specific location in any document by appending the <strong>id</strong> to the URL:</p>
<div id="cb11" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb11-1" class="sourceLine" data-line-number="1"></a><span class="kw">&lt;a</span><span class="ot"> href=</span><span class="st">"http://example.com/index.html#reference"</span><span class="kw">&gt;</span>
<a id="cb11-2" class="sourceLine" data-line-number="2"></a>  Reference material
<a id="cb11-3" class="sourceLine" data-line-number="3"></a><span class="kw">&lt;/a&gt;</span></code></pre>
</div>
<p>The code fragment above, creates a hyperlink which instructs the browser to load the document <strong>index.html</strong> from the domain <strong>example.com</strong> and to jump to the location on the page having an <strong>id</strong> with the value of <em>reference</em>.</p>
<h3 id="target">target</h3>
<p>By default, clicking on a hyperlink loads the resource into the current context (i.e. your current browser window or tab).<br />
Setting the attribute <strong>target</strong> to “_blank” will cause the resource to open in a new window or tab:</p>
<div id="cb12" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb12-1" class="sourceLine" data-line-number="1"></a><span class="kw">&lt;a</span><span class="ot"> href=</span><span class="st">"http://example.com"</span><span class="ot"> target=</span><span class="st">"_blank"</span><span class="kw">&gt;</span>Click to
<a id="cb12-2" class="sourceLine" data-line-number="2"></a>  open in a new window or tab.<span class="kw">&lt;/a&gt;</span></code></pre>
</div>
<h3 id="download">download</h3>
<p>Sometimes, you want a hyperlink to download a resource instead of loading it. This can be done using the <strong>download</strong> attribute:</p>
<div id="cb13" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb13-1" class="sourceLine" data-line-number="1"></a><span class="kw">&lt;a</span><span class="ot"> href=</span><span class="st">"http://example.com/file.zip"</span><span class="ot"> download=</span><span class="st">"file.zip"</span><span class="kw">&gt;</span>
<a id="cb13-2" class="sourceLine" data-line-number="2"></a>  Click to download.
<a id="cb13-3" class="sourceLine" data-line-number="3"></a><span class="kw">&lt;/a&gt;</span></code></pre>
</div>
<p>The example above will prompt the user to download <strong>file.zip</strong>. If <strong>download</strong> has a value, it will be used as the default name for the resource being downloaded (the user can change it before downloading). If no value is given for <strong>download</strong>, the user will be prompted for a suitable filename. Obviously, if you are assigning a value to the <strong>download</strong> attribute, ensure it is a sensible filename.<a id="fnref3" class="footnote-ref" href="#fn3"><sup>3</sup></a></p>
<h2 id="practical-considerations">Practical Considerations</h2>
<p>A good hyperlink is one that lets the user know exactly what they are going to get when they click on it. In other words, it should be informative.<br />
Avoid vague or generic terms or phrases. For example, the following are not considered “good” hyperlinks:</p>
<div id="cb14" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb14-1" class="sourceLine" data-line-number="1"></a><span class="kw">&lt;a</span><span class="ot"> href=</span><span class="st">"http://example.com"</span><span class="kw">&gt;</span> Click here!<span class="kw">&lt;/a&gt;</span>
<a id="cb14-2" class="sourceLine" data-line-number="2"></a>
<a id="cb14-3" class="sourceLine" data-line-number="3"></a><span class="kw">&lt;a</span><span class="ot"> href=</span><span class="st">"http://example.com"</span><span class="kw">&gt;</span> Read more.<span class="kw">&lt;/a&gt;</span>
<a id="cb14-4" class="sourceLine" data-line-number="4"></a>
<a id="cb14-5" class="sourceLine" data-line-number="5"></a><span class="kw">&lt;p&gt;</span>
<a id="cb14-6" class="sourceLine" data-line-number="6"></a>  Get more information
<a id="cb14-7" class="sourceLine" data-line-number="7"></a>  <span class="kw">&lt;a</span><span class="ot"> href=</span><span class="st">"http://example.com"</span><span class="kw">&gt;</span> here<span class="kw">&lt;/a&gt;</span>.
<a id="cb14-8" class="sourceLine" data-line-number="8"></a><span class="kw">&lt;/p&gt;</span></code></pre>
</div>
<p>Better hyperlinks would be:</p>
<div id="cb15" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb15-1" class="sourceLine" data-line-number="1"></a><span class="kw">&lt;p&gt;</span> Download
<a id="cb15-2" class="sourceLine" data-line-number="2"></a>  <span class="kw">&lt;a</span><span class="ot"> href=</span><span class="st">"http://example.com"</span><span class="kw">&gt;</span>
<a id="cb15-3" class="sourceLine" data-line-number="3"></a>    The Guide to Effective Links
<a id="cb15-4" class="sourceLine" data-line-number="4"></a>  <span class="kw">&lt;/a&gt;</span>
<a id="cb15-5" class="sourceLine" data-line-number="5"></a><span class="kw">&lt;/p&gt;</span>
<a id="cb15-6" class="sourceLine" data-line-number="6"></a>
<a id="cb15-7" class="sourceLine" data-line-number="7"></a><span class="kw">&lt;p&gt;</span>There is so much to learn about the
<a id="cb15-8" class="sourceLine" data-line-number="8"></a>  <span class="kw">&lt;a</span><span class="ot"> href=</span><span class="st">"http://example.com"</span><span class="kw">&gt;</span>World Wide Web<span class="kw">&lt;/a&gt;</span>
<a id="cb15-9" class="sourceLine" data-line-number="9"></a><span class="kw">&lt;/p&gt;</span>
<a id="cb15-10" class="sourceLine" data-line-number="10"></a>
<a id="cb15-11" class="sourceLine" data-line-number="11"></a><span class="kw">&lt;p&gt;</span>
<a id="cb15-12" class="sourceLine" data-line-number="12"></a>  <span class="kw">&lt;a</span><span class="ot"> href=</span><span class="st">"http://example.com"</span><span class="kw">&gt;</span>Sign up<span class="kw">&lt;/a&gt;</span>
<a id="cb15-13" class="sourceLine" data-line-number="13"></a>  and become a member.
<a id="cb15-14" class="sourceLine" data-line-number="14"></a><span class="kw">&lt;/p&gt;</span></code></pre>
</div>
<p>When people read, they tend to skim and notice the first few characters (about the length of 2 short words). If people can’t figure out what the hyperlink is about from the first 2 words, the text of the link is probably suboptimal.<br />
You should also prefer nouns, objects, and concrete things over verbs. The title of a resource, generally, is the appropriate text for a hyperlink.<br />
You can also put a hyperlink on an image:</p>
<div id="cb16" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb16-1" class="sourceLine" data-line-number="1"></a><span class="kw">&lt;a</span><span class="ot"> href=</span><span class="st">"big_image.jpg"</span><span class="kw">&gt;</span>
<a id="cb16-2" class="sourceLine" data-line-number="2"></a>  <span class="kw">&lt;img</span><span class="ot"> src=</span><span class="st">"thumbail.jpg"</span><span class="kw">&gt;</span>
<a id="cb16-3" class="sourceLine" data-line-number="3"></a><span class="kw">&lt;/a&gt;</span></code></pre>
</div>
<p>(The example above assumes both images are in the same location as the HTML document.)<br />
You would typically do this to minimize the image size in your document (this leads to faster download and a better user experience). If the user wants to see the full sized image, they can click on the image.<br />
You might also do this if hyperlink text is not good enough. For example, the social media buttons you see on many websites are little images wrapped inside an HTML <strong>anchor</strong>:</p>
<div id="cb17" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb17-1" class="sourceLine" data-line-number="1"></a><span class="kw">&lt;a</span><span class="ot"> href=</span><span class="st">"facebook.com"</span><span class="kw">&gt;&lt;img</span><span class="ot"> src=</span><span class="st">"fb_thumb.png"</span><span class="kw">&gt;&lt;/a&gt;</span></code></pre>
</div>
<p>While you can create a link to open in a new window or tab (using <span class="kbd">target=“_blank”</span>), remember that many people don’t appreciate new windows or tabs opening up without warning. So it is a good idea to warn people:</p>
<div id="cb18" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb18-1" class="sourceLine" data-line-number="1"></a><span class="kw">&lt;p&gt;</span>
<a id="cb18-2" class="sourceLine" data-line-number="2"></a>  Get a
<a id="cb18-3" class="sourceLine" data-line-number="3"></a>  <span class="kw">&lt;a</span><span class="ot"> href=</span><span class="st">"http://example.com"</span><span class="ot"> target=</span><span class="st">"_blank"</span><span class="kw">&gt;</span>
<a id="cb18-4" class="sourceLine" data-line-number="4"></a>    Free Sample
<a id="cb18-5" class="sourceLine" data-line-number="5"></a>  <span class="kw">&lt;/a&gt;</span>. (Opens in a new tab.)
<a id="cb18-6" class="sourceLine" data-line-number="6"></a><span class="kw">&lt;/p&gt;</span></code></pre>
</div>
<h2 id="summary">Summary</h2>
<ul>
<li>The <span class="kbd">&lt;a&gt;</span> tag is used to create a hyperlink in your document.</li>
<li>The hyperlink can be to various types of resources:
<ul>
<li>Documents on other websites</li>
<li>Documents on your website</li>
<li>Locations within your document</li>
<li>Other files or images</li>
</ul>
</li>
<li>To create a hyperlink to a part of your document, you need to add an <strong>id</strong> attribute to an HTML tag in that region and you reference the <strong>id</strong> by prefacing its value with a pound sign (<strong>#</strong>)</li>
<li>The <strong>href</strong> attribute takes an absolute or relative URL to a resource.</li>
<li>The <strong>target</strong> attribute allows you to specify the hyperlink should open in a new window or tab.</li>
<li>The <strong>download</strong> attribute allows you to specify the resource should be downloaded.</li>
<li>Pick meaningful text for hyperlinks. The user should be able to infer what the hyperlink resource is from just the first few characters (about the length of 2 short words).</li>
<li>Images can be used as hyperlinks. This is commonly seen in social media icons.</li>
</ul>
<h2 id="playing-around">Playing Around</h2>
<p>The best way to learn is to play around with what you have learned.<br />
Some webpage ideas are:</p>
<ul>
<li>update one of your previous webpages to include hyperlinks &#8211; for example, replace the images with a smaller “thumbnail” images and create hyperlinks to load the full sized image</li>
<li>create a number of recipe pages and a main page that lists all the recipes and links to them. Put a return link on each recipe page back to the main page.</li>
<li>if you are feeling extremely adventurous, create a “Choose Your Own Adventure” story. This is a type of story in which the reader reads a short piece of prose (usually 1-3 paragraphs) and has to choose an action at the end, this leads to another page, and so on.</li>
<li>create a reference page for yourself. I am pretty sure this tutorial series is not the only resource you are using. Create a page that lists and links to your favourite resources.</li>
</ul>
<h2 id="references">References</h2>
<ol type="1">
<li><a href="https://html.spec.whatwg.org/multipage/text-level-semantics.html#the-a-element"><span class="kbd">&lt;a&gt;</span> tag</a></li>
<li><a href="https://html.spec.whatwg.org/multipage/links.html#attr-hyperlink-href"><strong>href</strong> attribute</a></li>
<li><a href="https://html.spec.whatwg.org/multipage/links.html#attr-hyperlink-target"><strong>target</strong> attribute</a></li>
<li><a href="https://html.spec.whatwg.org/multipage/links.html#attr-hyperlink-download"><strong>download</strong> attribute</a></li>
<li><a href="https://www.nngroup.com/articles/first-2-words-a-signal-for-scanning/">Effective Hyperlinks</a></li>
</ol>
<div class="prev"><a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/a-recipe-example-with-an-image">Prev</a></div>
<div class="next"><a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/a-recipe-example-with-hyperlinks">Next</a></div>
<div class="clear"></div>
<section class="footnotes">
<hr />
<ol>
<li id="fn1">This is not true for <strong>XHTML</strong> which has case-sensitive <strong>id</strong> values. Also, there was a bug in Netscape 6 (an ancient browser released in 2000) which treated the values as case-sensitive.<a class="footnote-back" href="#fnref1">↩</a></li>
<li id="fn2">You can use <span class="kbd">&lt;sup&gt;</span> and <span class="kbd">&lt;/sup&gt;</span> for superscript and <span class="kbd">&lt;sub&gt;</span> and <span class="kbd">&lt;/sub&gt;</span> for subscript.
<div id="cb10" class="sourceCode">
<pre class="sourceCode html"><code class="sourceCode html"><a id="cb10-1" class="sourceLine" data-line-number="1"></a><span class="kw">&lt;p&gt;</span>The formula for water is H<span class="kw">&lt;sub&gt;</span>2<span class="kw">&lt;/sub&gt;</span>O.<span class="kw">&lt;/p&gt;</span>
<a id="cb10-2" class="sourceLine" data-line-number="2"></a>
<a id="cb10-3" class="sourceLine" data-line-number="3"></a><span class="kw">&lt;p&gt;</span>y = x<span class="kw">&lt;sup&gt;</span>2<span class="kw">&lt;/sup&gt;</span> + 3x + 12<span class="kw">&lt;/p&gt;</span></code></pre>
</div>
<p><a class="footnote-back" href="#fnref2">↩</a></li>
<li id="fn3">Because you have no idea what sort of file system your resource may be downloaded to, it is best to follow these general naming rules:<a class="footnote-back" href="#fnref3">↩</a>
<ul>
<li>avoid spaces in the name</li>
<li>use only letters, digits, underscores (_), hyphens (-), and periods</li>
<li>preferably start the filename with a letter or underscore</li>
<li>keep the name short &#8211; preferably no longer than 8 characters + period + 3 characters (e.g. filename.nam)</li>
</ul>
</li>
</ol>
</section>
<p>The post <a href="https://complete-concrete-concise.com/tutorials/webdev/front-end-basics/hyperlinks-in-html/">Hyperlinks in HTML</a> appeared first on <a href="https://complete-concrete-concise.com">Complete, Concrete, Concise</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
