ใช้แท็ก <iframe> เพื่อฝังวิดีโอ YouTube แอตทริบิวต์ src ใช้ลิงก์ embed กำหนด width และ height ให้เหมาะสม
วิธีหาลิงก์ Embed
- ไปที่วิดีโอ YouTube ที่ต้องการ
- กดปุ่ม Share > Embed
- คัดลอกลิงก์ในแอตทริบิวต์ src ของ iframe
ตัวอย่าง
<!DOCTYPE html> <html> <head> <title>HTML Video embed</title> </head> <body> <p>Learn Eclipse</p> <br /> <iframe width="560" height="315" src="https://www.youtube.com/embed/y881t8ilMyc" frameborder="0" allowfullscreen></iframe> </body> </html>
แอตทริบิวต์สำคัญ: allowfullscreen อนุญาตเต็มหน้าจอ frameborder="0" ไม่มีขอบ สามารถเพิ่ม title เพื่อ accessibility