Tailwind CSS 타이포그래피 (Typography)
Flowbite Typography는 공식 Tailwind CSS Typography 플러그인에서 포크된 플러그인이에요. 래퍼 요소에 format 클래스를 추가하면 그 안의 제목, 문단, 이미지, 목록 같은 모든 인라인 자식 요소에 글꼴 크기, 굵기, 색상, 간격이 자동으로 적용됩니다. UI/UX 가독성과 접근성 기준에 맞춰 스타일이 정리된 상태로 제공돼요.
출처: 문서
본문
시작하기 (Getting started)
프로젝트에 Node.js와 Tailwind CSS가 이미 설치되어 있어야 해요. 먼저 NPM으로 Flowbite Typography 플러그인을 설치합니다.
npm i -D flowbite-typography
그리고 메인 Tailwind CSS 파일에 플러그인을 import 합니다.
@plugin "flowbite-typography";
tailwind.config.js 파일에서도 동일하게 설정할 수 있어요 (Tailwind CSS v4를 쓰면 config 파일을 메인 CSS에서 import 하면 됩니다).
// import the tailwind.config.js file in your main CSS file if using Tailwind CSS v4
module.exports = {
theme: {
// ...
},
plugins: [
require('flowbite-typography'),
// ...
],
}
이제 Flowbite Typography 플러그인의 새로운 포맷팅 클래스를 자유롭게 사용할 수 있어요.
기본 사용법 (Basic usage)
플러그인이 설치되면 래퍼 요소에 format 클래스를 추가하고, 제목, 문단, 이미지, 목록, 캡션, 링크, 테이블 같은 인라인 요소를 사용해요. 모든 요소는 권장 가독성 및 접근성 기준에 따라 간격, 글꼴 크기, 굵기, 색상이 자동으로 스타일링됩니다.
<article class="format lg:format-lg">
<h1>Prototyping from A to Z: best practices for successful prototypes</h1>
<p class="lead">Flowbite is an open-source library of UI components built with the utility-first classes from Tailwind CSS. It also includes interactive elements such as dropdowns, modals, datepickers.</p>
<p>Before going digital, you might benefit from scribbling down some ideas in a sketchbook. This way, you can think things through before committing to an actual design project.</p>
<p>But then I found a <a href="#">component library based on Tailwind CSS called Flowbite</a>. It comes with the most commonly used UI components, such as buttons, navigation bars, cards, form elements, and more which are conveniently built with the utility classes from Tailwind CSS.</p>
...
<h2>When does design come in handy?</h2>
<p>While it might seem like extra work at a first glance, here are some key moments in which prototyping will come in handy:</p>
<ol>
<li><strong>Usability testing</strong>. Does your user know how to exit out of screens? Can they follow your intended user journey and buy something from the site you’ve designed? By running a usability test, you’ll be able to see how users will interact with your design once it’s live;</li>
<li><strong>Involving stakeholders</strong>. Need to check if your GDPR consent boxes are displaying properly? Pass your prototype to your data protection team and they can test it for real;</li>
<li><strong>Impressing a client</strong>. Prototypes can help explain or even sell your idea by providing your client with a hands-on experience;</li>
<li><strong>Communicating your vision</strong>. By using an interactive medium to preview and test design elements, designers and developers can understand each other — and the project — better.</li>
</ol>
</article>
lg:format-lg 클래스를 추가하면 큰 화면(뷰포트)에서 글꼴 크기와 간격이 증가합니다.
링크 색상 (Link colors)
format-{color} 클래스를 설정하면 기본 파란색 링크 색상을 원하는 색으로 바꿀 수 있어요. 아래는 format-red를 적용한 예시입니다.
<article class="format lg:format-lg format-red">
<h1>Prototyping from A to Z: best practices for successful prototypes</h1>
<p class="lead">Flowbite is an open-source library of UI components built with the utility-first classes from Tailwind CSS. It also includes interactive elements such as dropdowns, modals, datepickers.</p>
<p>Before going digital, you might benefit from scribbling down some ideas in a sketchbook. This way, you can think things through before committing to an actual design project.</p>
<p>But then I found a <a href="#">component library based on Tailwind CSS called Flowbite</a>. It comes with the most commonly used UI components, such as buttons, navigation bars, cards, form elements, and more which are conveniently built with the utility classes from Tailwind CSS.</p>
</article>
다크 모드 (Dark mode)
article 래퍼 요소에 dark:format-invert 클래스를 적용해 다크 모드에서 타이포그래피가 반전되도록 할 수 있어요.
<article class="format lg:format-lg dark:format-invert">
<h1>The content inside this article will invert when switching to dark mode</h1>
<p class="lead">Flowbite is an open-source library of UI components built with the utility-first classes from Tailwind CSS. It also includes interactive elements such as dropdowns, modals, datepickers.</p>
<p>Before going digital, you might benefit from scribbling down some ideas in a sketchbook. This way, you can think things through before committing to an actual design project.</p>
<p>But then I found a <a href="#">component library based on Tailwind CSS called Flowbite</a>. It comes with the most commonly used UI components, such as buttons, navigation bars, cards, form elements, and more which are conveniently built with the utility classes from Tailwind CSS.</p>
...
<h2>When does design come in handy?</h2>
<p>While it might seem like extra work at a first glance, here are some key moments in which prototyping will come in handy:</p>
<ol>
<li><strong>Usability testing</strong>. Does your user know how to exit out of screens? Can they follow your intended user journey and buy something from the site you’ve designed? By running a usability test, you’ll be able to see how users will interact with your design once it’s live;</li>
<li><strong>Involving stakeholders</strong>. Need to check if your GDPR consent boxes are displaying properly? Pass your prototype to your data protection team and they can test it for real;</li>
<li><strong>Impressing a client</strong>. Prototypes can help explain or even sell your idea by providing your client with a hands-on experience;</li>
<li><strong>Communicating your vision</strong>. By using an interactive medium to preview and test design elements, designers and developers can understand each other — and the project — better.</li>
</ol>
</article>
최대 너비 (Max width)
기본 최대 너비를 format 클래스 옆에 커스텀 max-w-{size} 클래스를 지정해 재정의할 수 있어요. max-w-none은 최대 너비를 없애는 예시입니다.
<article class="max-w-none format lg:format-lg format-red">
<h1>Prototyping from A to Z: best practices for successful prototypes</h1>
<p class="lead">Flowbite is an open-source library of UI components built with the utility-first classes from Tailwind CSS. It also includes interactive elements such as dropdowns, modals, datepickers.</p>
<p>Before going digital, you might benefit from scribbling down some ideas in a sketchbook. This way, you can think things through before committing to an actual design project.</p>
<p>But then I found a <a href="#">component library based on Tailwind CSS called Flowbite</a>. It comes with the most commonly used UI components, such as buttons, navigation bars, cards, form elements, and more which are conveniently built with the utility classes from Tailwind CSS.</p>
</article>
포맷 비활성화 (Disable format)
타이포그래피 콘텐츠 내부의 특정 부분에 스타일을 적용하고 싶지 않다면 not-format 클래스를 사용해요.
<article class="format lg:format-lg dark:format-invert">
<h1>The content inside this article will invert when switching to dark mode</h1>
<p class="lead">Flowbite is an open-source library of UI components built with the utility-first classes from Tailwind CSS. It also includes interactive elements such as dropdowns, modals, datepickers.</p>
<p>Before going digital, you might benefit from scribbling down some ideas in a sketchbook. This way, you can think things through before committing to an actual design project.</p>
<p>But then I found a <a href="#">component library based on Tailwind CSS called Flowbite</a>. It comes with the most commonly used UI components, such as buttons, navigation bars, cards, form elements, and more which are conveniently built with the utility classes from Tailwind CSS.</p>
...
<!-- content that won't have styles applied -->
<div class="not-format">
<h2>When does design come in handy?</h2>
<p>While it might seem like extra work at a first glance, here are some key moments in which prototyping will come in handy:</p>
<ol>
<li><strong>Usability testing</strong>. Does your user know how to exit out of screens? Can they follow your intended user journey and buy something from the site you’ve designed? By running a usability test, you’ll be able to see how users will interact with your design once it’s live;</li>
<li><strong>Involving stakeholders</strong>. Need to check if your GDPR consent boxes are displaying properly? Pass your prototype to your data protection team and they can test it for real;</li>
<li><strong>Impressing a client</strong>. Prototypes can help explain or even sell your idea by providing your client with a hands-on experience;</li>
<li><strong>Communicating your vision</strong>. By using an interactive medium to preview and test design elements, designers and developers can understand each other — and the project — better.</li>
</ol>
</div>
</article>
옵션 (Options)
Tailwind 설정 파일에서 플러그인 옵션을 확장해 색상, 클래스명 등을 직접 지정할 수 있어요.
커스텀 색상 (Custom colors)
tailwind.config.js 파일에서 typography 플러그인을 확장해 나만의 색을 설정해요.
module.exports = {
theme: {
extend: {
typography: ({ theme }) => ({
orange: {
css: {
'--tw-format-body': theme('colors.orange[500]'),
'--tw-format-headings': theme('colors.orange[900]'),
'--tw-format-lead': theme('colors.orange[500]'),
'--tw-format-links': theme('colors.orange[600]'),
'--tw-format-bold': theme('colors.orange[900]'),
'--tw-format-counters': theme('colors.orange[500]'),
'--tw-format-bullets': theme('colors.orange[500]'),
'--tw-format-hr': theme('colors.orange[200]'),
'--tw-format-quotes': theme('colors.orange[900]'),
'--tw-format-quote-borders': theme('colors.orange[300]'),
'--tw-format-captions': theme('colors.orange[700]'),
'--tw-format-code': theme('colors.orange[900]'),
'--tw-format-code-bg': theme('colors.orange[50]'),
'--tw-format-pre-code': theme('colors.orange[100]'),
'--tw-format-pre-bg': theme('colors.orange[900]'),
'--tw-format-th-borders': theme('colors.orange[300]'),
'--tw-format-td-borders': theme('colors.orange[200]'),
'--tw-format-th-bg': theme('colors.orange[50]'),
'--tw-format-invert-body': theme('colors.orange[200]'),
'--tw-format-invert-headings': theme('colors.white'),
'--tw-format-invert-lead': theme('colors.orange[300]'),
'--tw-format-invert-links': theme('colors.white'),
'--tw-format-invert-bold': theme('colors.white'),
'--tw-format-invert-counters': theme('colors.orange[400]'),
'--tw-format-invert-bullets': theme('colors.orange[600]'),
'--tw-format-invert-hr': theme('colors.orange[700]'),
'--tw-format-invert-quotes': theme('colors.pink[100]'),
'--tw-format-invert-quote-borders': theme('colors.orange[700]'),
'--tw-format-invert-captions': theme('colors.orange[400]'),
'--tw-format-invert-code': theme('colors.white'),
'--tw-format-invert-pre-code': theme('colors.orange[300]'),
'--tw-format-invert-pre-bg': 'rgb(0 0 0 / 50%)',
'--tw-format-invert-th-borders': theme('colors.orange[600]'),
'--tw-format-invert-td-borders': theme('colors.orange[700]'),
'--tw-format-invert-th-bg': theme('colors.orange[700]'),
},
},
}),
},
},
plugins: [
require('flowbite-typography'),
// ...
],
}
이제 format-red 클래스를 사용해 이 스타일을 적용할 수 있어요.
래퍼 클래스 (Wrapper class)
플러그인 호출에 옵션 객체를 넘겨 기본 format 클래스를 원하는 이름으로 바꿀 수 있어요.
module.exports = {
theme: {
// ...
},
plugins: [
require('flowbite-typography')({
className: 'custom-class',
}),
]
...
}
커스텀 CSS (Custom CSS)
Tailwind 설정 파일의 css 키-값 쌍을 확장해 기본 CSS를 커스터마이즈할 수도 있어요.
module.exports = {
theme: {
extend: {
typography: {
DEFAULT: {
css: {
color: '#666',
a: {
color: '#3182ce',
'&:hover': {
color: '#2c5282',
},
},
},
},
},
},
},
plugins: [
require('flowbite-typography'),
// ...
],
}
블로그 템플릿 (Blog templates)
Flowbite Blocks에서 Typography 플러그인을 사용하는 블로그 템플릿 레이아웃도 확인해 볼 수 있어요.