Contacts

Hyperlink does not work in html. Hyperlink - what is it, how to make a link and insert it into HTML code (href, target blank and other attributes of the a tag). Link-button using CSS styles

In this lesson we will talk about how to link in HTML... Links are very often used on sites, they allow you to go from one page of the site to another. A feature of links is that they can lead not only to a web page, but also to files, images, etc.

Links can be internal or external. Internal links navigate to pages and files within one site. External links lead to third party sites, documents and files. At the same time, these types of links are set in almost the same way.

How to link in HTML, examples

1. Href- is responsible for where the link should lead. A standard link is defined as follows: Link text.

2. TARGET- is responsible for the window in which the document will open. By default, a new document opens in the current browser window. The target attribute allows you to open a link in a new browser window. This attribute has the following parameters:

  • _blank - loads the page in a new window;
  • _self - loads the page in the current window;
  • _parent - loads the page into the parent frame;
  • _top - cancels all frames and loads the page in a new window.

3. NAME- used to navigate to a specific area within a page. A keyword (bookmark or label) is indicated in quotation marks after the hash symbol. To go to this label, use the link in which this label is written.

External link example

Go to the site



Go to the site
Free WordPress Tutorials

Example 4. Images as links.

Sample image as a link



An example of a link to a specific place on the page

Go to text

Page text ...



In this example, the page is labeled "list" using the "name" attribute. Linking to this label will navigate to a specific area of ​​the page.

Download file
Write a letter

You can set the color of links using the attributes that are specified in the "body" tag as parameters. Consider these attributes:

  • link - unvisited link, by default it is displayed in blue;
  • alink - active link, red by default;
  • vlink is the visited link, it has purple color by default.
An example of setting the color of links ...

Thus, we figured out how links are created in HTML. Links can be styled in a specific way. You can see about it in the lesson by clicking on the link.

I think you already understand what this chapter is about .. and you know what a link is, if not, then click here .. There are several types of links, as well as "mechanisms" for following them. In this chapter I will try to tell you in detail how to register links, as well as devote to the intricacies of working with them.

Lyrical digression:
Once in the army, the chief of staff came up to me and gave an order, I quote:
Bring me that document, I really don't know where it is and what it is !! What are you standing? Let's run !! I'm late !!!

So, what am I doing this, so that the browser, like me then, does not fall into a stupor, it needs to know: the exact name of the document, the path to the document, and the place where to bring it, or rather where to open it.

At the moment, with the help of notepad, we have created only one HTML document, I have it with the name index.html (why I chose such a strange name index.html and why you need it and why you need it) I don’t know with which one, you came up with the name yourself, but I think , You remember it and know where it lies, unless of course you are my chief of staff :) .. In this document we will try to create a link to another document that we do not have yet .. So before you link to it, you need to create it , fortunately, you already know how.

  1. We open the notebook.
  2. We write the code in html language. for example a page with a number of photos.
  3. We save it as an html page in the same working folder where the first document we created is already there. Let's, so as not to be confused, call it primer.html, and probably rename the first one to index.html

Now I know that you have two html documents index.html and primer.html and that now you have a minimal set for further learning.

Text links.

Meet the tag (from anchor - anchor), you can enclose text or a picture in it, which will become a link to certain documents. Tag attribute href specifies the name and path to the document to which the link points.

Everything together is written like this:

Here are my pictures !!

As you probably understood primer.html is the name of our second html document, and the inscription "Here are my pictures !!" this is a piece of text from the index.html file.

Similar to the pictures, the tag the path of the link to the opened document is written in the same ways:

Here are my pictures !!- Such an entry implies that in the directory where our first html document is located there is a stranica folder in which the primer.html file is located
Here are my pictures !!- This means that the primer.html file is located one level higher from the document
Here are my pictures !!- the document is located on the website www.site.ru ..

Well, let's try? Below is an example of two documents at once in which links pointing to each other are spelled out.

Index.html file:



Link a piece of text





Tell me, dear child: in which ear is my buzzing?


V right or left?





Primer.html file:



Followed the link here





But I didn’t guess! I have a buzzing in both ears.



Well, I don't play like that ...





From the example you can see that the links are highlighted in color, by default blue is the link, and red is the already visited link, these colors can be changed using the opening tag already well known to us. < body > and its attributes.

link- link color.
alink- the color of the clicked, active link.
vlink- the color of the visited link.

It is written like this:

>

Continuing to talk about the color of a text link, it is worth mentioning that, if necessary, you can forcefully highlight in color both the entire link and its individual parts (phrases of the word letters) with a familiar tag and its attribute color. However, this applies not only to color, but you can also separately set the size, style and font of the text. But remember that color manipulation must be done inside the tag. here and not overboard, otherwise the color of the link will be either by default, or as it is written in the tag

