HTML Anchors and Hyperlinks

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson
Download our mobile app to listen on the go
Get App

Questions and Answers

What does the href parameter specify in an anchor tag?

The destination address, which can be an absolute or relative URL, or the name of an anchor.

What is an example of an absolute URL?

What does a relative URL point to?

Another directory and/or document inside the same website.

What is returned when pointing to another directory without explicitly specifying the document?

<p>web servers typically return the document &quot;index.html&quot; inside that directory</p> Signup and view all the answers

What does the hreflang parameter specify?

<p>Specifies the language of the resource linked by the href attribute.</p> Signup and view all the answers

What does the target parameter specify?

<p>Specifies where to open the link, e.g., in a new tab or window.</p> Signup and view all the answers

What are possible/valid values for the target parameter?

<p>All of the above (E)</p> Signup and view all the answers

What does the download parameter specify?

<p>Specifies that the target will be downloaded when a user clicks on the hyperlink.</p> Signup and view all the answers

Anchor tags are commonly used to link separate webpages.

<p>True (A)</p> Signup and view all the answers

Anchor tags can only be used to link separate webpages.

<p>False (B)</p> Signup and view all the answers

What is basic use of the <a> element?

<p>To allows links to another site.</p> Signup and view all the answers

What is the usage of the href attribute?

<p>It specifies the URL that you are linking to.</p> Signup and view all the answers

What can anchors be used for?

<p>to jump to specific tags on an HTML page</p> Signup and view all the answers

To use an anchor, what attribute must the tag have?

<p>id</p> Signup and view all the answers

Anchors are mostly used to jump to a subsection of a page and are used in conjunction with header tags.

<p>True (A)</p> Signup and view all the answers

How do you link to an anchor in the same page?

<p>Use the <code>href</code> attribute with a <code>#</code> followed by the <code>id</code> of the element you want to link to.</p> Signup and view all the answers

How can you link across the site from one page to the other by referencing the page and anchor name?

<p>By including the page name followed by <code>#</code> and the anchor name in the <code>href</code> attribute.</p> Signup and view all the answers

You can use a _____ path to link to pages on the same website.

<p>relative</p> Signup and view all the answers

If the value of the href-attribute begins with _____, your device will dial the number when you click it.

<p>tel:</p> Signup and view all the answers

What does target="_blank" do?

<p>Opens the link in a new tab or window.</p> Signup and view all the answers

What security vulnerability is given by using target="_blank"?

<p>Gives the opening site partial access to the window.opener object via JavaScript</p> Signup and view all the answers

To mitigate the security vulnerability of using target="_blank", what should you add to pages you do not control?

<p><code>rel=&quot;noopener&quot;</code></p> Signup and view all the answers

If the value of the href-attribute begins with _____, it will try to open an email client on click.

<p>mailto:</p> Signup and view all the answers

What tag is used to created an ordered list?

<ol> Signup and view all the answers

What tag is used to created each list item in an ordered list?

<li> Signup and view all the answers

Ordered lists use ordinal sequences to indicate the order of list elements.

<p>True (A)</p> Signup and view all the answers

Unordered lists use indents to list elements with their children.

<p>False (B)</p> Signup and view all the answers

How do you set a starting number in an ordered list?

<p>Use the start attribute within the <code>&lt;ol&gt;</code> tag.</p> Signup and view all the answers

How can you explicitly set a certain list item to a specific number?

<p>By using the value attribute directly on a list item.</p> Signup and view all the answers

The start and value attributes only accept a number - even if the ordered list is set to display as Roman numerals or letters.

<p>True (A)</p> Signup and view all the answers

From what version does <ol reversed> work?

<p>Version ≥ 5</p> Signup and view all the answers

How do you change the type of numeral shown in the list item marker?

<p>By using the type attribute.</p> Signup and view all the answers

If changing the order of the items does NOT make the list incorrect, you should use <ul>.

<p>True (A)</p> Signup and view all the answers

The nested list has to be a child of the li element.

<p>True (A)</p> Signup and view all the answers

With what element can a description list be created?

<p><code>&lt;dl&gt;</code></p> Signup and view all the answers

In a description list, in what element is the name given?

<p><code>&lt;dt&gt;</code></p> Signup and view all the answers

Flashcards

What is the 'href' attribute?

Specifies the destination address of a hyperlink; can be absolute, relative URL, or anchor name.

What is 'hreflang'?

Specifies the language of the linked resource; uses language values from BCP 47 (HTML5) or RFC 1766 (HTML 4).

What is the 'rel' attribute?

Specifies the relationship between the current document and the linked document.

What does 'target' attribute do?

Specifies where to open a link (e.g., new tab or window).

Signup and view all the flashcards

What is the 'title' attribute?

Specifies extra information about a link, often as a tooltip.

Signup and view all the flashcards

What is the 'download' attribute?

Specifies that the target will be downloaded upon clicking the hyperlink.

Signup and view all the flashcards

What are anchor tags used for?

Used to link separate webpages or different places in a single document.

Signup and view all the flashcards

How to link to another site?

