In HTML, different HTML elements have attributes that point to other resources. The value of these properties is a URL, which can be absolute or relative.
Relative URLs do not contain the full URL. With relative URLs, we automatically start at the address where the browser is currently located and then add the path component and extension. Explicitly tell the browser to use the current folder.
The following is the syntax for linking pages using relative URLs.
<a href="relative URL">Link text…</a>
The following is a sample program that uses relative URLs to link pages.
<!DOCTYPE html> <html> <body> <h2>Relative link</h2> <h3>Sign In Page</h3> <form> <label for="fname">Email Address</label><br> <input type="text" id="fname" name="fname" ><br> <label for="lname">Password</label><br> <input type="text" id="lname" name="lname" ><br><br> <input type="submit" value="Login"> <a href="Untitled-2.html">Sign Up</a> </form> </body> </html>
<!DOCTYPE html> <html> <body> <h2>Relative link</h2> <h3>Sign Up Page</h3> <form> <label for="fname">Name</label><br> <input type="text" id="fname" name="fname" ><br> <label for="email">Email</label><br> <input type="text" id="email" name="email" ><br> <label for="fname">Password</label><br> <input type="text" id="fname" name="fname" ><br> <label for="lname"> Re-enter Password</label><br> <input type="text" id="lname" name="lname" ><br><br> <input type="submit" value="Submit"> <a href="Untitled-1.html">Login</a> </form> </body> </html>
In the above example, we linked two different pages using relative URLs. Relative URLs do not contain the full URL. As we can see in the sample program above.
The above is the detailed content of How to link pages in HTML using relative URLs?. For more information, please follow other related articles on the PHP Chinese website!