Index.html file:



Rainbow

link = "# 008000" alink = "# ff0000" vlink = "# ffff00">


Look at the phrase that will help you remember the places of flowers in the rainbow.




R
A
D
Have
G
A






Primer.html file:



Rainbow

link = "# 008000" alink = "# ff0000" vlink = "# ffff00">



Each
hunter
wishes
know
where
is sitting
pheasant



Go back to the main page




    One of your pages on the site necessarily should be called index.html. It is the file with this name that the robot program will look for on your site when a person enters the name of your site. Since the page index.html will open first, make it the main one. The rest of the pages can be called whatever you like ... there are no more nuances with names.

    About case .. When writing the path and names of documents, remember that, for example: Page.html, page.html and PAGE.html these are the names of different documents! The same goes for bookmark and picture names. Always be case sensitive when writing code, there is a high probability that such names will not be recognized by this or that browser. Make it a rule to write and call everything in small Latin letters, then the risk of the human factor and the vagaries of programs will be reduced to zero.

    The rule of three clicks.

    Try to form a "tree of links" in such a way that a site visitor can get from any of its pages to any place on the site with a minimum number of clicks on links. More than three transitions to the right place on the site is no longer good .. Endless downloads of pages unnecessary for a person can lead to nervous breakdown and premature closure of the site. Save time, money and nerves of people.

Hello dear readers of the blog site. Today we will talk about how to create hyperlinks in html, learn how to use the tag and its href and target attributes, let's learn how to make a picture a link.

Hyperlinks are key elements of a web page. They link disparate html pages together into a complete website. Typically, links are displayed as an underlined piece of text, and when you hover over it, the mouse cursor changes to a pointing finger. In addition, the hyperlink can be in the form of a graphic image or a fragment thereof. When you click on a link, the browser loads a web page, the address of which is specified in the attributes of this link. Hyperlinks allow you to link both to the internal pages of your site and to any other resources on the Internet.

Creating text hyperlinks

Let's start simple and look at creating common text links. To create a text hyperlink, any piece of text that should become a link is sufficient, enclose in paired tag ... And in href attribute of this tag, you must specify the address of the target web page on the Internet:

page 15

This snippet of html code creates a paragraph that contains the link. The link points to the web page page15.html, which is located in the catalog folder stored in the root folder of the www.site.ru site.

page 15

If the page does not use CSS styles and does not apply additional attributes, then the hyperlinks on the page by default display as follows:

  • regular links are displayed in blue;
  • visited links are highlighted in purple;
  • the active hyperlink (which has been clicked at the moment) is displayed in red, but since the time between clicking on the link and starting the download of a new document is quite short, such a link state is very short;
  • link text is underlined.

Internet addresses

The full address contains the Internet address of the web server and the path to the file to be obtained. For example:

http://www.site.ru/catalog/page15.html

Here www.site.ru is the address of the web server, and /catalog/page15.html is the path to the file on this server. In general, usually full Internet addresses are used only if it is necessary to create a hyperlink pointing to some resources located on another website.

When creating hyperlinks pointing to files that are part of the same site as the current web page, it is better to use shortened Internet addresses. The shortened address contains only the path to the file on the server, since the web server address is already known to the browser.

Abbreviated Internet addresses are absolute and relative... The absolute address specifies the path to the target file relative to the site's root folder. Such an address begins with a / (slash) character, which denotes the root folder. For example, the address “/page15.html” points to the page15.html file, which is stored in the root folder of the site. Or, the address "/catalog/page.html" points to the page.html file, which is located in the catalog folder nested in the root folder of the site.

The relative address is the file path relative to the file of the current web page. Relative addresses do not have a slash at the beginning. Let's look at a few examples.

For example, the address "page.html" points to a file that is located in the same folder as the file of the current web page. And the address "catalog / page.html" will open the page.html file stored in the catalog folder nested in the folder where the current page is stored. Using two dots at the beginning of the address, you can indicate the folders of the previous nesting level. For example, the address "... / page.html" points to the page.html page stored in the folder containing the current web page folder.

Link to mail

With the html language, you can create mail hyperlinks, clicking on which launches the mail client program. When specifying an address in an attribute href before the email you must put "Mailto:", i.e. something like this: href = "mailto: [email protected]". Moreover, there should be no spaces after the colon before the postal address.

write a letter

How to make a picture a link

This is where I finish talking about creating hyperlinks, I will only remind you of the main points:

  1. A paired tag is used to create links with the obligatory href attribute, in the value of which the address of the target page is placed: Text;
  2. When creating a link to mail in the href attribute, before the mail address, you must put "mailto:": write a letter;
  3. If you need to create link image, then just put the img tag inside the tag : .

