Main menu

Pages

HTML: Hypertext links , image or button , bookmarks , Download

Hypertext links



In HTML, you can create hyperlinks (also known as links) to other web pages, files, or resources using the a element. Here's an example of how you can create a hyperlink:

<a href="https://www.example.com">Visit Example</a>

In this example, the a element defines the hyperlink, and the href attribute specifies the URL of the target resource. The text "Visit Example" between the opening and closing a tags is the link text that will be displayed on the web page.

You can also create internal links within the same web page by using anchor tags. An anchor tag is an element that defines a target location within a web page. Here's an example of how to create an anchor tag:

<a id="section1"></a>


In this example, the a element defines an anchor point with the id attribute set to "section1". You can then create a hyperlink to this anchor point within the same web page by using the href attribute with a pound sign and the id value, like this:

<a href="#section1">Go to Section 1</a>

In this example, the href attribute specifies the target location within the same web page using the pound sign (#) followed by the id value of the anchor tag.

You can also add additional attributes to hyperlinks to control how they are displayed or to provide additional information. Some common attributes include title (to provide a tooltip text when the user hovers over the link), target (to specify where the link should open, such as in a new window or tab), and rel (to define the relationship between the linked document and the current document, such as "nofollow" to indicate that the link should not be followed by search engine crawlers).

Hypertext links (image or button)


The target attribute in HTML is used to specify where to open the target resource (e.g., a web page or a file) when the user clicks on a hyperlink. The target attribute is applied to the a (anchor) element, and it can take several values:

  • _self: the target resource will be opened in the same window or frame as the one containing the hyperlink.
  • _blank: the target resource will be opened in a new window or tab.
  • _parent: the target resource will be opened in the parent frame of the current frame (if any).
  • _top: the target resource will be opened in the full body of the window, overriding any frames (if any).

Here's an example of how to use the target attribute

<a href="https://www.example.com" target="_blank">Visit Example</a>

In this example, the target attribute is set to _blank, which means that when the user clicks on the hyperlink, the target resource (the web page at https://www.example.com) will be opened in a new window or tab.

Note that not all values of the target attribute are supported by all browsers, and some browser extensions may override the behavior of the target attribute. Therefore, it's generally recommended to use the default value (_self) unless there is a specific reason to use a different value.

bookmarks

 In HTML, a bookmark is a named anchor that allows users to jump directly to a specific point on a web page. Bookmarks are created using the a (anchor) element with the name attribute.

Here's an example of how to create a bookmark:

<a name="bookmark1">This is the bookmarked text</a>


In this example, the a element has a name attribute with the value "bookmark1". This creates a bookmark at this point on the page.

To create a hyperlink to the bookmark, you can use the a element with the href attribute set to the name of the bookmark preceded by the "#" symbol. Here's an example:

<a href="#bookmark1">Go to bookmark</a>

In this example, the href attribute is set to "#bookmark1", which is the name of the bookmark we created earlier. When the user clicks on this hyperlink, the browser will scroll to the point on the page where the bookmark is located.

Note that bookmarks are not as commonly used as they once were, as modern web design tends to rely more on smooth scrolling and other techniques for navigating within a page. However, bookmarks can still be useful in certain situations, such as when you want to provide a direct link to a specific section of a long document.

Download


In HTML, you can create a hyperlink to a file that can be downloaded by the user. This is done using the a (anchor) element with the href attribute set to the URL of the file you want to download, and the download attribute set to the desired name for the downloaded file.

Here's an example of how to create a download link:

<a href="path/to/file.pdf" download="my_file.pdf">Download my file</a>

In this example, the href attribute is set to the path of the PDF file you want to download, and the download attribute is set to "my_file.pdf". This means that when the user clicks on the hyperlink, the PDF file will be downloaded to their device with the name "my_file.pdf".

Note that the download attribute is not supported in all web browsers, so it's a good idea to provide a fallback option for users who are not able to download the file using the download attribute. You can do this by providing a normal hyperlink to the file, like this:

<a href="path/to/file.pdf">Download my file</a>

This will still allow users to download the file, but it won't specify a filename for the downloaded file.







Comments

table of contents title