Tailwind 는 다양한 기본 색상들을 제공한다.
하지만 프로젝트의 정해진 메인 색상이 있는 경우 등 커스텀 색상 팔레트를 만들어야 하는 경우, tailwind.config.js
를 수정하여 팔레트를 직접 구성할 수 있다.
tailwind.config.js
/** @type {import('tailwindcss').Config} */
module.exports = {
theme: {
colors: {
// 여기서 색상 팔레트를 구성하세요
}
}
}
tailwind.config.js
/** @type {import('tailwindcss').Config} */
module.exports = {
theme: {
colors: {
transparent: 'transparent',
current: 'currentColor',
'white': '#ffffff',
'purple': '#3f3cbb',
'midnight': '#121063',
'metal': '#565584',
'tahiti': '#3ab7bf',
'silver': '#ecebff',
'bubble-gum': '#ff77e9',
'bermuda': '#78dcca',
},
},
}
bg-tahiti-400
와 같은 클래스 이름을 생성한다.tailwind.config.js
/** @type {import('tailwindcss').Config} */
module.exports = {
theme: {
colors: {
transparent: 'transparent',
current: 'currentColor',
'white': '#ffffff',
'tahiti': {
100: '#cffafe',
200: '#a5f3fc',
300: '#67e8f9',
400: '#22d3ee',
500: '#06b6d4',
600: '#0891b2',
700: '#0e7490',
800: '#155e75',
900: '#164e63',
},
// ...
},
},
}
DEFAULT
키를 사용할 수 있다.bg-tahiti
는 #06b6d4 를 나타낸다./** @type {import('tailwindcss').Config} */
module.exports = {
theme: {
colors: {
// ...
'tahiti': {
light: '#67e8f9',
DEFAULT: '#06b6d4',
dark: '#0e7490',
},
// ...
},
},
}
<button class="bg-[#1da1f2] text-white ...">
<svg><!-- ... --></svg>
Share on Twitter
</button>
tailwindcss/colors
를 구성파일에서 가져와서 별칭을 지정할 수도 있다.const colors = require('tailwindcss/colors')
module.exports = {
theme: {
colors: {
transparent: 'transparent',
current: 'currentColor',
black: colors.black,
white: colors.white,
gray: colors.slate,
green: colors.emerald,
purple: colors.violet,
yellow: colors.amber,
pink: colors.fuchsia,
},
},
}
theme.extend.colors
에 추가하면 된다.module.exports = {
theme: {
extend: {
colors: {
brown: {
50: '#fdf8f6',
100: '#f2e8e5',
// ...
},
}
},
},
}
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
"./src/pages/**/*.{js,ts,jsx,tsx,mdx}",
"./src/components/**/*.{js,ts,jsx,tsx,mdx}",
"./src/app/**/*.{js,ts,jsx,tsx,mdx}",
],
theme: {
extend: {
colors: {
primary: {
50: "#eef8ff",
100: "#d8eeff",
200: "#b9e0ff",
300: "#89cfff",
400: "#52b4ff",
DEFAULT: "#2a91ff",
600: "#0d6efd",
700: "#0c5ae9",
800: "#1149bc",
900: "#144194",
950: "#11295a",
},
},
},
},
plugins: [],
};
nextcss/color-tools
패키지의 toneMap
함수는 입력받은 기본 색상에 대해 50 부터 950 까지 색조 코드 객체를 반환한다.const Object = toneMap(hex: String);
import { toneMap } from "@nextcss/color-tools";
const tones = toneMap("#eee");
console.log(tones);
// Output → {
// 50: '#fdfdfd',
// 100: '#fcfcfc',
// 150: '#fbfbfb',
// 200: '#f9f9f9',
// 250: '#f7f7f7',
// 300: '#f5f5f5',
// 350: '#f3f3f3',
// 400: '#f1f1f1',
// 450: '#f0f0f0',
// 500: '#eeeeee',
// 550: '#d6d6d6',
// 600: '#bebebe',
// 650: '#a7a7a7',
// 700: '#8f8f8f',
// 750: '#777777',
// 800: '#5f5f5f',
// 850: '#474747',
// 900: '#303030',
// 950: '#242424',
// }
npm i -D @nextcss/color-tools
generateColors
함수 생성 및 적용/** @type {import('tailwindcss').Config} */
import { toneMap } from "@nextcss/color-tools";
function generateColors(color) {
return {
DEFAULT: color,
...toneMap(color),
};
}
module.exports = {
content: [
"./src/pages/**/*.{js,ts,jsx,tsx,mdx}",
"./src/components/**/*.{js,ts,jsx,tsx,mdx}",
"./src/app/**/*.{js,ts,jsx,tsx,mdx}",
],
theme: {
extend: {
colors: {
primary: {
...generateColors("#2a91ff"),
},
},
},
},
plugins: [],
};
/** @type {import('tailwindcss').Config} */
import { toneMap } from "@nextcss/color-tools";
function generateColors(color) {
return {
DEFAULT: color,
...toneMap(color),
};
}
module.exports = {
content: [
"./src/pages/**/*.{js,ts,jsx,tsx,mdx}",
"./src/components/**/*.{js,ts,jsx,tsx,mdx}",
"./src/app/**/*.{js,ts,jsx,tsx,mdx}",
],
theme: {
extend: {
colors: {
primary: {
...generateColors("#007bff"),
},
danger: {
...generateColors("#dc3545"),
},
secondary: {
...generateColors("#6c757d"),
},
success: {
...generateColors("#28a745"),
},
warning: {
...generateColors("#ffc107"),
},
info: {
...generateColors("#17a2b8"),
},
light: {
...generateColors("#f8f9fa"),
},
dark: {
...generateColors("#343a40"),
},
},
},
},
plugins: [],
};
References
Customizing Colors - Tailwind CSS
GitHub - nextcss/color-tools: Useful color tools for your next JavaScript project.
tailwind css 똑똑하게 사용하기 - 이상원 기술 블로그