Hyperlinks are the main asset of Web pages. This, in fact, is the core of the world wide web. That, without which it would have remained just another means of displaying documents. They are a visible display of the communication technology of a wide variety of Internet resources, which creates the unique integration of the Web.

We all know perfectly well that if, when viewing a Web page, hover the mouse cursor over a hyperlink embedded in the content of a Web page, the cursor will take the shape of a hand with an extended index finger, and a single click on this hyperlink will cause the browser to find that resource on the Web. that the hyperlink points to and download it.

Any fragment of the visible content of a Web page, that is, both text and graphics, can be used as a hyperlink. For this, the tag is applied<а>with its covering twin... Let's take a look at the simplest example.

Listing 1.15

"http://www.w3.org/TR/html4/strict.dtd">

Hyperlinks
<р>0 ordinary text.
Hyperlink to another web page



Rice. 1.15. Browser window showing the result of displaying the file shown in Listing 1.15

It is easy to see in fig. 1.15, the hyperlink is also highlighted to distinguish it from normal text. The highlight color is set by the remote user in their browser, but we have the ability to explicitly specify which color to use to highlight hyperlinks using style sheets. We'll look at their use in the next chapter. If we look at the code in Listing 1.15, we can see that the text that the hyperlink is linked to is surrounded by tags<а>and... In this case, the opening tag has the href parameter, the value of which is the URL of the Internet resource to which the created hyperlink points. In this case, the URL can be either full, that is, it includes the name of the resource access protocol, the name of the site and the page, As, for example, "http://www.mysite.com/mypage.htm", and relative, when you specify the path to a document located on the same site as the original Web page. In this case, a code similar to the following will be used:

<а href="/chap2/page1.htm">

Here we refer to a Web page in a file called pagel.htm located in the chap2 directory.
In general, the URL should be described in more detail. This is the only and absolutely accurate means of identifying any resources posted on the Web. In general, it can be written as follows:

http://www.mysite.com/fоlder1/file1.htm

The URL itself can be divided into three logical parts. At the very beginning of the URL, we describe the protocol used to access the Internet resource. Web pages use the HTTP protocol, as in our example. If you need to set a hyperlink to a file located on some FTP server, then this name is written in the initial part of the URL. There is also a mechanism that allows, when the mouse cursor clicks on a hyperlink, activate the mail client installed by the user in the system by default, and start the mode of writing a letter, while simultaneously specifying the recipient's address. For this, a hyperlink of the following form is used:

<а href="mailto://[email protected]">

As you can see, the key field mailto is used as a protocol designation, and after a colon and a pair of slashes, which always separate the protocol name from the main part of the address, the email address is written to which the email written by the user will be sent.

The second part of the URL describes the resource address itself. For a Web page, this is the domain name of the site. Usually a second or third level domain name is used. First-level domain names are written at the very end of the domain name. Within each first-level domain, regulatory organizations allocate second-level domain names. And the owners of second-level domain names independently create third-level domain names. So, practically, every owner of a second-level domain name assigns himself a third-level domain name WWW.

And the third part of the URL is the path to a specific file in the internal file space of the Web server. There is a small digression here to explain how Web servers work.

In order for any remote user to be able to access any Web site, which, as you know, is a collection of individual Web pages and specialized executable applications - scripts, it is necessary that all these Web pages are on a separate computer, running a specialized application called a web server. The responsibility of such a Web server is to receive requests from remote users, process those requests, and send the content of the Web pages to the remote users over HTTP.

For a Web server, a separate directory is allocated on the computer disk, in which html files containing Web pages are located, and applications - scripts that provide the interactive functions of the site. Naturally, within the general directory reserved for Web pages, we can create our own folder structures to more clearly separate the resources of the site. Thus, graphic images used in the design of Web pages are usually allocated to separate folders, the Web pages themselves are grouped in directories, according to their belonging to a particular section of the site. And the full path to some html file or other resource that is used in the design of Web pages, and is the third part of the URL. Let's look at a small example:

http://www.mysite.com/content/about.html

This URL points to a file called about.html, which is located in the content directory in the file space of the www.mysite.com Web server. In this case, the transfer to the user of the contents of the desired file will be carried out using the HTTP protocol.

However, in the field for entering the address of the Internet resource of any browser, you can enter only the domain name of the site, and we will already get access to the main Web page of this site. The fact is that if you do not specify the protocol in the input field, then the browser will automatically use the HTTP protocol. And if you do not specify the full name of the html file with the Web page, then the Web server that accepts a request from a remote user will display the main page of the site, often called home page, which is necessarily stored in a file named index.html, that is, each site must contain a file with this name, which is the start page of the Web site.

