createCssUtility() — tailwindcss Function Reference
Architecture documentation for the createCssUtility() function in utilities.ts from the tailwindcss codebase.
Entity Profile
Dependency Diagram
graph TD 1b775438_02d9_5178_6806_405c3c0b5328["createCssUtility()"] ffde8eb7_7def_91ee_918c_be4f250f76a2["utilities.ts"] 1b775438_02d9_5178_6806_405c3c0b5328 -->|defined in| ffde8eb7_7def_91ee_918c_be4f250f76a2 f7f9b3da_5977_1aa6_3bcb_bfc607af4e8f["parseCss()"] f7f9b3da_5977_1aa6_3bcb_bfc607af4e8f -->|calls| 1b775438_02d9_5178_6806_405c3c0b5328 329b56fb_df00_1c0c_1dbb_f9821a1760ab["isValidFunctionalUtilityName()"] 1b775438_02d9_5178_6806_405c3c0b5328 -->|calls| 329b56fb_df00_1c0c_1dbb_f9821a1760ab f359e052_6bcd_b19f_188c_5faf6e0d8021["value()"] 1b775438_02d9_5178_6806_405c3c0b5328 -->|calls| f359e052_6bcd_b19f_188c_5faf6e0d8021 4982d9ce_98d4_85d9_44af_7cc47b93c482["walk()"] 1b775438_02d9_5178_6806_405c3c0b5328 -->|calls| 4982d9ce_98d4_85d9_44af_7cc47b93c482 49a8c506_c50e_ed4b_5a0e_0393edae2b6f["parse()"] 1b775438_02d9_5178_6806_405c3c0b5328 -->|calls| 49a8c506_c50e_ed4b_5a0e_0393edae2b6f c58cbb33_f3cc_0b4f_844a_15bf66a1dc61["segment()"] 1b775438_02d9_5178_6806_405c3c0b5328 -->|calls| c58cbb33_f3cc_0b4f_844a_15bf66a1dc61 333e8e98_491a_3493_516c_169c024de8d8["entries()"] 1b775438_02d9_5178_6806_405c3c0b5328 -->|calls| 333e8e98_491a_3493_516c_169c024de8d8 e7db6358_7af5_e4b2_792d_749691a304cc["add()"] 1b775438_02d9_5178_6806_405c3c0b5328 -->|calls| e7db6358_7af5_e4b2_792d_749691a304cc a5656dd3_93ce_c98d_6cec_38309e85d053["functional()"] 1b775438_02d9_5178_6806_405c3c0b5328 -->|calls| a5656dd3_93ce_c98d_6cec_38309e85d053 dbd80fa4_4b36_fb8e_fb6e_f2aec789aa6b["cloneAstNode()"] 1b775438_02d9_5178_6806_405c3c0b5328 -->|calls| dbd80fa4_4b36_fb8e_fb6e_f2aec789aa6b b1961b55_1394_8973_5694_152fd6b3140a["resolveValueFunction()"] 1b775438_02d9_5178_6806_405c3c0b5328 -->|calls| b1961b55_1394_8973_5694_152fd6b3140a 523b2aa9_cd79_cdf0_dba9_b6b81fa6b149["suggest()"] 1b775438_02d9_5178_6806_405c3c0b5328 -->|calls| 523b2aa9_cd79_cdf0_dba9_b6b81fa6b149 2b202e81_c79a_bf7e_74f9_fe9a98bbea87["isPositiveInteger()"] 1b775438_02d9_5178_6806_405c3c0b5328 -->|calls| 2b202e81_c79a_bf7e_74f9_fe9a98bbea87 style 1b775438_02d9_5178_6806_405c3c0b5328 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/tailwindcss/src/utilities.ts lines 5941–6301
export function createCssUtility(node: AtRule) {
let name = node.params
// Functional utilities. E.g.: `tab-size-*`
if (isValidFunctionalUtilityName(name)) {
// API:
//
// - `--value('literal')` resolves a literal named value
// - `--value(number)` resolves a bare value of type number
// - `--value([number])` resolves an arbitrary value of type number
// - `--value(--color)` resolves a theme value in the `color` namespace
// - `--value(number, [number])` resolves a bare value of type number or an
// arbitrary value of type number in order.
//
// Rules:
//
// - If `--value(…)` does not resolve to a valid value, the declaration is
// removed.
// - If a `--value(ratio)` resolves, the `--modifier(…)` cannot be used.
// - If a candidate looks like `foo-2/3`, then the `--value(ratio)` should
// be used OR the `--value(…)` and `--modifier(…)` must be used. But not
// both.
// - All parts of the candidate must resolve, otherwise it's not a valid
// utility. E.g.:`
// ```
// @utility foo-* {
// test: --value(number)
// }
// ```
// If you then use `foo-1/2`, this is invalid, because the modifier is not used.
return (designSystem: DesignSystem) => {
let storage = {
'--value': {
usedSpacingInteger: false,
usedSpacingNumber: false,
themeKeys: new Set<`--${string}`>(),
literals: new Set<string>(),
},
'--modifier': {
usedSpacingInteger: false,
usedSpacingNumber: false,
themeKeys: new Set<`--${string}`>(),
literals: new Set<string>(),
},
}
// Pre-process the AST to make it easier to work with.
//
// - Normalize theme values used in `--value(…)` and `--modifier(…)`
// functions.
// - Track information for suggestions
walk(node.nodes, (child) => {
if (child.kind !== 'declaration') return
if (!child.value) return
if (!child.value.includes('--value(') && !child.value.includes('--modifier(')) return
let declarationValueAst = ValueParser.parse(child.value)
// Required manipulations:
//
// - `--value(--spacing)` -> `--value(--spacing-*)`
// - `--value(--spacing- *)` -> `--value(--spacing-*)`
// - `--value(--text- * --line-height)` -> `--value(--text-*--line-height)`
// - `--value(--text --line-height)` -> `--value(--text-*--line-height)`
// - `--value(--text-\\* --line-height)` -> `--value(--text-*--line-height)`
// - `--value([ *])` -> `--value([*])`
//
// Once Prettier / Biome handle these better (e.g.: not crashing without
// `\\*` or not inserting whitespace) then most of these can go away.
walk(declarationValueAst, (fn) => {
if (fn.kind !== 'function') return
// Track usage of `--spacing(…)`
if (
fn.value === '--spacing' &&
// Quick bail check if we already know that `--value` and `--modifier` are
// using the full `--spacing` theme scale.
!(storage['--modifier'].usedSpacingNumber && storage['--value'].usedSpacingNumber)
) {
walk(fn.nodes, (node) => {
Domain
Subdomains
Defined In
Calls
Called By
Source
Frequently Asked Questions
What does createCssUtility() do?
createCssUtility() is a function in the tailwindcss codebase, defined in packages/tailwindcss/src/utilities.ts.
Where is createCssUtility() defined?
createCssUtility() is defined in packages/tailwindcss/src/utilities.ts at line 5941.
What does createCssUtility() call?
createCssUtility() calls 15 function(s): add, cloneAstNode, entries, functional, isPositiveInteger, isValidFunctionalUtilityName, isValidStaticUtilityName, keysInNamespaces, and 7 more.
What calls createCssUtility()?
createCssUtility() is called by 1 function(s): parseCss.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free