0Pricing
Tailwind CSS Academy · 강의

플러그인으로 사용자 지정 유틸리티 추가

기본 Tailwind 배포판에 없는 text-shadow-* 또는 scrollbar-hide와 같은 새로운 유틸리티 클래스를 추가하는 플러그인을 작성합니다.

플러그인으로 사용자 지정 유틸리티 추가은(는) CoddyKit의 무료 Tailwind CSS Academy 강의입니다. 이것은 4개 중 2번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Tailwind CSS Academy 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Tailwind CSS Academy 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

When to Add a Custom Utility

Add a custom utility when you find yourself repeatedly writing the same raw CSS in @apply blocks or inline styles, when Tailwind lacks a utility for a valid CSS property, or when a browser-specific prefix combination needs a clean class name. Good custom utilities follow Tailwind's single-responsibility principle: one utility controls one CSS property or a tightly related group. Avoid creating utilities that set many unrelated properties — those belong in components.

Scrollbar Hide Utility

One of the most commonly requested custom utilities is .scrollbar-hide — it hides the scrollbar visually while keeping the element scrollable. This requires vendor-specific properties across browsers: scrollbar-width: none for Firefox and -webkit-scrollbar: display none for Chromium browsers. Packaging this in a plugin makes it available as a simple scrollbar-hide class anywhere in your markup.

const plugin = require('tailwindcss/plugin');

module.exports = {
  plugins: [
    plugin(function({ addUtilities }) {
      addUtilities({
        '.scrollbar-hide': {
          '-ms-overflow-style': 'none',
          'scrollbar-width': 'none',
          '&::-webkit-scrollbar': {
            display: 'none'
          }
        },
        '.scrollbar-default': {
          '-ms-overflow-style': 'auto',
          'scrollbar-width': 'auto',
          '&::-webkit-scrollbar': {
            display: 'block'
          }
        }
      });
    })
  ]
};

// Usage
// <div class='overflow-x-auto scrollbar-hide'>...

Text Shadow Utilities

CSS text-shadow is a commonly used property that Tailwind does not include by default. Building a plugin for it with theme integration lets consumers use it like any built-in utility and also supports customization via the config. Define default values in the theme and reference them in the plugin so the utility respects user overrides in tailwind.config.js.

const plugin = require('tailwindcss/plugin');

module.exports = {
  theme: {
    extend: {
      textShadow: {
        sm: '0 1px 2px var(--tw-shadow-color, rgba(0,0,0,0.2))',
        DEFAULT: '0 2px 4px var(--tw-shadow-color, rgba(0,0,0,0.3))',
        lg: '0 4px 8px var(--tw-shadow-color, rgba(0,0,0,0.4))'
      }
    }
  },
  plugins: [
    plugin(function({ matchUtilities, theme }) {
      matchUtilities(
        { 'text-shadow': (value) => ({ textShadow: value }) },
        { values: theme('textShadow') }
      );
    })
  ]
};
// Usage: text-shadow-sm, text-shadow, text-shadow-lg
// Or arbitrary: text-shadow-[0_4px_6px_rgba(0,0,0,0.5)]

Writing Direction Utilities

CSS logical properties for writing direction (margin-inline-start, padding-inline-end, inset-inline-start) enable right-to-left (RTL) layout support without duplicate CSS. Tailwind v3 added some logical properties, but you can write a plugin to fill any remaining gaps with a consistent naming convention matching Tailwind's style.

plugin(function({ addUtilities, theme }) {
  const spacing = theme('spacing');
  const utilities = {};

  Object.entries(spacing).forEach(([key, value]) => {
    // Logical margin utilities (RTL-aware)
    utilities['.ms-' + key] = { 'margin-inline-start': value };
    utilities['.me-' + key] = { 'margin-inline-end': value };
    utilities['.ps-' + key] = { 'padding-inline-start': value };
    utilities['.pe-' + key] = { 'padding-inline-end': value };
    // Logical inset
    utilities['.start-' + key] = { 'inset-inline-start': value };
    utilities['.end-' + key] = { 'inset-inline-end': value };
  });

  addUtilities(utilities);
})

Gradient Text Utility

Gradient text requires a combination of three CSS properties: background-clip: text, -webkit-background-clip: text, and color: transparent. Since the actual gradient colors come from bg-gradient-to-* and from-*/to-* utilities, the plugin only needs to provide the clipping foundation. This is a classic multi-property utility that benefits from being a single, memorable class name.