But at the same time it is necessary to realize that if in the browser we can afford to write the address incompletely, relying on its correct interpretation by the browser itself, then in the hyperlinks we are obliged to write the URL in full, except for those cases when the documents pointed to by the hyperlink are located on the same site as the original Web page. In such cases, we may not indicate the domain name of the site, limiting ourselves to specifying the protocol and full name, including the path in the file system of the Web server, of the resource to which the hyperlink points.

In fact, the tag<а>has a fairly large number of parameters that allow you to set a variety of properties of the hyperlink. As we study the material, we will look at all of them.

Hyperlinks are usually divided into global and local. Global hyperlinks point to Internet resources located outside the original Web page. Local links refer to some resources located on the current page. This technique is often used if the page contains a large enough amount of information that does not fit completely in the viewport. For example, we post a story or a text document divided into sections on a Web page. At the same time, at the beginning of this document, we can create its table of contents, acting on the basis of hyperlinks, each of which will point to a section of the document. Then the user who loads the Web page will be able to navigate the document using these hyperlinks, and not just using the vertical scroll bar, which undoubtedly facilitates navigation.

In order for us to use local hyperlinks in the document, we must first mark those fragments of the document to which they will point. For example, if we want some local hyperlink to move the remote user to a certain paragraph, then in this paragraph we must put the tag<а>with the name parameter. In this case, the hyperlink itself will be created using a slightly modified value of the href parameter. But it's easier to see all this with an example (Fig. 1.16).

Listing 1.16

"http://www.w3.org/TR/html4/strict.dtd">

Hyperlinks

It is easy to see from the listing text that when referring to an identifier located in the body of a Web page, we specify the name of this identifier with a hash sign in front of it as the value of the href parameter. However, in this way, we can use hyperlinks not only to fragments of the content of the original Web page, but also to fragments of other Web pages marked in a similar way. Such a hyperlink will look something like this:

<а href="http://www.mysite.com/doc2.htm/anch3">

That is, we combine the use of the full URL of the document and at the same time point to a certain fragment of it, marked as "anch3".

Rice. 1.16. Browser window showing the result of displaying the file in Listing 1.16

It should be noted that if the text pointed to by the hyperlink is already displayed in the viewport, as happened in our last example, then no change will occur. All you have to do is resize the browser viewport vertically to hide the last line of content that the hyperlink points to, and the result of its action can be visually demonstrated.

Naturally, all names of such bookmark markers, which are defined using the value of the name parameter, must be unique. Be aware, however, that HTML does not distinguish between uppercase and lowercase characters. Therefore, if two bookmarks are defined in our HTML document, which will subsequently be referenced by hyperlinks that differ only in the case of characters, then for the HTML analyzer built into the browser, these identifiers will be considered the same, and it will not process any of them.

However, we already know that it is possible to identify any element of an HTML document using the id parameter, which can be used as part of any tag. At the same time, hyperlinks pointing to document fragments can use these parameters as well, i.e., to set a bookmark marker to a tag, it is not necessary to use the tag<а>with the name parameter, you just need to use the id parameter.

The values ​​for the name parameter and the id parameter are unique identifiers for the elements in the HTML document. Therefore, no value for the name parameter should match any value for the id parameter.

But which option should you choose for your Web pages, which option should you use? Be aware here that while the id parameter can serve several purposes, such as identifying a bookmark marker, creating unique identifiers for executable DHTML scripts and styling, some legacy browsers may not accept these identifiers for targeting hyperlinks.

Together with the tag<а>the title parameter can be used to help identify the hyperlink to the remote user. The value of this parameter is a text string that will be displayed as a small hint when the user hovers the mouse cursor over the desired hyperlink. An ad for such a hyperlink looks like the following:

<а href="www.site.com" title="Very nice site">

Using the hreflang parameter, we can specify the language in which the text content of the Internet resource to which this hyperlink points is written. The parameter value is one of the standard language conventions that we discussed earlier in this chapter.
But specifying the language in which the textual content of a Web page is written is not enough. It is also necessary to indicate the encoding used. And here we can be helped by the already familiar charset parameter, the value of which is the standard designation of the encoding used to display the text content of the Internet resource pointed to by the desired hyperlink.

Using the gel parameter, we can indicate the purpose of the document that the hyperlink points to, that is, the value of this parameter clearly indicates the relationship between the original document and the document we are linking to. Using this parameter has no effect on how the hyperlink is displayed or how the resource is retrieved, but it can be useful. If Web pages are intended not only for viewing with a browser, but also for processing by some specialized applications. Such, for example, as advanced search engines, which are able to correctly recognize and handle such relationships between documents, indicated by hyperlinks.

