Lesson 12 / الدرس 12

Links: absolute and relative paths / الروابط: المسار المطلق والنسبي

The <a> tag turns text into a link. Its href attribute is the destination — another site, a file beside yours, an email address, or a phone number.

الوسم <a> يحوّل النص إلى رابط، وسمته href هي الوجهة: موقع آخر، أو ملف بجانب صفحتك، أو بريد إلكتروني، أو رقم هاتف.

A link lets the visitor move from one place to another with a click or a tap. You write it with the <a> tag — short for "anchor" — and its most important attribute, href, which holds the address it goes to.

<a href="https://example.com">Visit our site</a>
The text between the tags is what the visitor sees and clicks; href is where the click takes them. Press "Try it live" and change the text or the address.

Absolute paths and relative paths

An absolute link is a full address, starting with https:// — it works from anywhere, because it names the whole site. A relative link is just the name of a file sitting beside your own page, with no https:// in front — it only makes sense from inside your own project, because the browser looks for it next to the page it is on.

<a href="https://example.com">Another site</a>
<a href="about.html">About us (a page next to this one)</a>
The first link goes anywhere on the web. The second only works if a file named about.html really sits next to this page — that is what "relative" means.

Opening a link in a new tab

By default a link opens in the same tab, replacing the page the visitor is on. Add target="_blank" to open it in a new tab instead. Save it for links that take the visitor away from something they were doing — a source you are citing, a file to download — not for ordinary navigation on your own site: forcing every link into a new tab fills the visitor's phone with tabs they did not ask for, and the page they expect the "back" button to reach is gone.

Email and phone links

Two special prefixes turn a link into an action instead of a page. mailto: followed by an address opens the visitor's email app with that address already filled in as the recipient. tel: followed by a number opens the phone dialer with that number ready to call — most of your visitors are on a phone, so this one link can save them from copying a number by hand.

<a href="mailto:hello@example.com">Email us</a>
<a href="tel:+962791234567">Call us</a>
Tap the first link on a phone and it opens a new email addressed to hello@example.com. Tap the second and it offers to dial +962791234567.
PatternWhat it does
href="https://..."Absolute link — works from anywhere
href="about.html"Relative link — a file beside your own page
target="_blank"Opens the link in a new tab
href="mailto:..."Opens the visitor's email app
href="tel:..."Opens the visitor's phone dialer

The patterns used in this lesson.

Try it live / جرّب بنفسك

Preview / المعاينة

Check yourself / اختبر نفسك

1. Which of these is a relative link?

2. You write href="example.com" hoping it links to another site. What actually happens?

3. Which href value opens the visitor's phone dialer?

Your task / مهمتك

Build a small links page: one absolute link to a site you like, one relative link to a page called about.html sitting next to yours, a mailto: link with an email address, and a tel: link with a phone number.

ابنِ صفحة روابط صغيرة: رابط مطلق إلى موقع يعجبك، ورابط نسبي إلى صفحة اسمها about.html تجلس بجانب صفحتك، ورابط mailto: ببريد إلكتروني، ورابط tel: برقم هاتف.

  • One absolute link (starts with https://) رابط مطلق واحد (يبدأ بـ https://)
  • One relative link to about.html رابط نسبي واحد إلى about.html
  • A mailto: link with a real-looking email address رابط mailto: ببريد إلكتروني شكله صحيح
  • A tel: link with a phone number رابط tel: برقم هاتف
How do you want to submit? / كيف تريد التسليم؟