search
HomeWeb Front-endHTML TutorialThe href attribute of the HTMLa tag specifies how to use relative paths and absolute paths

This time I will bring you the href attribute of the HTMLa tagSpecify the relative path and absolute path usage, use the href attribute of the HTMLa tag to specify the relative path and absolute path usageNotesWhat are they? The following is a practical case. Let’s take a look.

In actual Web development, inserting

images, including CSS files, etc. all require paths. If the file path is added incorrectly, it will cause the reference to become invalid (unable to Browsing linked files, or inserted pictures 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:

文件1.htm的绝对路径是:d:/www/html/1.htm
文件2.htm的绝对路径是:d:/www/html/2.htm
那么:1.htm相对于2.htm的路径就是:1.htm

How to use relative links:

If you link to the same directory, you only need to enter the name of the document to be linked, for example:

<a href =”1 htm”>网页链接 </a>  
<img  src=”bg.jpg” / alt="The href attribute of the HTMLa tag specifies how to use relative paths and absolute paths" >

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

<a href =”html/ next.htm”>  
<img  src=”images/bg.jpg” / alt="The href attribute of the HTMLa tag specifies how to use relative paths and absolute paths" >

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

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

Example summary


现在有4个html文件分别是aaa.html bbb.html ccc.html index.html
aaa.html的路径为:D:/www/adminwang/html/aaa.html
bbb.html的路径为:D:/www/adminwang/ bbb.html
ccc.html的路径为:D:/www/ ccc.html
index.html的路径为D:/www/ index.html

1. Link files in the same directory

For example, ccc.html file link The code of index.html is as follows:

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

2. Link to the file in the previous directory

For example, the code of bbb.
html link to ccc.html is as follows:

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

3. Link files in the upper 2-level directory

For example, the code for linking aaa.html to ccc.html is as follows:

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

4. Linking files in lower-level directories

For example, ccc.html links to bbb.html The code is as follows:

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

5. Link files in the lower 2-level directory

For example, the code for ccc.html to link aaa.html is as follows:

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

HTML absolute path

Provide the file The full path to , 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

There is nothing to say about the absolute path. Once you master the relative path, the absolute path is very simple.


I believe you have mastered the methods after reading these cases. For more exciting information, please pay attention to other related articles on the php Chinese website!

Related reading:

Detailed explanation of examples of HTML text formatting

Summary of frequently used tags in html

The basics of HTML editing (a must-read for beginners)

The above is the detailed content of The href attribute of the HTMLa tag specifies how to use relative paths and absolute paths. For more information, please follow other related articles on the PHP Chinese website!

Statement
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
HTML: Building the Structure of Web PagesHTML: Building the Structure of Web PagesApr 14, 2025 am 12:14 AM

HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.

From Text to Websites: The Power of HTMLFrom Text to Websites: The Power of HTMLApr 13, 2025 am 12:07 AM

HTML is a language used to build web pages, defining web page structure and content through tags and attributes. 1) HTML organizes document structure through tags, such as,. 2) The browser parses HTML to build the DOM and renders the web page. 3) New features of HTML5, such as, enhance multimedia functions. 4) Common errors include unclosed labels and unquoted attribute values. 5) Optimization suggestions include using semantic tags and reducing file size.

Understanding HTML, CSS, and JavaScript: A Beginner's GuideUnderstanding HTML, CSS, and JavaScript: A Beginner's GuideApr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

The Role of HTML: Structuring Web ContentThe Role of HTML: Structuring Web ContentApr 11, 2025 am 12:12 AM

The role of HTML is to define the structure and content of a web page through tags and attributes. 1. HTML organizes content through tags such as , making it easy to read and understand. 2. Use semantic tags such as, etc. to enhance accessibility and SEO. 3. Optimizing HTML code can improve web page loading speed and user experience.

HTML and Code: A Closer Look at the TerminologyHTML and Code: A Closer Look at the TerminologyApr 10, 2025 am 09:28 AM

HTMLisaspecifictypeofcodefocusedonstructuringwebcontent,while"code"broadlyincludeslanguageslikeJavaScriptandPythonforfunctionality.1)HTMLdefineswebpagestructureusingtags.2)"Code"encompassesawiderrangeoflanguagesforlogicandinteract

HTML, CSS, and JavaScript: Essential Tools for Web DevelopersHTML, CSS, and JavaScript: Essential Tools for Web DevelopersApr 09, 2025 am 12:12 AM

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

The Roles of HTML, CSS, and JavaScript: Core ResponsibilitiesThe Roles of HTML, CSS, and JavaScript: Core ResponsibilitiesApr 08, 2025 pm 07:05 PM

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

Is HTML easy to learn for beginners?Is HTML easy to learn for beginners?Apr 07, 2025 am 12:11 AM

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

See all articles

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft