text-transform kiểm soát viết hoa/chữ thường của văn bản không thay đổi nội dung DOM (chỉ ảnh hưởng hiển thị).
Giá trị
| Giá trị | Hiệu ứng | Ví dụ input → output |
|---|---|---|
none (mặc định) | Giữ nguyên | "Hello World" → "Hello World" |
capitalize | Viết hoa chữ cái đầu từ | "hello world" → "Hello World" |
uppercase | Viết hoa tất cả | "Hello World" → "HELLO WORLD" |
lowercase | Viết thường tất cả | "Hello World" → "hello world" |
full-width | Chuyển sang full-width (CJK) | Dùng cho typography CJK |
full-size-kana | Kana full-size (Japanese) | Typography Japanese |
Ví dụ
<html>
<head></head>
<body>
<p style="text-transform: capitalize;">This will be capitalized</p>
<p style="text-transform: uppercase;">This will be in uppercase</p>
<p style="text-transform: lowercase;">This will be in lowercase</p>
</body>
</html>
Lưu ý
capitalizechỉ viết hoa ký tự đầu của **từ** (tách bởi space, punctuation). Không xử lý đúng mọi ngôn ngữ (ví dụ "iPhone" → "Iphone").- Không ảnh hưởng đến
element.textContenthoặcvaluecủa input (chỉ hiển thị). - Kết hợp
::first-letter,::first-linecho hiệu ứng typography nâng cao.