plugin(function({ addUtilities }) {
  addUtilities({
    '.text-gradient': {
      '-webkit-background-clip': 'text',
      'background-clip': 'text',
      '-webkit-text-fill-color': 'transparent',
      'color': 'transparent'
    }
  });
})

// Usage: combine with standard bg-gradient utilities
<h1 class='
  text-gradient
  bg-gradient-to-r
  from-purple-500
  to-blue-500
  text-4xl font-bold
'>
  Beautiful gradient text
</h1>

Grid Auto-Fill Utility

CSS Grid's auto-fill and auto-fit repeat patterns for responsive grids are common but require verbose syntax. A plugin that generates parameterizable grid utilities for the most common column minimum widths makes responsive grids dramatically simpler to write. Use matchUtilities so users can specify arbitrary minimum column widths.

plugin(function({ matchUtilities }) {
  matchUtilities(
    {
      'grid-fill': (value) => ({
        gridTemplateColumns: 'repeat(auto-fill, minmax(' + value + ', 1fr))'
      }),
      'grid-fit': (value) => ({
        gridTemplateColumns: 'repeat(auto-fit, minmax(' + value + ', 1fr))'
      })
    },
    { values: { sm: '10rem', md: '15rem', lg: '20rem', xl: '25rem' } }
  );
})

// Usage:
// <div class='grid grid-fill-md gap-4'>
//   Items auto-arrange into columns of min 15rem
// </div>

CSS Grid Area Utilities

Named grid areas via grid-template-areas require verbose CSS that is hard to express in Tailwind's utility model. A plugin can add utilities for common named-area layouts — like a classic page layout with header, sidebar, main, and footer areas — as single utility classes. These pair well with col-span-* and row-span-* for more complex layouts.

plugin(function({ addUtilities }) {
  addUtilities({
    '.grid-area-page': {
      gridTemplateAreas:
        '"header header"' +
        '"sidebar main"' +
        '"footer footer"',
      gridTemplateColumns: '250px 1fr',
      gridTemplateRows: 'auto 1fr auto'
    },
    '.area-header': { gridArea: 'header' },
    '.area-sidebar': { gridArea: 'sidebar' },
    '.area-main': { gridArea: 'main' },
    '.area-footer': { gridArea: 'footer' }
  });
})

// Usage:
// <div class='grid grid-area-page min-h-screen'>
//   <header class='area-header'>...</header>
//   <aside class='area-sidebar'>...</aside>
//   <main class='area-main'>...</main>
//   <footer class='area-footer'>...</footer>
// </div>

Animation Utilities Beyond Built-Ins

Tailwind provides animate-spin, animate-pulse, animate-bounce, and animate-ping. For richer animations — like a wiggle, a heartbeat, or a float effect — add custom keyframes to the theme and reference them in a plugin. The plugin ensures the animation class names follow Tailwind's animate-* convention, keeping the system coherent.

// tailwind.config.js
module.exports = {
  theme: {
    extend: {
      keyframes: {
        wiggle: {
          '0%, 100%': { transform: 'rotate(-3deg)' },
          '50%': { transform: 'rotate(3deg)' }
        },
        heartbeat: {
          '0%, 100%': { transform: 'scale(1)' },
          '14%': { transform: 'scale(1.3)' },
          '28%': { transform: 'scale(1)' },
          '42%': { transform: 'scale(1.3)' },
          '70%': { transform: 'scale(1)' }
        }
      },
      animation: {
        wiggle: 'wiggle 1s ease-in-out infinite',
        heartbeat: 'heartbeat 1.5s ease-in-out infinite'
      }
    }
  }
};

// Usage: class='animate-wiggle' or class='animate-heartbeat'

Testing Your Custom Utilities

Verify your plugin utilities appear in the generated CSS by creating a test HTML file that uses the class names and running the Tailwind CLI. The JIT engine must find the class in a file matching your content globs. Also test that responsive and state variants work if you intend for them to — some pseudo-element utilities like ::-webkit-scrollbar do not support responsive prefixes meaningfully.

<!-- test.html -->
<div class='scrollbar-hide overflow-y-auto h-48'>
  <p class='text-shadow-lg text-2xl font-bold text-gray-900'>Test</p>
  <div class='grid grid-fill-md gap-4'>
    <div class='bg-gray-100 p-4 rounded'>Card 1</div>
    <div class='bg-gray-100 p-4 rounded'>Card 2</div>
  </div>
