Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> JavaScript

Cách đặt font-family cho văn bản trong HTML

Để đổi font-family trong HTML, dùng thuộc tính style với CSS font-family. HTML5 không hỗ trợ <font>, dùng CSS.

Lưu ý: style inline ghi đè style toàn cục.

Cách đặt font-family cho văn bản trong HTML

Ví dụ

<!DOCTYPE html>
<html>
  <head> <title>HTML Font Family</title> </head>
  <body>
    <h1>Our Products</h1>
    <p style="font-family:georgia,garamond,serif;">
      This is demo text
    </p>
  </body>
</html>

Mẹo: Luôn kết thúc font-family bằng generic family (serif, sans-serif, monospace, cursive, fantasy) làm fallback.