Skip to content

Typography

Typography คือ foundation ของ UI — ข้อความที่อ่านง่ายทำให้ users อยู่กับเว็บนานขึ้น

Key Principle: ใช้ scale ที่ consistent เช่น text-sm, text-base, text-lg ไม่ใช่ค่าสุ่ม


ClassSizeLine HeightUse Case
text-xs0.75rem1remCaptions
text-sm0.875rem1.25remBody small
text-base1rem1.5remBody default
text-lg1.125rem1.75remLead text
text-xl1.25rem1.75remHeading 4
text-2xl1.5rem2remHeading 3
text-3xl1.875rem2.25remHeading 2
text-4xl2.25rem2.5remHeading 1

ClassWeightUse Case
font-thin100Display only
font-light300Large headings
font-normal400Body text
font-medium500Buttons
font-semibold600Subheadings
font-bold700Headings
font-black900Hero titles

<p class="text-gray-600">Muted text</p>
<p class="text-blue-500">Primary text</p>
<p class="text-red-500/50">50% opacity</p>

<p class="leading-relaxed tracking-wide">
Easy to read paragraph with relaxed line height
</p>
ClassCSSUse Case
leading-tightline-height: 1.25Headings
leading-normalline-height: 1.5Body
leading-relaxedline-height: 1.625Long form content
tracking-tightletter-spacing: -0.025emLarge headings
tracking-wideletter-spacing: 0.025emUppercase labels

<p class="text-center underline">Centered and underlined</p>
<p class="text-right line-through">Right aligned strikethrough</p>

<!-- ตัดที่ 3 บรรทัด -->
<p class="line-clamp-3">Very long text that will be truncated...</p>

<!-- หัวข้อที่จัดระยะห่างอัตโนมัติ -->
<h1 class="text-balance">This is a long headline that will be balanced</h1>

Note: text-balance ช่วยให้หัวข้อยาวๆ ดูสวยงามขึ้นโดยจัดสมดุลความยาวแต่ละบรรทัด


<article>
<p class="text-sm font-medium text-blue-500 uppercase tracking-wide">
Category
</p>
<h1 class="mt-1 text-3xl font-bold text-gray-900 text-balance">
This is an Amazing Article Title That Spans Multiple Lines
</h1>
<p class="mt-2 text-gray-500">Published on <time>Jan 1, 2024</time></p>
</article>
<div class="p-4">
<h3 class="font-semibold text-lg">Card Title</h3>
<p class="mt-2 text-gray-600 text-sm line-clamp-2">
This is a description that might be very long but will be truncated to 2
lines maximum.
</p>
</div>

Do ✅Don’t ❌
ใช้ text-balance กับ headingsใช้กับ body text (slow)
ใช้ scale ที่ consistentผสมขนาดแบบ random
ใช้ tracking-tight กับหัวข้อใหญ่ใช้ tracking กับทุก text
กำหนด leading-* explicitพึ่ง default เสมอ

  1. Responsive Typography: ใช้ text-lg md:text-xl lg:text-2xl สำหรับ headings
  2. Contrast: text-gray-600 บน white bg = readable, text-gray-400 = too light
  3. Font Pairing: ผสม font ได้สูงสุด 2 ตัว (heading + body)
  4. Line Length: ควรมี max-width ~65-75 characters สำหรับ readability