Stay a href http site. External links, HREF attribute
(HTML Anchor Element).
The main function of links is that they allow you to move from one HTML document to another, or contain the address of a file intended to be opened in the user's browser, or for further downloading.Browser support
Tag | Opera | IExplorer | Edge |
|||
---|---|---|---|---|---|---|
Yes | Yes | Yes | Yes | Yes | Yes |
Attributes
Attribute | Meaning | Description |
---|---|---|
charset | char_encoding | Not supported in HTML5. Specifies the encoding of the associated document. |
coords | coordinates | Not supported in HTML5. Defines the coordinates of the link. |
filename | If the attribute is specified, then the browser does not follow the link, but offers to download the document specified in the link address. | |
href | URL | Sets URL the page or document to which the link leads. |
hreflang | language_code | Defines the language of the linked document to which the link leads. |
media | media_query | Indicates that the document to which the link leads is adapted for certain types of devices. |
name | section_name | Not supported in HTML5. Specifies the name of the anchor. Use the global attribute instead. |
rel | alternate author bookmark help license next nofollow noreferrer prefetch prev search tag | |
rev | text | Not supported in HTML5. Indicates the relationship between the current document and the related (linked) document. |
shape | default rect circle poly | Not supported in HTML5. Defines the shape of the link (used with the coords attribute). Use the element instead of this tag. |
target | _blank _parent _self _top framename | Specifies where to open the document. |
type | media_type | Indicates MIME type of the document to be navigated to. |
Usage example
In the browser, this will be displayed by default as follows: Everything will be found.
The href attribute (an abbreviation for hyper reference) is the main attribute of the tag, indicating to the browser Page URL where the link leads. Uniform Resource Locator(English) Uniform Resource Locator, ) - a uniform locator (location identifier) of the resource.
Relative and absolute link paths
The above example uses an absolute path address. The name absolute is due to the fact that we specify the full web address of the page as the path to the file. Below are examples of specifying absolute paths:
Element Content href = "http://www.yandex.ru" > Element content href = "//www.yandex.ru" > Element contentPlease note that in most cases, absolute link paths are used for pages or files that are located on other resources (not located on the same server as the page from which they link).
If the page or file being linked to is located on the same server as the page being linked from, then, as a rule, relative link addresses are used. The main feature of relative links is that they are placed relative to the root of the site or the current HTML document.
Path relative to the current document
I suggest first understanding the paths relative to the current HTML document. Regardless of what kind of wilds the file is located in, you will set the path relative to this file.
Example of connecting files:
Let's move on to the next example, let's say we have a file index.html, in the same directory there is a folder (directory) named etc from which we need to connect an image and make a link to the document page.html:
Please note how we indicate the path to our files - we specify the name of the directory and, using a forward slash, indicate the name of the file we need. This directory is a child directory in relation to the current directory, and in order to include the necessary files we go down one level below ( directory_name/required_file).
Well, the final example, in which we need to connect to our page an image that is located in a directory that is located two levels above the current page and we need to add a link that is one level above the current page:
Please note that if the file is in a parent folder, you must use the symbols ../ this will move you up one level. You can use the ../ symbols to go up until you get to the root folder of your site or hard drive.
Path relative to the site root
I would like to immediately draw your attention, in order for the path relative to the site root to work on your local computer, you must have a software environment installed that allows you to emulate a web server.
If you are planning to create websites and you do not have an environment for your training, then I recommend that you download a software package designed for local development, debugging and testing of web projects. I am using Open Server, it is intended for users who use the Windows operating system. As an analogue Open Server under Mac, I can suggest MAMP, if it doesn’t suit you, you can try choosing another one.
Let's move on to the next example, in which we need to connect files that are located on the web server. Using a piece of this site as an example, let’s connect from folders primer one image and one html file:
As with using absolute addresses, the way to set a path relative to the root of the site is quite simple. The only difference is that we no longer need to specify the domain name, and, accordingly, relative paths are used only within one server.
Note that you must include a forward slash at the beginning of the path, this tells the user's browser that the path begins at the root directory.
target attribute
The target attribute is used to tell the browser where to open the web page. The following example opens the document in a new browser window:
SearchBelow are all the values of this attribute:
Working with frames will be discussed later in the tutorial article "".
mailto attribute
Using the "mailto" attribute in an HTML document allows you to create a link to send an email:
Write to the authorIn the attribute value, you can immediately specify the values for the headers (subject, copies, body of the letter, etc.). Spaces and line breaks cannot be inserted without coding:
> Write to the author- subject - subject of the letter.
- cc - copy of the letter.
- bcc - hidden copy of the letter.
- body - the body of the letter.
It is acceptable to indicate several addresses (or not indicate them at all):
" mailto:mail_1@some.com, mailto:mail_2@some.com "> Write to the authorImage as link
In order to use an image as a link, you need to place the image between .
Link html- this is one of the basic concepts in creating HTML documents. Every Internet user has used them at least once. Every time you click on the Internet to go, view, read, read more, click on news, etc., you use links! The pages you click on may be on completely different sites.The link is usually highlighted with an underline and blue color. However, links of other colors, images, and areas of the site can serve as links.
Go to Yandex