The rel parameter uses one of the predefined keywords that we will now look at.

  • Alternate. The value indicates that the document is an alternate representation of the original document. If the lang parameter is used in the hyperlink with a value that is different from the language of the original document, then such a hyperlink is usually considered a link to a copy of the original document in another language.
  • Stylesheet. Indicates that the document referenced by the hyperlink is a style sheet. The mechanism for applying style sheets is described in detail in the second chapter.
  • Start. It is used to designate the initial, starting document of a certain set of documents. For a website, this would obviously be the home page.
  • Next. The value is used if the starting document and the document pointed to by the hyperlink are in some linear ordered sequence of documents, and the latter is next in sequence with respect to the original Web page.
  • Prev. The value is used in the same way as the previous one, but now indicates that the document in the chain is not the next, but the previous one, relative to the starting document.
  • index. Used in hyperlinks that point to a document that is the indexed content of the original Web page.
  • Glossary. The value indicates that the document contains a glossary of terms used in the original document.
  • copyright. Used when the document referenced by the hyperlink contains a copyright notice for the content of the original document.
  • chapter. Used in hyperlinks pointing to documents that are separate chapters in a set of documents.
  • section. Hyperlink with this parameter value rel indicates a document that is a section in a common set of documents that form a single whole of content.
  • subsection. The meaning is a continuation of the concept indicated by the previous meaning we have considered. It means that the document is already subsection.
  • Appendix. The value indicates that the document pointed to by the hyperlink is an attachment to the original document.
  • Help. Used for links to documents that provide additional reference information in relation to the content of the original document.
  • Bookmark. Used for links to HTML documents containing links to some highlighted key fragments of the source document.

When using these values, it should be borne in mind that in this case HTML parsers will be case-sensitive, so you must completely adhere to the spelling shown in our list.

In fact, in HTML there is an opportunity to create your own values ​​for the attribute we are considering, but since to use this parameter to the full, it is necessary to use specialized means of describing these new values ​​and software aimed at recognizing these types of links. Since we are interested in browsers, we don't need to create new types of links.

This technology is actually a palliative, which is designed to provide at least part of the possibilities provided by the new language for describing documents on the Internet - XML ​​(extensible Markup Language), which is predicted to be the successor and "killer" of HTML. But there are no widespread XML browsers yet. applications that process XML documents. And for quite a long time this technology will not become generally accepted, which means that HTML technology still has every right to exist and will be used as the basis for Web pages for a long time to come.

But back to looking at the attributes of the tag<а>... The rev attribute is the opposite of the rel attribute. If the rel attribute specifies the type of document that the hyperlink points to, then the rev attribute specifies the type of the original document that contains the hyperlink. The same set of keywords that was used for the rel attribute is used as the values ​​for this attribute.

Using the target parameter, we specify in which frame the document that the hyperlink points to should be displayed. The point is that usually one document is displayed in one browser viewport. But in HTML it is possible to divide the viewport into several areas, called frames, each of which will display its own HTML document. We will consider the technology of using frames in one of the following sections of this chapter, but for now, we just note that the target parameter allows you to explicitly specify in which frame the Web page should be displayed. Setting up a hyperlink using this parameter will look something like this:

<а href="http://www.mysite.com/docl.html" target="_top">

Such a hyperlink will cause the browser to load the Web page whose URL is specified as the value of the href parameter into the top frame, whose name is specified in the target parameter. The last parameter uses the keywords defined in the HTML specification. We'll cover them in the section on frames.

Some input organs and hyperlinks allow you to move the input focus among themselves using the tabulation key, that is, one press of this key activates the next input organ included in the general sequence. And the order of movement between the controls included in the general sequence is set using the tabindex parameter. As the value of this parameter, an ordinary positive integer is used, and the larger this number is at any data entry body or hyperlink, the later it will come to it when the input focus is moved. Naturally, no pair of Web page design elements should have the same value, otherwise the browser will simply not include them in the sequence of elements with a focus movement.

However, in addition to accessing by successive tab key presses, we can use the access key parameter, the value of which is a character. When the user presses the key that is responsible for entering this character, the Input focus is automatically transferred to the desired hyperlink, in the declaration of which the access key parameter is embedded, and the user can activate it without using the mouse, just by pressing the key ... Let's look at a small example:

<а href="http://www.mysite.com/docl.html" tabindex="2" accesskey="U">

The carrier of a hyperlink can be not only text, but also a graphic image. To do this, you need to place a tag announcing the insertion of graphics into the content of a Web page between the tags<а>and... But the fact is that we can "hang" not one, but several hyperlinks on a graphic image, that is, several active areas are highlighted within the image, clicking on each of them activates the corresponding hyperlink. A similar technology is called segmented graphics.

To create such graphic images associated with multiple hyperlinks, specialized tags are used. First, the active areas of the drawing, also called segments, are declared. All of them make up a map of the active segments of the picture, which is assigned a certain name. And then this map name is associated with the image itself, declared using the tag . Let's consider a typical example.

Listing 1.17

