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.
- We open the notebook.
- We write the code in html language. for example a page with a number of photos.
- 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 locatedHere 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:
Tell me, dear child: in which ear is my buzzing?
V right or left?
Primer.html file:
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:
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:
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:
- 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;
- When creating a link to mail in the href attribute, before the mail address, you must put "mailto:": write a letter;
- 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">
<р>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">
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
<а 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">
<р>This is plain text.