Creates a hyperlink to a specified URL with anchor text.

Signup and view all the flashcards

How to link to an anchor?

Jumps to specific tags on an HTML page using the 'id' attribute.

Signup and view all the flashcards

How to link to a page on the same site?

Links to pages on the same website using a relative path.

Signup and view all the flashcards

How to create a dial number link?

Dials a number when clicked on a mobile device or computer with dialing software.

Signup and view all the flashcards

How to open a link in a new tab/window?

Opens a link in a new tab or window by setting the target attribute to "_blank".

Signup and view all the flashcards

What does target='_blank' give the opening site?

Gives partial access, use rel="noopener" to block access.

Signup and view all the flashcards

How to create a link that runs an email client?

Opens an email client when clicked, with the specified email address as the recipient.

Signup and view all the flashcards

How to add cc and bcc to email link?

Adds cc- or bcc-recipients to an email link using specific syntax.

Signup and view all the flashcards

How to include a subject and body in email link?

Populates the subject and body of a new email via a link.

Signup and view all the flashcards

Use case for ordered lists?

Lists where order matters (e.g., steps).

Signup and view all the flashcards

What are the 3 types of HTML lists??

Ordered, Unordered and Description Lists

Signup and view all the flashcards

How to create an ordered list?

Created with

    tag; list items use
  1. tag.

    Signup and view all the flashcards

How to manually change the numbers in ordered lists?

Set a starting number using the start attribute in the <ol> tag.

Signup and view all the flashcards

How to explicitly set the list item to a specific number?

Set a specific number with the 'value' attribute; further items increment from this value.

Signup and view all the flashcards

How to reverse the numbering in ordered lists?

Reverse the numbering by adding reversed in your ol element

Signup and view all the flashcards

How to change the numbering type in ordered lists?

Change the numeral type using the type attribute.

Signup and view all the flashcards

How to create an unordered list??

Use

    tag and
  • tags for list items.

    Signup and view all the flashcards

When to use

    vs.
      ?

Use

    to emphasize order; use
      if order doesn't matter.

      Signup and view all the flashcards

What is a nested list?

Nesting Lists to represent sub-items of a list item

Signup and view all the flashcards

Where should a nested list be located?

List has to be a child of the 'li' element

Signup and view all the flashcards

Creating a description list?

Use the dl element.

Signup and view all the flashcards

What is special about a name-value group?

Has more than one name and/or more than one value

Signup and view all the flashcards

Study Notes

  • Anchor tags commonly link separate webpages
  • They also link different places within a single document
  • Anchor tags can be used in tables of contents
  • They also launch external applications
  • href specifies the destination address, either as an absolute or relative URL, or the name of an anchor
  • An absolute URL represents the complete URL of a website such as http://example.com/
  • A relative URL points to another directory or document within the same website, such as /about-us/ pointing to the "about-us" directory inside the root directory /
  • Web servers typically return the index.html document if the document is not specified
  • hreflang specifies the language of the linked resource
  • The href attribute is required when using hreflang
  • You should use language values from BCP 47 for HTML5 and RFC 1766 for HTML4 when using hreflang
  • rel specifies the relationship between the current document and the linked one
  • HTML5 values for rel must be defined in the specification or registered in the Microformats wiki.
  • target specifies where to open the link, with values like _blank, _self, _parent, _top, and framename (deprecated)
  • Forcing a specific target behavior can violate user control
  • title specifies extra information about a link, often displayed as a tooltip on cursor hover and is usable with almost all HTML tags
  • download specifies that the target will be downloaded when a user clicks the hyperlink, and the attribute's value will be the name of the downloaded file
  • There are no restrictions on allowed values
  • The browser automatically detects the correct file extension
  • If the download value is omitted, the original filename is used

Linking to Another Site

  • An anchor element <a> is used to create a basic link.
  • <a href="http://example.com/">Link to example.com</a> will create a hyperlink to http://example.com/

Linking to an Anchor

  • Anchors can be used to jump to specific tags on an HTML page.
  • Tags can point to any element with an id attribute
  • Anchors are useful for jumping to subsections of a page, often used with header tags.

Linking to an Anchor Example

  • Example page page1.html structure
<h2>First topic</h2>
<p>Content about the first topic</p>
<h2>Second topic</h2>
<p>Content about the second topic</p>
  • To create quick-links to specific sections within a page, assign an id attribute to the topics
<h2 id="Topic1">First topic</h2>
<p>Content about the first topic</p>
<h2 id="Topic2">Second topic</h2>
<p>Content about the second topic</p>
  • Hyperlinks can be created in a table of contents.
<h1>Table of Contents</h1>
<a href='#Topic1'>Click to jump to the First Topic</a>
<a href='#Topic2'>Click to jump to the Second Topic</a>
  • Anchors are attached to the webpage so you can link across sites by referencing the page and anchor name.
  • <a href="page1.html#Topic1">look back in the First Topic</a> links to the anchor

