🌐 HTML Cơ Bản script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js">

🔗 Bài 3: Links & Media

Học cách tạo liên kết và nhúng media vào trang web HTML

🔗 Links & Media là gì?

💡 Tại sao quan trọng?

Links và Media là linh hồn của web! Links tạo kết nối giữa các trang web với nhau, còn Media (hình ảnh, video, audio) làm cho trang web trở nên sinh động và thu hút người dùng.

🔗

Links (Liên kết)

Kết nối trang web với các trang khác hoặc các phần trong cùng trang

<a> - Thẻ anchor để tạo links
🖼️

Images (Hình ảnh)

Hiển thị hình ảnh từ file local hoặc online

<img> <figure> <figcaption>
🎬

Video & Audio

Nhúng video và audio vào trang web

<video> <audio> <source>
📦

Embedded Content

Nhúng nội dung từ các trang web khác

<iframe> <embed> <object>

🖼️ Thẻ <img> - Hình ảnh

📸 Thẻ img cơ bản

Thẻ <img> được sử dụng để nhúng hình ảnh vào trang web. Đây là thẻ tự đóng (self-closing tag).

Cú pháp cơ bản thẻ img
<!-- Cú pháp cơ bản -->
<img src="path/to/image.jpg" alt="Mô tả hình ảnh">

<!-- Với kích thước -->
<img src="logo.png" alt="Logo công ty" width="200" height="100">

<!-- Hình ảnh từ internet -->
<img src="https://via.placeholder.com/300x200" alt="Placeholder image">

<!-- Hình ảnh responsive -->
<img src="photo.jpg" alt="Ảnh đẹp" style="max-width: 100%; height: auto;">

⚙️ Thuộc tính quan trọng của thẻ <img>

📂

src (required)

Đường dẫn đến file hình ảnh

Local: src="images/photo.jpg"
Online: src="https://example.com/image.png"
📝

alt (required)

Mô tả ảnh cho accessibility và SEO

Good: alt="Logo Netflix màu đỏ"
Bad: alt="image1"
📏

width & height

Kích thước ảnh (pixels)

width="300" height="200"
Nên dùng CSS thay cho thuộc tính HTML
🚀

loading

Lazy loading cho performance

loading="lazy" - Load khi cần
loading="eager" - Load ngay (mặc định)
Ví dụ img với figure & figcaption
<!-- Hình ảnh với caption -->
<figure>
    <img src="https://via.placeholder.com/400x300" alt="Cảnh hoàng hôn trên biển">
    <figcaption>Hoàng hôn đẹp trên bãi biển Đà Nẵng</figcaption>
</figure>

<!-- Multiple images -->
<figure>
    <img src="photo1.jpg" alt="Ảnh 1" width="200">
    <img src="photo2.jpg" alt="Ảnh 2" width="200">
    <figcaption>Bộ sưu tập ảnh du lịch</figcaption>
</figure>

🎬 Video & Audio Tags

🎥 Thẻ <video>

Nhúng video HTML5
<!-- Video cơ bản -->
<video width="640" height="360" controls>
    <source src="movie.mp4" type="video/mp4">
    <source src="movie.webm" type="video/webm">
    Trình duyệt không hỗ trợ video HTML5.
</video>

<!-- Video với poster và các thuộc tính -->
<video 
    width="800" 
    height="450" 
    controls 
    poster="video-thumbnail.jpg"
    preload="metadata"
    autoplay 
    muted 
    loop
>
    <source src="demo.mp4" type="video/mp4">
    <source src="demo.webm" type="video/webm">
    <p>Trình duyệt của bạn không hỗ trợ video HTML5. 
       <a href="demo.mp4">Tải video</a>.</p>
</video>

🔊 Thẻ <audio>

Nhúng audio HTML5
<!-- Audio cơ bản -->
<audio controls>
    <source src="song.mp3" type="audio/mpeg">
    <source src="song.ogg" type="audio/ogg">
    Trình duyệt không hỗ trợ audio HTML5.
</audio>

<!-- Audio với các thuộc tính -->
<audio controls autoplay loop preload="auto">
    <source src="background-music.mp3" type="audio/mpeg">
    <source src="background-music.wav" type="audio/wav">
    <p>Trình duyệt của bạn không hỗ trợ audio. 
       <a href="background-music.mp3">Tải nhạc</a>.</p>
</audio>

⚙️ Thuộc tính Video & Audio

🎮

controls

Hiện nút play, pause, volume

controls - Boolean attribute
🔄

autoplay & loop

Tự động chạy và lặp lại

autoplay muted (cần muted cho autoplay)
loop - Lặp lại vô hạn

preload

Cách tải media

preload="none" - Không tải
preload="metadata" - Chỉ thông tin
preload="auto" - Tải toàn bộ
📸

