Home Web Front-end HTML Tutorial Explanation on the usage of HTML a tag href attribute to specify relative path and absolute path

Explanation on the usage of HTML a tag href attribute to specify relative path and absolute path

Jun 05, 2018 pm 02:50 PM
href html path

href is one of the most commonly used important attributes for linking front-end files. Here we will take a look at the usage of the HTML a tag href attribute to specify relative paths and absolute paths. Friends who need it can refer to

In actual web development, inserting pictures, including CSS files, etc. all require paths. If the file path is added incorrectly, the reference will become invalid (the linked file cannot be browsed, or the inserted picture cannot be displayed, etc.). Many beginners are confused. Below I will introduce relative paths and absolute paths in detail.

HTML relative path
refers to the path relationship with other files (or folders) caused by the path where this file is located.
For example:
The absolute path of file 1.htm is: d:/www/html/1.htm
The absolute path of file 2.htm is: d:/www/html/2.htm
Then: the path of 1.htm relative to 2.htm is: 1.htm

How to use relative links:
If the link is to the same directory, just Enter the name of the document to be linked, for example:

XML/HTML CodeCopy the content to the clipboard

<a href =”1 htm”>网页链接 </a>
<img src=”bg.jpg” />
Copy after login

If linking to the next level directory , you need to enter the directory name first, then add "/", and then enter the file name, for example:

XML/HTML CodeCopy the content to the clipboard

<a href =”html/ next.htm”>
<img src=”images/bg.jpg” />
Copy after login

If you connect to the upper-level directory, you need to enter "../" first, and then enter the directory name and file name, for example:

XML/HTML Code Copy content to clipboard

<a href = “../ www/index.htm”>
Copy after login

Example summary
There are now 4 html files, namely aaa.html bbb.html ccc The path of .html index.html
aaa.html is: D:/www/adminwang/html/aaa.html
bbb.html is: D:/www/adminwang/ bbb.html
The path of ccc.html is: D:/www/ ccc.html
The path of index.html is D:/www/ index.html

1. Link files in the same directory
For example, the code for the ccc.html file link index.html is as follows:

XML/HTML CodeCopy the content to the clipboard

<a href="index.html">链接index网页</a>
Copy after login

2. Link to the file in the previous directory
For example, the code for linking bbb.html to ccc.html is as follows:

XML/HTML Code Copy the content to the clipboard

<a href="../ccc.html">链接ccc网页</a>
Copy after login

3. Link the files in the upper 2-level directory
For example, the code for linking aaa.html to ccc.html is as follows:

XML/HTML CodeCopy the content to the clipboard

<a href=”../../ccc.html”>链接ccc网页</a>
Copy after login

4. Link files in lower-level directories
For example, ccc.html link The code of bbb.html is as follows:

XML/HTML CodeCopy the content to the clipboard

<a href="adminwang/bbb.html">链接bbb网页</a>
Copy after login

5. Link to the next 2 levels Directory files
For example, the code for ccc.html link aaa.html is as follows:

XML/HTML CodeCopy the content to the clipboard

<a href="adminwang/html/aaa.html">链接aaa网页</a>
Copy after login

HTML Absolute Path
Provides the full path to the file, including the applicable protocol or drive letter. That is, the real full path of the file or directory on your home page on the hard disk. For example:
http://www.adminwang.com/index.htm
d:/ www /html/images/bg.jpg
Absolute path has nothing to say, relative path is mastered, absolute path is It's very simple.

Related recommendations:

How to prevent hyperlink jumps when using a link

in HTML Detailed explanation of the use of tags

The above is the detailed content of Explanation on the usage of HTML a tag href attribute to specify relative path and absolute path. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Table Border in HTML Table Border in HTML Sep 04, 2024 pm 04:49 PM

Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.

HTML margin-left HTML margin-left Sep 04, 2024 pm 04:48 PM

Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.

Nested Table in HTML Nested Table in HTML Sep 04, 2024 pm 04:49 PM

This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.

HTML Table Layout HTML Table Layout Sep 04, 2024 pm 04:54 PM

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

HTML Input Placeholder HTML Input Placeholder Sep 04, 2024 pm 04:54 PM

Guide to HTML Input Placeholder. Here we discuss the Examples of HTML Input Placeholder along with the codes and outputs.

Moving Text in HTML Moving Text in HTML Sep 04, 2024 pm 04:45 PM

Guide to Moving Text in HTML. Here we discuss an introduction, how marquee tag work with syntax and examples to implement.

HTML Ordered List HTML Ordered List Sep 04, 2024 pm 04:43 PM

Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively

HTML onclick Button HTML onclick Button Sep 04, 2024 pm 04:49 PM

Guide to HTML onclick Button. Here we discuss their introduction, working, examples and onclick Event in various events respectively.

See all articles