Links in HTML

This lecture notes is based on Prof Doreen De Leon's lectures.

Reading

Sebesta Section 2.6

Absolute and Relative URLs

The <a> tag

Creating a reference within a document

Example

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//w3c//DTD XHTML 1.0 Strict//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head><title>My favorite</title></head>
<body>
<h2>My favorite web sites</h2>
<a href="http://www.cnn.com">CNN</a><br />
<a href="http://www.latimes.com">LA times</a>
</body>
</html>

My favorite web sites

CNN
LA times


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//w3c//DTD XHTML 1.0 Strict//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head><title>Car</title></head>
<body>
<h2>Cars</h2>
Click the icon to <i>cars.com</i>
<a href="http://www.cars.com"><img src="cars.gif" alt="car" /></a>
</body>
</html>

Cars

Click the icon to cars.com car


<h2 id="reading">Reading</h2>

Click <a href="#reading">here</a> to go to the Reading section.

Click here to go to the Reading section.


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//w3c//DTD XHTML 1.0 Strict//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head><title>Link</title></head>
<body>
<a href="index2.html">Link index2.html</a>
</body>
</html>


Link index2.html