poster (video only)

Ảnh thumbnail cho video

poster="thumbnail.jpg"

📦 Iframe & Embedded Content

🔗 Iframe là gì?

<iframe> cho phép nhúng một trang web khác vào trong trang web hiện tại. Thường dùng để nhúng YouTube, Google Maps, hay các widget khác.

Các ví dụ iframe phổ biến
<!-- YouTube video -->
<iframe 
    width="560" 
    height="315" 
    src="https://www.youtube.com/embed/dQw4w9WgXcQ" 
    title="YouTube video player" 
    frameborder="0" 
    allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" 
    allowfullscreen
></iframe>

<!-- Google Maps -->
<iframe 
    src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3919.4!2d106.6956!3d10.7769!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x0%3A0x0!2zMTDCsDQ2JzM3LjAiTiAxMDbCsDQxJzQ0LjAiRQ!5e0!3m2!1sen!2s!4v1234567890"
    width="600" 
    height="450" 
    style="border:0;" 
    allowfullscreen="" 
    loading="lazy"
></iframe>

<!-- Embed another website -->
<iframe 
    src="https://example.com" 
    width="800" 
    height="600"
    title="External website"
    sandbox="allow-scripts allow-same-origin"
></iframe>

⚠️ Lưu ý về Iframe:

  • Security: Sử dụng sandbox attribute để hạn chế quyền
  • Performance: Iframe có thể làm chậm trang web
  • SEO: Nội dung trong iframe không được index
  • Responsive: Cần CSS để iframe responsive

💪 Bài tập thực hành

🎯 Bài tập 1: Tạo Gallery ảnh với links

Tạo một gallery ảnh đơn giản với navigation:

Yêu cầu bài tập
<!-- 
🎯 YÊU CẦU:
1. Navigation menu với 4 links:
   - Trang chủ
   - Gallery  
   - Video
   - Liên hệ (mailto)

2. Gallery section với:
   - 4 hình ảnh placeholder (300x200)
   - Mỗi ảnh có figcaption
   - Click ảnh thì mở ảnh lớn (target="_blank")

3. Video section với:
   - Embed 1 YouTube video
   - 1 audio file với controls

4. Footer với:
   - Links đến social media (Facebook, Instagram)
   - Email và phone links

✅ SỬ DỤNG:
- a, img, figure, figcaption
- video, audio, iframe
- Placeholder images: https://via.placeholder.com/WIDTHxHEIGHT
- YouTube embed: https://www.youtube.com/embed/VIDEO_ID
-->

<!DOCTYPE html>
<html lang="vi">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>My Gallery</title>
</head>
<body>
    <!-- Viết code của bạn ở đây -->
    
    
    
    
</body>
</html>

🎯 Bài tập 2: Tạo trang Landing Page với Media

Landing Page với Media
<!-- 
🏢 YÊU CẦU LANDING PAGE:
1. Header:
   - Logo (image)
   - Navigation menu với smooth scroll links (#hero, #about, #contact)

2. Hero section:
   - Background image hoặc hero image
   - Tiêu đề + Call-to-action button

3. About section:
   - Video giới thiệu (YouTube embed hoặc local video)
   - Mô tả công ty

4. Services section:
   - 3 service cards với icons (images)
   - Mỗi card có link "Learn More"

5. Contact section:
   - Google Maps iframe
   - Contact links (email, phone, address)

6. Footer:
   - Social media links với icons
   - Copyright

💡 GỢI Ý:
- Dùng https://via.placeholder.com cho images
- Dùng Font Awesome icons: https://fontawesome.com
- YouTube test video: https://www.youtube.com/embed/dQw4w9WgXcQ
-->

<!-- Tạo landing page của bạn ở đây -->

💡 Tips làm bài tập:

  • 🔗 Links accessibility: Luôn có title và mô tả rõ ràng
  • 🖼️ Alt text tốt: Mô tả cụ thể, không dùng "image", "picture"
  • 📱 Responsive media: max-width: 100% cho images
  • Performance: Dùng loading="lazy" cho ảnh không quan trọng
  • 🎬 Video UX: Luôn có controls, cân nhắc autoplay
  • 🔒 External links: Dùng target="_blank" rel="noopener noreferrer"

📝 Tổng kết bài học

🎯 Những điều đã học được:

  • Links: Thẻ a với href, target, rel và các loại links
  • Images: Thẻ img với src, alt, width/height và figure
  • Video: Thẻ video với source, controls, poster
  • Audio: Thẻ audio với controls và preload
  • Iframe: Nhúng external content và security

🚀 Bước tiếp theo:

Trong Bài 4, chúng ta sẽ học về Forms - cách tạo biểu mẫu để thu thập thông tin từ người dùng với input, textarea, select và validation.

📋 Tiếp tục Bài 4: Forms →