Dark mode
HTML Complete Guide
Basic Structure
โครงสร้างพื้นฐานของเอกสาร HTML
html
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h1>Heading</h1>
<p>Paragraph</p>
</body>
</html>
Common Elements
Element | Example | Description |
---|---|---|
Heading | <h1>...</h1> | หัวข้อระดับ 1-6 |
Paragraph | <p>...</p> | ย่อหน้า |
Link | <a href="..."> | ลิงก์ |
Image | <img src="..."> | รูปภาพ |
List | <ul> <li>...</li> </ul> | รายการ |
Table | <table> <tr> <td>...</td> </tr> </table> | ตาราง |
Form | <form> <input> </form> | ฟอร์ม |
Semantic Elements
องค์ประกอบเชิงความหมายของเอกสาร HTML
Element | Purpose | Example | MDN Docs |
---|---|---|---|
<header> | ส่วนหัวของหน้าเว็บหรือส่วนของเนื้อหา | <header><h1>Title</h1></header> | |
<nav> | เมนูนำทาง | <nav><ul><li><a href="#">Link</a></li></ul></nav> | |
<main> | เนื้อหาหลักของหน้า | <main><article>...</article></main> | |
<article> | เนื้อหาที่เป็นเอกเทศ | <article><h2>Blog Post</h2><p>Content</p></article> | |
<aside> | เนื้อหารองที่เกี่ยวข้อง | <aside><h3>Related</h3><p>Info</p></aside> | |
<footer> | ส่วนท้ายของหน้าเว็บหรือส่วนของเนื้อหา | <footer><p>Copyright</p></footer> |
html
<header>
<nav>...</nav>
</header>
<main>
<article>...</article>
<aside>...</aside>
</main>
<footer>...</footer>
Forms
แบบฟอร์มสำหรับเก็บข้อมูลผู้ใช้
html
<form>
<label for="name">Name:</label>
<input type="text" id="name" name="name">
<label for="email">Email:</label>
<input type="email" id="email" name="email">
<button type="submit">Submit</button>
</form>
HTML5 APIs
เอพีไอของ HTML5 สำหรับการพัฒนาเว็บ
html
<!-- Geolocation -->
<button onclick="getLocation()">Get Location</button>
<!-- Local Storage -->
<script>
localStorage.setItem('key', 'value');
</script>
<!-- Canvas -->
<canvas id="myCanvas" width="200" height="100"></canvas>
Multimedia
มัลติมีเดียสำหรับเพิ่มความน่าสนใจ
html
<video width="320" height="240" controls>
<source src="movie.mp4" type="video/mp4">
</video>
<audio controls>
<source src="audio.mp3" type="audio/mpeg">
</audio>
Meta Tags & SEO
เมตาแท็กและการทำ SEO สำหรับการเพิ่มความสามารถในการค้นหา
html
<head>
<meta charset="UTF-8">
<meta name="description" content="Free Web tutorials">
<meta name="keywords" content="HTML, CSS, JavaScript">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
Accessibility
การเข้าถึงสำหรับผู้ใช้ที่มีความต้องการพิเศษ
html
<img src="image.jpg" alt="คำอธิบายรูปภาพ">
<button aria-label="ปิดเมนู">X</button>
<div role="navigation">...</div>
Character Entities
อักขระพิเศษสำหรับแสดงอักขระที่ไม่สามารถพิมพ์ได้
Entity | Result | Description |
---|---|---|
< | < | Less than |
> | > | Greater than |
& | & | Ampersand |
© | Copyright | |
| Non-breaking space |
Global Attributes
คุณสมบัติทั่วไปที่ใช้ได้กับแท็ก HTML ส่วนใหญ่ คุณสมบัติที่ใช้ได้กับแท็ก HTML ส่วนใหญ่
Attribute | Description |
---|---|
id | ระบุเอกลักษณ์เฉพาะ |
class | ระบุคลาสสำหรับ CSS |
style | ระบุสไตล์ inline |
title | ระบุข้อมูลเพิ่มเติม |
data-* | เก็บข้อมูลที่กำหนดเอง |
hidden | ซ่อน element |
Embedding Content
การฝังเนื้อหาจากแหล่งอื่น
html
<!-- Embed YouTube video -->
<iframe width="560" height="315" src="https://www.youtube.com/embed/..."></iframe>
<!-- Embed Google Map -->
<iframe src="https://www.google.com/maps/embed?..."></iframe>
Best Practices
แนวทางปฏิบัติที่ดีสำหรับการเขียน HTML
Practice | Description |
---|---|
Semantic HTML | ใช้ Semantic HTML |
Document Structure | ใช้โครงสร้างเอกสารที่ถูกต้อง |
Image Accessibility | ระบุ alt สำหรับรูปภาพ |
Code Formatting | ใช้ indentation ที่สม่ำเสมอ |
Naming Conventions | ตั้งชื่อ class/id ที่สื่อความหมาย |
Style Separation | หลีกเลี่ยง inline styles |
Case Consistency | ใช้ lowercase สำหรับชื่อแท็กและคุณสมบัติ |
Tag Closure | ปิดแท็กทั้งหมดให้ถูกต้อง |