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> — اختصار "anchor" — وأهم سماته href، وهي التي تحمل عنوان الوجهة.<a href="https://example.com">Visit our site</a>
href is where the click takes them. Press "Try it live" and change the text or the address.
href هو الوجهة التي ينقله إليها. اضغط "Try it live" وغيّر النص أو العنوان.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.
https://، ويعمل من أي مكان لأنه يسمّي الموقع كله. أما الرابط النسبي فهو مجرد اسم ملف يجلس بجانب صفحتك، بلا https:// في أوله، ولا معنى له إلا داخل مشروعك أنت، لأن المتصفح يبحث عنه بجانب الصفحة التي هو فيها.<a href="https://example.com">Another site</a>
<a href="about.html">About us (a page next to this one)</a>
about.html really sits next to this page — that is what "relative" means.
about.html بجانب هذه الصفحة — وهذا هو معنى "نسبي".https:// وتتوقع أن يبقى الرابط مطلقًا. فـ href="example.com" ليس عنوانًا، بل مسار نسبي، فيبحث المتصفح عن صفحة اسمها example.com بجانب صفحتك، ولا يجدها، فينكسر الرابط في صمت.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.
target="_blank" ليفتح في تبويب جديد بدلًا من ذلك. استخدمها للروابط التي تُبعد الزائر عن شيء كان يفعله — مصدر تستشهد به، أو ملف يُنزّله — لا لتصفح موقعك العادي؛ لأن إجبار كل رابط على فتح تبويب جديد يملأ هاتف الزائر بتبويبات لم يطلبها، وتختفي الصفحة التي يتوقع زر "رجوع" أن يعيده إليها.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.
mailto: متبوعة بعنوان بريد تفتح تطبيق البريد عند الزائر وتملأ خانة المستلم بذلك العنوان تلقائيًا. و tel: متبوعة برقم تفتح تطبيق الاتصال ورقم الهاتف جاهز للطلب — ومعظم زوارك على الهاتف، فهذا الرابط وحده يوفر عليهم نسخ الرقم يدويًا.<a href="mailto:hello@example.com">Email us</a>
<a href="tel:+962791234567">Call us</a>
hello@example.com. Tap the second and it offers to dial +962791234567.
hello@example.com. وإذا لمست الثاني يعرض عليك الاتصال بالرقم +962791234567.| Pattern | What 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 / جرّب بنفسك
Check yourself / اختبر نفسك
1. Which of these is a relative link?
A relative link has no https:// in front — it names a file that sits beside your own page.
https:// — فهو يسمّي ملفًا يجلس بجانب صفحتك.
2.
You write href="example.com" hoping it links to another site. What actually happens?
href="example.com" وتوقعت أنها تربط بموقع آخر. ماذا يحدث فعليًا؟Without https:// the browser treats it as a relative path, not an address — it searches your own site for a file called example.com.
https:// يتعامل المتصفح معها كمسار نسبي لا عنوان، فيبحث في موقعك نفسه عن ملف اسمه example.com.3. Which href value opens the visitor's phone dialer?
The tel: prefix hands the number to the phone's dialer. mailto: is for email, and the other two prefixes do not exist.
tel: تسلّم الرقم لتطبيق الاتصال في الهاتف. أما mailto: فللبريد الإلكتروني، والبادئتان الأخريان غير موجودتين أصلًا.Score / النتيجة: 0 / 3
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:برقم هاتف