Linking to a Page on the Same Site

  • Relative paths can be used to link pages on the same website.
  • <a href="/example">Text Here</a> links to the file example at the root directory / of the server.
  • If the link is on http://example.com, <a href="/page">Text Here</a> and <a href="http://example.com/page">Text Here</a> both link to the page file at the root

Dailing a Number

  • If the href attribute begins with tel:, the device will dial the number when clicked
  • Works on mobile devices or computers/tablets running software like Skype or FaceTime
  • <a href="tel:11234567890">Call us</a> will dial 11234567890
  • Most devices and programs will prompt the user to confirm the number.
  • The target attribute specifies where the link opens.
  • <a href="example.com" target="_blank">Text Here</a> opens the link in a new tab or window, as per user preferences.
  • Using target="_blank" grants the opening site partial access to the window.opener object via JavaScript
  • The access allows changing the window.opener.location
  • There is a risk of redirecting users to malware or phishing sites
  • Use rel="noopener" to prevent sending the window.opener object with the request
  • Firefox requires rel="noopener noreferrer" for maximum effect

Running Email Client

  • If the href attribute starts with mailto:, clicking the link opens an email client.
  • <a href="mailto:[email protected]">Send email</a> opens the email client and sets [email protected] as the recipient.

Email Client Usage

  • Cc and Bcc recipients can be added to a mailto: link via <a href="mailto:[email protected][email protected]&[email protected]">Send email</a>
  • Subject and body text can be populated with <a href="mailto:[email protected]?subject=Example+subject&body=Message+text">Send email</a>
  • Clicking a mailto: link opens the default email client and may prompt the user to choose one.
  • Not all options specified after the recipient's address are supported in all email clients.

HTML Lists

  • HTML offers three types of lists including ordered, unordered, and description lists
  • Ordered lists use ordinal sequences to indicate the order of list elements
  • Unordered lists use symbols (like bullets) to list elements
  • Description lists use indents to list elements with their children

Ordered Lists

  • An ordered list is created with the <ol> tag.
  • List items are created with the <li> tag.
<ol>
 <li>Item</li>
 <li>Another Item</li>
 <li>Yet Another Item</li>
</ol>
  • The list is numbered by default

Changing Ordered List Numbers

  • Ordered Lists can have their number style manually changed
  • Use the start attribute to define the number with which a list begins
  • Numbers increment by one as usual from the starting attribute
<ol start="3">
 <li>Item</li>
 <li>Some Other Item</li>
 <li>Yet Another Item</li>
</ol>
  • Specific list items can have a defined number with the value attribute.
  • Subsequent list items from a value will increment as normal, ignoring where the parent list was at.
  • The numbering restarts at the value, even if the list was up to the value already.
<ol start="5">
 <li>Item</li>
 <li>Some Other Item</li>
 <li value="4">A Reset Item</li>
 <li>Another Item</li>
 <li>Yet Another Item</li>
</ol>
  • The start and value attributes only work with numbers, even if the list style is set to letters or numerals

Reversing the Numerical Direction

  • Numbering can be reversed by adding reversed in the <ol> tag
<ol reversed>
 <li>Item</li>
 <li>Some Other Item</li>
 <li value="4">A Reset Item</li>
 <li>Another Item</li>
 <li>Yet Another Item</li>
</ol>
  • Reverse numbering is helpful for continually adding to a list with most recent items appearing first.

Numerical Styling of Ordered Lists

  • The type of numeral used in ordered lists can be changed
  • The available type values when using <ol> are
<ol type="1|a|A|i|I">
  • 1: Decimal numbers (1, 2, 3, 4)
  • a: Lowercase letters (a, b, c, d)
  • A: Uppercase letters (A, B, C, D)
  • i: Lowercase Roman numerals (i, ii, iii, iv)
  • I: Uppercase Roman numerals (I, II, III, IV)

Unordered Lists

  • An unordered list is created with the <ul> tag.
  • List items are created with the <li> tag.
<ul>
<li>Item</li>
<li>Another Item</li>
<li>Yet Another Item</li>
</ul>
  • The list is bulleted by default.
  • You should use <ol> when the order of items is important, and <ul> when the order doesn't matter.

Nested Lists

  • Lists can be nested to represent sub-items of a list item.
<ul>
<li>item 1</li>
<li>item 2
<ul>
<li>sub-item 2.1</li>
<li>sub-item 2.2</li>
</ul>
</li>
<li>item 3</li>
</ul>
  • Nested lists must be a child of a li element
  • Combining different list types is possible

Description Lists

  • Description lists, also known as definition lists prior to HTML5, use the <dl> element
  • Uses name-value groups where the name is given in a dt element, while the value resides in a dd element.
<dl>
<dt>name 1</dt>
<dd>value for 1</dd>
<dt>name 2</dt>
<dd>value for 2</dd>
</dl>
  • dt name-value groups include more than one name or value (alternatives)
<dl>
<dt>name 1</dt>
<dt>name 2</dt>
<dd>value for 1 and 2</dd>
<dt>name 3</dt>
<dd>value for 3</dd>
<dd>value for 3</dd>
</dl>

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Related Documents

More Like This

Use Quizgecko on...
Browser
Browser