! DOCTYPE HTML PUBLIC "- // W3C // DTD HTML 4.01 // EN"
"http://www.w3.org/TR/htm!4/strict.dtd">


Segmented graphics

<р>This is plain text.



First area
Second area
Third area


In this example, you can see that when declaring a picture, in the tag we insert the usemap parameter, the value of which is the name of the map of the active image segments associated with hyperlinks. A hash symbol is inserted before the name of the active segment map used. The description of this card is placed between the tags and... In this case, the opening tag there is a required parameter name, the value of which is the name of the card.

The map consists of a description of the segments. Each segment is described with one tag<агеа>... We can apply hotspots in three different shapes: rectangles, circles, and polygons. The shape is specified using the required shape parameter. As the value of this parameter, we can use one of the three preset values.

  • Meaning rect used to create rectangular hotspots.
  • Meaning circle used to create a circular segment.
  • Meaning poly allows you to create active segments in the form of convex polygons.

After we have set the type of form, it is necessary to accurately determine their size and location on our graphic image. For this, the coords parameter is used, as the value of which is written a list of coordinates that define the active segment. In Listing 1.17, we can see that the coordinates in the general list are separated by a regular comma. The coordinates are counted from the upper left corner of the picture, which has coordinates (0; 0).

For rectangular segments, specify the coordinates of the upper-left and lower-right corners. And for polygons, the coordinates of all points are sequentially listed, in the order of their connection by lines. Naturally, the first and last pair of coordinates must match, otherwise the polygon will be open and the active segment will not be processed.

Into the tag<аrеа>the href parameter is also included, the value of which is the URL of the resource pointed to by the hyperlink of this segment.
But this parameter, surprisingly, is optional. In the case where a segment is being created but should not be linked to a hyperlink, the nohref parameter should be used, which is irrelevant.
But a required parameter for the tag<аrеа>everything is just like that. This is the alt parameter, which is a text string that is an alternative representation of the picture. As we know, this line is displayed as a hint when the user hovers over the object. In our case, such an object is an active segment embedded in a graphic image.

Also in the tag<агеа>Like normal hyperlink tags, the tabindex and access key parameters are used to activate the hyperlink without using the mouse, using only the keyboard. We examined the structure of the values ​​of these parameters a little earlier. As a sidetrack, it should be noted that any proper webmaster should definitely use these parameters, since only their use can guarantee the activation of hyperlinks without the help of a mouse.

So, we figured out the use of segmented graphics technology. But we have not learned everything about links. The HTML spec defines a tag , which does not create a hyperlink that we are used to, but some connection between the displayed document and some additional file. Tags: can only be placed in the head section of an HTML document, between tags and As an example of the use of the tag we are considering you can give the following piece of code:

Listing 1.18

"http://www.w3.org/TR/html4/strict.dtd">


Chapter 2



With this snippet, we indicate that this Web page contains the second chapter of some extensive document, and using tags link to web pages containing the table of contents and the previous and next chapters. The type of document that the link points to is determined using the familiar rel parameter. A normal browser, of course, will not be able to process and display such links in any way. They were introduced into HTML to create documents that would be processed with the help of some specialized applications that allow creating workflow systems based on this format. But the built-in meager capabilities of HTML for creating full-fledged workflow systems were clearly not enough, and when the XML standard was developed, the developers happily changed their favorite.

So it turns out that in regular Web pages the tag absolutely useless? Not really. Only with this tag can we connect Web pages to external style sheets, the most powerful way to control how a document is displayed in a browser. But we will learn about style sheets a little later, in the second chapter. There we will also consider an example of using the tag ... For now, we just have to list the parameters of this tag. All of these parameters apply to tags as well.<а>with the same possible values, so we will not consider each parameter in detail, but simply list them briefly:

  • charset- indicates the encoding of the document to which the link points;
  • href- the URL of the document to which the link points is used as the value;
  • hreflang- the value is the code designation of the language in which the linked document is written;
  • type- sets the type of the document to which the link points;
  • rel- sets the status of the document to which the link points in relation to the original document;
  • rev- sets the status of the source document in relation to the one to which this link points;
  • media- indicates the type of device on which the referenced document will be displayed.

Currently, documents displayed on conventional monitors, on braille monitors for the visually impaired, for printers and speech reproduction devices are supported. And, of course, in addition to these parameters, a set of additional identification parameters common to all tags is used.

It remains for us to consider only one tag used to serve hyperlinks. As we know, we may omit the full URL for hyperlinked documents if the document is located on the same Web site as the original Web page. But it turns out that we can do the same with hyperlinks to Web pages that are part of other sites.

Using the tag we set the base for hyperlinks with shortened href values. Let's try to demonstrate the operation of this mechanism using a simple and illustrative example:

"http://www.w3.org/TR/html4/strict.dtd">

Web Page