</div>

<!-- Run: npx tailwindcss -i src/input.css -o test-output.css --content test.html -->
<!-- Inspect test-output.css for your custom utility classes -->

Documenting Custom Utilities

Document custom utilities for your team so they know what exists and how to use it. Create a PLUGINS.md file or a Storybook page listing each custom utility with its class names, accepted values, and usage examples. Without documentation, team members often write the same CSS twice — once as a utility and again as inline styles — because they did not know the plugin existed.

/*
  Custom Utilities Documentation
  ================================

  .scrollbar-hide
    Hides the scrollbar while preserving scroll functionality.
    Use with: overflow-y-auto, overflow-x-auto
    Example: <div class='overflow-y-auto h-64 scrollbar-hide'>

  .text-shadow-{size}
    Adds a text shadow. Sizes: sm, DEFAULT, lg.
    Example: <h1 class='text-shadow-lg text-3xl font-bold'>
    Arbitrary: <h1 class='text-shadow-[0_4px_8px_rgba(0,0,0,0.5)]'>

  .text-gradient
    Enables gradient text via background-clip: text.
    Must combine with bg-gradient-to-* and from-*/to-* utilities.
    Example: <span class='text-gradient bg-gradient-to-r from-purple-500 to-pink-500'>

  .grid-fill-{size}
    Auto-fill grid with minimum column width. Sizes: sm, md, lg, xl.
    Example: <div class='grid grid-fill-md gap-4'>
*/

Performance Impact of Custom Utilities

Custom utilities add to your generated CSS size. If a utility generates many permutations (like spacing utilities across 30+ scale steps), the output can grow significantly. Be selective about which utilities you generate programmatically. Use matchUtilities with a small set of theme values and rely on arbitrary values for one-off cases, rather than pre-generating every possible combination. This keeps your CSS bundle lean while maintaining flexibility.

// Avoid: generates 30+ utilities upfront
plugin(function({ addUtilities, theme }) {
  const spacing = theme('spacing'); // 30+ entries
  const utils = {};
  Object.entries(spacing).forEach(([k, v]) => {
    utils['.clip-' + k] = { clipPath: 'inset(' + v + ')' };
  });
  addUtilities(utils); // large CSS output
});

// Better: use matchUtilities with limited defaults
plugin(function({ matchUtilities, theme }) {
  matchUtilities(
    { 'clip': (v) => ({ clipPath: 'inset(' + v + ')' }) },
    { values: { none: '0', sm: '0.5rem', md: '1rem' } }
    // Users can still do clip-[2rem] for custom values
  );
});

Quick Check

Test your understanding of Tailwind CSS Mastery concepts from this lesson.

Lesson Recap

In this lesson you learned: addUtilities adds static custom utility classes, matchUtilities adds utilities with arbitrary value support, and custom utilities should be documented and scoped to real, repeated needs. Next up we learn how to add custom state variants via plugins to target custom selectors and data attributes.

자주 묻는 질문

“플러그인으로 사용자 지정 유틸리티 추가” 강의는 무료인가요?

네 — “플러그인으로 사용자 지정 유틸리티 추가” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Tailwind CSS Academy 강의 전체를 잠금 해제할 수 있습니다. Tailwind CSS Academy 강의에는 총 4개의 강의가 포함되어 있습니다.

“플러그인으로 사용자 지정 유틸리티 추가”에서 뭘 배우나요?

기본 Tailwind 배포판에 없는 text-shadow-* 또는 scrollbar-hide와 같은 새로운 유틸리티 클래스를 추가하는 플러그인을 작성합니다. 브라우저에서 직접 실행하는 실습 코드로 Tailwind CSS Academy을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Tailwind CSS Academy을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 Tailwind CSS Academy은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 2번째 강의입니다.

“플러그인으로 사용자 지정 유틸리티 추가” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 Tailwind CSS Academy 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 Tailwind CSS Academy 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. Tailwind 플러그인 API
  2. 플러그인으로 사용자 지정 유틸리티 추가
  3. 플러그인으로 사용자 지정 변형 추가
  4. 플러그인 게시 및 재사용
← Tailwind CSS Academy(으)로 돌아가기