ใช้แท็ก <a> (anchor) เพื่อสร้างไฮเปอร์ลิงก์ แท็ก HTML <a> ใช้สำหรับสร้างลิงก์ไปยังเอกสารอื่น หรือตำแหน่งภายในเอกสารเดียวกัน
แอตทริบิวต์ของ <a>
| แอตทริบิวต์ | ค่า | คำอธิบาย |
|---|---|---|
| charset | character_encoding | กำหนด character encoding ของเอกสารลิงก์ |
| coords | rect: left,top,right,bottom circ: centerx,centery,radius poly: x1,y1,x2,y2... |
พิกัดสำหรับ image map (ใช้กับ shape) |
| download | filename | ดาวน์โหลดเป้าหมายเมื่อคลิกลิงก์ |
| href | URL | ระบุ URL หรือ anchor ปลายทาง (จำเป็น) |
| hreflang | language_code | รหัสภาษาของ URL ปลายทาง |
| media | media_query | ระบุ media ที่เอกสารลิงก์เหมาะสม |
| name | section name | ทำเครื่องหมายพื้นที่ที่ลิงก์กระโดดไป (HTML5 ใช้ id แทน) |
| rel | alternate, stylesheet, start, next, prev, contents, index, glossary, copyright, chapter, section, subsection, appendix, help, bookmark, nofollow, noopener, noreferrer... | อธิบายความสัมพันธ์ระหว่างเอกสารปัจจุบันและปลายทาง |
| rev | (Deprecated) | ความสัมพันธ์ย้อนกลับ (Deprecated) |
| shape | rect, circle, poly | รูปร่างสำหรับ image map (Deprecated) |
| target | _blank, _self, _parent, _top | ที่เปิดลิงก์: _blank=แท็บใหม่, _self=เดิม, _parent=พาเรนต์, _top=เต็มหน้าต่าง |
| type | mime_type | MIME type ของ URL ปลายทาง |
ตัวอย่าง
คุณสามารถลองรันโค้ดต่อไปนี้เพื่อสร้างลิงก์:
<!DOCTYPE html>
<html>
<head>
<title>HTML a Tag</title>
</head>
<body>
<p>นี่คือลิงก์ไปยัง <a href="https://qries.com">Qries.com</a></p>
</body>
</html>
แนวทางปฏิบัติที่ดี: ใช้ rel="noopener noreferrer" เมื่อใช้ target="_blank" เพื่อความปลอดภัย