<Р>Text<А href="/pages/birds.gif">Link


As the value of the required parameter href tag we define the document that is the basis for the content of the web pages of our site. And now, if in the body of our HTML document we use a hyperlink with a shortened URL, then the domain name for this URL will not be the name of the original site, but the one specified in the tag ... So in the example, the hyperlink points to a document

c URL www.mysite.com/pages/birds.gif.

It should be clarified that the tag placed in the head of the document between tags and .

And that's all we can talk about using hyperlinks in HTML.

Hypertext is text that contains links to other text. An example is the author's notes on complex definitions or translators' footnotes at the bottom of a book page if it contains text in a foreign language. Internet sites are a complex system of hypertext transitions from one page to another, within the page itself, as well as between unrelated resources. This structure is practical, saves a lot of time, allows the visitor to quickly find the necessary information and not get lost in a large number of transitions.

Insert a hyperlink

In HTML, a descriptor (tag) is used to insert a hyperlink that is inserted at the desired location. It is usually placed in the middle of the text, since the hyperlink itself is a text structure. But links are also graphical (icons, buttons, pictures); they will be discussed further. Their location on a web page is not limited to text, but depends on the design decision of the site creator.

google home page

This is an example of how to insert a hyperlink into an HTML document using the tag ... The site visitor will see the underlined text, which is different from the color of the surrounding text (the color of the HTML-link can be any), the "Google home page", by clicking on which, he will be taken to the main page of the Google search engine. It should be noted that the text of the hyperlink must contain information about where the transition will be made. This principle should be adhered to and accepted as a rule!

Tag structure ...

You may notice that the tag - paired: an end tag is required.

href — attribute tag specifies the purpose of the link.

https://google.com/ - attribute value that contains the URL of the resource to be navigated to. It is enclosed in double or single quotes. It depends on the nesting structure of tags according to HTML rules.

google home page

this whole construction is called element web document.

According to HTML rules, some elements can contain other elements. Tag not an exception. If a programmer needs to highlight the word Google in bold, then this is done using a tag according to the general rules of text formatting, observing the sequence of nesting tags. The webmaster needs to know how to create a hyperlink in HTML without errors, otherwise they won't work. Broken links in computer slang are called "broken".

home page Google

Here: element

home page Google

contains a nested element

Google

Absolute hyperlinks

protocol: // domain name / file path

An example of the address of a search engine common in America: https://aol.com - absolute, since it contains the domain name.com.

Absolute hyperlinks are used to navigate to pages on other sites or to access resources located on another server. The transition is carried out using Internet protocols. Protocols are not the topic of this article, but since they are involved in creating hyperlinks, it is necessary to at least briefly mention them:

  • http and https - the most common; they are used to navigate between the Internet pages of different sites;
  • ftp - protocol for uploading files to a server or downloading by a user from a site;
  • mailto - postal protocol, by which e-mail is sent directly from the site, without going into personal mail.

There are several other special-purpose protocols (gopher, telnet), which are quite rare, the use of which requires special knowledge in programming or system administration.

Relative hyperlinks

With relative addressing, the use of hyperlinks in HTML serves to navigate within the resource and does not lead outside of it. If the page is so large that a vertical scroll bar works, sometimes very long, as, for example, in dictionaries, then it is very convenient and advisable to use relative links to quickly jump to the desired letter.

When creating an Internet dictionary, the programmer places the alphabet at the beginning of the page, and if not for the use of links, the user would have to turn the mouse wheel for a very long time to get to the letter "I".

Go to the letter I

where ya called anchor, a Go to the letter I- anchor destination. For the correct display of anchors, it is recommended to use Latin letters and numbers, so you should not write "I", although it would be clearer that way.

Now, in order for the transition from the alphabet at the beginning of the page to the letter "I" to be carried out, you need to anchor the anchor in the place of the HTML document in which the words begin with the letter "I":

letter I

there is a hash mark in front of the anchor, without which the transition to the letter will not work.

Relative addressing when creating a site

Convenient and most generally accepted algorithm for creating a website by a programmer:

  • creating a folder on your computer and placing it in a quick access location for convenience;
  • creating the main folder in this folder;
  • creation of secondary web pages (index.html / page2);
  • and placement of graphic files in it;
  • creating a folder and placing other objects in it (files for downloading, for example);
  • filling the site with content;
  • placement of site files on hosting.

You will definitely have to use links to link between the elements of the site, and it will be very useful to know how to insert a hyperlink in HTML on another page of the same site. If the site files are located in the same directory, on the same server, then there is no need to use absolute addressing. When transferring site files to hosting, the connection between the objects will be preserved, because they will also be located in the same directory on the hosting.

Let's say a programmer has created the main page of the site index.html, which has a link to another page, page2.html, decorated with an img.png image. Then the relative path to this picture will look like this:

