|
1 | 1 | --- |
2 | 2 | extends: _layouts.documentation |
3 | 3 | title: "Configuration" |
4 | | -description: null |
| 4 | +description: "A guide to configuring and customizing your Tailwind installation." |
5 | 5 | --- |
6 | 6 |
|
7 | | -Tailwind's defining feature is its ability to be customized. We understand that no two projects are the same, so why should the CSS framework you use be? Tailwind provides developers with a helpful set of front-end conventions, while still leaving room for adjustments where appropriate. This is all done using the Tailwind config file. |
| 7 | +At the heart of every Tailwind project is a JavaScript configuration file that serves as the home for your project's design system. |
8 | 8 |
|
9 | | -## Introducing the Tailwind config |
| 9 | +It's where you define your color palette, font stacks, type scale, border sizes, breakpoints, opacity scale, you name it. Your config file is like an executable style guide for your project. |
10 | 10 |
|
11 | | -The Tailwind config file is where you customize Tailwind specifically for your project. It will include your color palette, fonts, text weights, spacing and sizing definitions, borders, shadows, and much more. Think of the Tailwind config as a living definition of your design system. |
| 11 | +We provide a sensible default configuration with a very generous set of values to get you started, but you own this file; you're encouraged to change it as much as you need to fit the goals of your design. |
12 | 12 |
|
13 | | -Tailwind is actually built on PostCSS and therefore is configured entirely in JavaScript. This can feel a little strange at first, especially if you're more familiar with setting variables in a preprocessor like Sass or Less. In practice though, defining your CSS configuration in a real programming language like JavaScript has a lot of benefits. You can create variables to share parts of your configuration. You have the full power of JavaScript to dynamically create or manipulate values. Eventually you may even be able to automatically generate custom documentation for your project from this config file. |
| 13 | +It's important to understand that unlike other CSS frameworks you might have used, **none of the settings in this file are coupled to each other**. Nothing bad will happen even if you completely delete all of the values for a given module. |
14 | 14 |
|
15 | | -## Creating your Tailwind config file |
| 15 | +## Generating your configuration file |
16 | 16 |
|
17 | | -We recommend creating a `tailwind.js` file in your project's root, but really it can go wherever you want. We've provided a CLI utility to do this easily: |
| 17 | +Generate a Tailwind config file for your project using the Tailwind CLI utility included when you install the `tailwindcss` npm package: |
18 | 18 |
|
19 | 19 | <div class="bg-smoke-lighter font-mono text-sm p-4"> |
20 | 20 | <div class="text-purple-dark">./node_modules/.bin/tailwind <span class="text-blue-dark">init</span> <span class="text-smoke-darker">[filename]</span></div> |
21 | 21 | </div> |
22 | 22 |
|
23 | | -Alternatively, you can simply copy the default config below. |
| 23 | +By default, `tailwind init` will generate a `tailwind.js` config file at the root of your project, but feel free to name this file differently or store it in a different location if you prefer. |
24 | 24 |
|
25 | | -Please see the [installation](/docs/installation#4-process-your-css-with-tailwind) page for more information on how to setup Tailwind in your build process. |
| 25 | +### Default configuration |
26 | 26 |
|
27 | | -## The default Tailwind config file |
28 | | - |
29 | | -As you can see below, the default config file is heavily documented. Read through it to get a better understanding of how each section can be customized for your project. |
| 27 | +Your generated configuration file contains all of Tailwind's default configuration values, ready for you to customize. |
30 | 28 |
|
31 | 29 | <pre class="h-128 overflow-y-scroll language-javascript"><code>{!! str_replace('// var defaultConfig', 'var defaultConfig', file_get_contents(dirname(dirname(__DIR__)).'/defaultConfig.stub.js')) !!}</code></pre> |
32 | 30 |
|
33 | | -## Options |
| 31 | +## Configuration Sections |
| 32 | + |
| 33 | +### Colors |
| 34 | + |
| 35 | +The `colors` property doesn't actually affect your generated CSS on its own, but it's the perfect place to centralize your color palette so you can refer to it in your own CSS using Tailwind's [`config()`](/docs/functions-and-directives#config) function. |
| 36 | + |
| 37 | +```js |
| 38 | +// ... |
| 39 | + |
| 40 | +var colors = { |
| 41 | + 'transparent': 'transparent', |
| 42 | + // ... |
| 43 | + 'pink-lightest': '#ffebef', |
| 44 | +} |
| 45 | + |
| 46 | +// ... |
| 47 | + |
| 48 | +module.exports = { |
| 49 | + // ... |
| 50 | + colors: colors, |
| 51 | + // ... |
| 52 | +} |
| 53 | +``` |
| 54 | + |
| 55 | +By default, the `colors` property simply references a `colors` variable defined earlier in the file. Using a separate variable for your color palette like this makes it easy to re-use those colors when defining the color palette for individual utilities, like background colors, text colors, or border colors. |
| 56 | + |
| 57 | +Learn more about defining colors in Tailwind in the [Colors](/docs/colors) documentation. |
| 58 | + |
| 59 | +### Screens |
| 60 | + |
| 61 | +The `screens` property is where you define your project's breakpoints, and will be used to generate responsive versions of Tailwind's utility classes. |
| 62 | + |
| 63 | +```js |
| 64 | +// ... |
| 65 | + |
| 66 | +module.exports = { |
| 67 | + // ... |
| 68 | + screens: { |
| 69 | + 'sm': '576px', |
| 70 | + 'md': '768px', |
| 71 | + 'lg': '992px', |
| 72 | + 'xl': '1200px', |
| 73 | + }, |
| 74 | + // ... |
| 75 | +} |
| 76 | +``` |
| 77 | + |
| 78 | +We provide a familiar set of breakpoints that you might recognize from [Bootstrap](http://getbootstrap.com/docs/4.0/layout/overview/#responsive-breakpoints) to get you started, but you're free to change these as needed to suit your project. |
| 79 | + |
| 80 | +Learn more about customizing screens in the [Responsive Design](/docs/responsive-design#customizing-screens) documentation. |
| 81 | + |
| 82 | +### Styles |
| 83 | + |
| 84 | +The next set of properties define all of the values you'd like to use for utilities that are dynamically generated. |
| 85 | + |
| 86 | +This includes things like: |
| 87 | + |
| 88 | +- Background colors |
| 89 | +- Border widths |
| 90 | +- Font families |
| 91 | +- Font weights |
| 92 | +- Text sizes |
| 93 | +- Padding, margin, and negative margin scales |
| 94 | +- Width and height scales |
| 95 | + |
| 96 | +...and many others. |
| 97 | + |
| 98 | +For example, here's the section used to customize which border radius utilities will be generated: |
| 99 | + |
| 100 | +```js |
| 101 | +// ... |
| 102 | + |
| 103 | +module.exports = { |
| 104 | + // ... |
| 105 | + |
| 106 | + /* |
| 107 | + |----------------------------------------------------------------------------- |
| 108 | + | Border radius https://tailwindcss.com/docs/border-radius |
| 109 | + |----------------------------------------------------------------------------- |
| 110 | + | |
| 111 | + | Here is where you define your border radius values. If a `default` radius |
| 112 | + | is provided, it will be made available as the non-suffixed `.rounded` |
| 113 | + | utility. |
| 114 | + | |
| 115 | + | If your scale includes a `0` value to reset already rounded corners, it's |
| 116 | + | a good idea to put it first so other values are able to override it. |
| 117 | + | |
| 118 | + | Class name: .rounded{-side?}{-size?} |
| 119 | + | |
| 120 | + */ |
| 121 | + |
| 122 | + borderRadius: { |
| 123 | + 'none': '0', |
| 124 | + 'sm': '.125rem', |
| 125 | + default: '.25rem', |
| 126 | + 'lg': '.5rem', |
| 127 | + 'full': '9999px', |
| 128 | + }, |
| 129 | + |
| 130 | + // ... |
| 131 | +} |
| 132 | +``` |
34 | 133 |
|
35 | | -In addition to defining your project's design system, the configuration file can also be used for setting a variety of global options. |
| 134 | +Read through the generated config file or visit the "customizing" documentation for each module to learn more. |
36 | 135 |
|
37 | | -These options are available under the top-level `options` key, located at the bottom of the configuration file by default. |
| 136 | +### Modules |
38 | 137 |
|
39 | | -### Prefix |
| 138 | +The `modules` property is where you control which modules are generated, and what state variants to generate for each module. |
| 139 | + |
| 140 | +```js |
| 141 | +// ... |
| 142 | + |
| 143 | +module.exports = { |
| 144 | + // ... |
| 145 | + |
| 146 | + modules: { |
| 147 | + appearance: ['responsive'], |
| 148 | + backgroundAttachment: ['responsive'], |
| 149 | + backgroundColors: ['responsive', 'hover'], |
| 150 | + backgroundPosition: ['responsive'], |
| 151 | + backgroundRepeat: ['responsive'], |
| 152 | + // ... |
| 153 | + }, |
| 154 | + |
| 155 | + // ... |
| 156 | +} |
| 157 | +``` |
| 158 | + |
| 159 | +Each property is a module name pointing to an array of state variants to generate for that module. |
| 160 | + |
| 161 | +The available state variants are: |
| 162 | + |
| 163 | +- `responsive`, for generating breakpoint-specific versions of those utilities |
| 164 | +- `hover`, for generating versions of those utilities that only take effect on hover |
| 165 | +- `focus`, for generating versions of those utilities that only take effect on focus |
| 166 | +- `parent-hover`, for generating versions of those utilities that only take effect when a marked parent element is hovered |
| 167 | + |
| 168 | +To include a module but not generate any state variants, use an empty array: |
| 169 | + |
| 170 | +```js |
| 171 | +// ... |
| 172 | + |
| 173 | +module.exports = { |
| 174 | + // ... |
| 175 | + |
| 176 | + modules: { |
| 177 | + |
| 178 | + // Include the `appearance` utilities, but not responsive, |
| 179 | + // focus, hover, etc. versions. |
| 180 | + appearance: [], |
| 181 | + // ... |
| 182 | + }, |
| 183 | + |
| 184 | + // ... |
| 185 | +} |
| 186 | +``` |
| 187 | + |
| 188 | +To completely disable a module, set it to `false`: |
| 189 | + |
| 190 | +```js |
| 191 | +// ... |
| 192 | + |
| 193 | +module.exports = { |
| 194 | + // ... |
| 195 | + |
| 196 | + modules: { |
| 197 | + |
| 198 | + // Don't include this module at all. |
| 199 | + appearance: false, |
| 200 | + // ... |
| 201 | + }, |
| 202 | + |
| 203 | + // ... |
| 204 | +} |
| 205 | +``` |
| 206 | + |
| 207 | +If a module is missing from your configuration file, the default configuration for that module will be used. |
| 208 | + |
| 209 | +### Options |
| 210 | + |
| 211 | +#### Prefix |
40 | 212 |
|
41 | 213 | The `prefix` option allows you to add a custom prefix to all of Tailwind's generated utility classes. |
42 | 214 |
|
@@ -100,7 +272,7 @@ If you'd like to prefix your own utilities as well, just add the prefix to the c |
100 | 272 | } |
101 | 273 | ``` |
102 | 274 |
|
103 | | -### Important |
| 275 | +#### Important |
104 | 276 |
|
105 | 277 | The `important` option lets you control whether or not Tailwind's utilities should be marked with `!important`. |
106 | 278 |
|
@@ -146,3 +318,23 @@ If you'd like to make your own utilities `!important`, just add `!important` to |
146 | 318 | } |
147 | 319 | } |
148 | 320 | ``` |
| 321 | + |
| 322 | +#### Separator |
| 323 | + |
| 324 | +The `separator` option lets you customize what character or string should be used to separate state variant prefixes (screen sizes, `hover`, `focus`, etc.) from utility names (`text-center`, `items-end`, etc.). |
| 325 | + |
| 326 | +We use a colon by default (`:`), but it can be useful to change this if you're using a templating language like [Pug](https://pugjs.org) that doesn't support special characters in classnames. |
| 327 | + |
| 328 | +```js |
| 329 | +// ... |
| 330 | + |
| 331 | +module.exports = { |
| 332 | + // ... |
| 333 | + |
| 334 | + options: { |
| 335 | + // ... |
| 336 | + separator: '_', |
| 337 | + }, |
| 338 | + |
| 339 | +} |
| 340 | +``` |
0 commit comments