picture

Tip: When learning this topic, it is best to use a simple text editor, due to the fact that you need to acquire a knack for spelling jump addresses correctly and in order to learn how to understand someone else's code. At this stage, the written hyperlink in the notepad will be a good result without errors,HTML does not forgive them and gives errors.

Ways to follow hyperlinks

By default, a new page opens in the current browser window when the user clicks on a hyperlink. But a web programmer can change the default and force the page to open, for example, in a new window. For this there is an attribute target with a certain value. This can be most clearly expressed in a table.

Attribute Syntax target:

google home page

The Google home page will open in a new window.

Note: to open pages in a new tab, there are no values ​​for this attribute, but is set by the user himself in the browser settings.

Hyperlink color

An experienced Internet user should have noticed over time that hyperlinks differ in color from the surrounding text and are usually blue. The links that he followed and then returned to the previous page turn purple. The use of hyperlinks in HTML in a non-standard color scheme is a little bit, but it makes the site stand out from the rest.

Sets the colors of links in the tag with the help of attributes and their values, in which the HTML color in the rgb system appears (# 00FF00) or with a direct indication of the color name ("green"). There are three types of link attributes:

  • link - sets the color of an unvisited link;
  • vlink - sets the color of the link that the user has already followed;
  • alink - sets the color of the link at the moment of transition to another page. This happens quickly, so it is not always possible to catch this effect.

Example markup:

If you apply these attributes in the tag , links for this web document will be dark blue, visited links will be purple, and active links will be orange-red.

Graphic hyperlinks

The progress and development of web design makes it imperative to know how to insert a hyperlink in HTML as an image. It is clear that the picture must match the content of the destination page. For example, the main page of a site about medicinal plants can be presented in the form of photographs of plants, by clicking on which, the user will go to a page that describes the medicinal properties of the plant.

The method of replacing static buttons ( ) to beautiful graphics created by a web designer in graphics editors (GIMP, Photoshop).

To insert graphics as hyperlinks on site pages, the same syntax is used, only instead of text, an image insert tag is used according to HTML rules:

Attributes for setting alternate text, width, height, and others apply in the same way.

Calls from the site

The html5 standard has expanded the functionality of using the Internet, and now you can make calls not only from your phone, but directly from the site. For this purpose, you can also use hyperlinks in an HTML document, and they have the following syntax:

...subscriber...

Instead of the word "subscriber", a contact that is understandable to the caller is prescribed, as in the phone book. You can also place a graphic file (subscriber's photo).

For calls to be made from the site, it is necessary to have not only a link to the subscriber's phone number, but also a headset (microphone, headphones) installed on the computer VoIP program, the Internet speed must exceed 0.5 Mb / s. Calls are paid for by traffic consumption. Therefore, if the Internet is unlimited, then the calls are free.

Ethics of creating hyperlinks

When placing a website on the Internet, a webmaster must know what types of hyperlinks exist in HTML, and not only correctly and professionally apply them, but also adhere to the following provisions:

  • The hyperlink should be clearly visible and distinct from the surrounding text. The user should know that this is a hyperlink.
  • It should be clear to the user where he will go by clicking on the link. For this, it is advisable to use another attribute title, which succinctly describes the transition page. The syntax for applying the attribute is as follows:

Yandex

  • The user must receive truthful information about the file that will be downloaded when clicking on the link.

Having got to the wrong page or downloaded the wrong file, the user in 99% of cases will immediately leave the site and in the future will never go to it.

Anti-SEO when creating hyperlinks

In addition to the technical side of the question of how to insert a hyperlink in HTML, there is also a moral aspect to be highlighted. There are many sites to which users are blocked by security software (antivirus) or even by the government. These are the sites that were created by dishonest web programmers.

One of the tricks they use is to insert "invisible" hyperlinks into a web page. Fraudsters know how to create a hyperlink in HTML, and use the attributes to remove the underline of the link and assign it the color of the surrounding text so that the average user does not see it. And with the help of other web technology tools (CSS, JavaScript, PHP), you can program their behavior. For example, the JavaScript OnMouseOver event triggers an action on a web page element. When a user hovers over an invisible link, he is taken to the advertising page of another site. Or even worse, when there is an invisible link to a file and unnecessary software starts to be downloaded and installed on his computer. Usually these are viruses that change the browser home page, clutter up the hard disk with a lot of programs, and so on.

Soon such sites will be included in the "black list" of virus databases, security systems and among the Internet users themselves. Such sites do not live long, and they have to change their names, endlessly migrate over the Internet, changing host providers. This does not contribute to the promotion of the site, which its creator always strives for, will never make it a megaportal, such as, for example, social networks. Among other things, such tricks cause a lot of negative emotions in people affected by these actions.



Did you like the article? Share it