geekskai Logogeekskai
ToolsBlogPricing
Sign in
Sign in
ToolsBlogSign in
Saturday, September 28, 2024|5.59Mins Read

How to Change CSS of PrimeVue: Pass Through, Tokens, and Unstyled Mode

Authors
  • avatar
    Name
    Geeks Kai
    Twitter
    @KaiGeeks
Discuss on Twitter • View on GitHub

Tags

primevuecssvuefrontendweb-developmentui-components

Previous Article

10+ Best Ways to Check if a Key Exists in JavaScript Objects

Next Article

Cloudflare Pages 搭建博客 | 2026 最新版
← Back to the blog
geekskai Logo
geekskai

Public tools for developers and creators, plus optional Geekskai Audio Toolkit plans. Built with care.

Popular Tools

SoundCloud DownloaderSoundCloud to MP3SoundCloud to WAVSoundCloud PlaylistSoundCloud Artwork
View All Tools

Resources

BlogAbout MePricingTagsProjectsPrivacy PolicyTerms of ServiceRefund Policy

Connect With Us

mailMail
githubGitHub
twitterTwitter
linkedinLinkedin
© 2026 geekskai • All rights reserved

How to Change CSS of PrimeVue

Quick Answer: The best way to change CSS in PrimeVue is usually to use pass through (pt) for component-specific styling, design tokens for theme-level styling, and unstyled mode when you want complete control. Plain CSS overrides still work, but they should not be the first tool you reach for.

Best for: Vue developers who want cleaner PrimeVue customization without brittle selector overrides

Cost: Free, built into PrimeVue

Key benefit: You can style PrimeVue components at the right layer instead of fighting generated classes

PrimeVue gives you several ways to change component styles, but they are not all equally maintainable. If you only know the old pattern of overriding .p-button with stronger selectors, you will eventually run into conflicts, upgrade friction, or hard-to-read CSS.

For modern PrimeVue projects, the usual order is:

  1. Use pt for component-part styling
  2. Use design tokens or CSS variables for theme changes
  3. Use unstyled mode when you want full control
  4. Use CSS overrides for targeted exceptions

When to Use Each Approach

GoalBest approach
Change one component's internal partspt
Apply consistent theme changes across componentsDesign tokens / CSS variables
Control every class yourselfUnstyled mode
Patch one edge case quicklyScoped or global CSS

Method 1: Basic Usage with pt

PrimeVue's pass through API lets you target internal DOM sections of a component directly. Each component documents the available section names, such as root, header, content, label, or icon.

This is the most useful PrimeVue-specific styling API because it lets you style component internals without guessing which selectors to override later.

Example with Panel:

<template>
  <div class="card">
    <Panel
      header="Header"
      toggleable
      :pt="{
        header: (options) => ({
          id: 'myPanelHeader',
          style: {
            userSelect: 'none'
          },
          class: [
            'border-primary',
            {
              'bg-primary text-primary-contrast': options.state.d_collapsed,
              'text-primary bg-primary-contrast': !options.state.d_collapsed
            }
          ]
        }),
        content: { class: 'border-primary text-lg text-primary-700' },
        title: 'text-xl',
        toggler: () => 'bg-primary text-primary-contrast hover:text-primary hover:bg-primary-contrast'
      }"
    >
      <p class="m-0">Custom Panel content</p>
    </Panel>
  </div>
</template>

Why pt works well

  • you can target exact internal sections
  • you can pass class, style, ARIA attributes, and custom attributes
  • values can be strings, objects, or functions
  • it is usually more stable than overriding internal .p-* selectors blindly

Method 2: Declarative pt: Syntax

If you prefer a more template-driven style, PrimeVue also supports declarative pass-through syntax. This is useful when the override is small and you want it close to the markup.

<Panel
  pt:root:class="border border-solid"
  pt:header:id="headerId"
  pt:header:data-test-id="testId"
  pt:header:class="bg-blue-500"
  :pt:header:onClick="onHeaderClick"
>
  <Button
    label="Click Me"
    :pt="{
      root: 'bg-blue-500 text-white',
      icon: 'text-white',
      label: 'text-white'
    }"
  />
</Panel>

Format:

<ComponentTag pt:[passthrough_key]:[attribute]="value" />

This syntax is easier to scan in simpler components, while the object form is usually better for more complex logic.

Method 3: Global PrimeVue Configuration

If you want consistent defaults across your app, configure pt globally when installing PrimeVue.

import PrimeVue from "primevue/config"
import { createApp } from "vue"

const app = createApp(App)

app.use(PrimeVue, {
  pt: {
    panel: {
      header: {
        class: "bg-primary text-primary-contrast",
      },
    },
    autocomplete: {
      input: {
        root: "w-64",
      },
    },
  },
})

app.mount("#app")

This is useful when:

  • you want the same default style in many places
  • you use the same utility classes repeatedly
  • you want a central source of truth for component styling

Method 4: Unstyled Mode

If you want PrimeVue for functionality but not for its default visual layer, use unstyled mode.

import PrimeVue from "primevue/config"
import { createApp } from "vue"

const app = createApp(App)

app.use(PrimeVue, {
  unstyled: true,
})

Unstyled mode is the best option when:

  • you already have a design system
  • you use Tailwind or another utility-first approach
  • you do not want to keep overriding styled mode defaults

You can also combine unstyled mode with a global pt preset.

Method 5: usePassThrough for Reusable Presets

If you want reusable and mergeable configuration, PrimeVue provides usePassThrough.

import { usePassThrough } from "primevue/passthrough"
import BasePreset from "./basepreset"

const CustomPreset = usePassThrough(
  BasePreset,
  {
    panel: {
      title: {
        class: ["leading-none font-light text-2xl"],
      },
    },
  },
  {
    mergeSections: true,
    mergeProps: false,
  }
)

Then register it:

app.use(PrimeVue, { unstyled: true, pt: CustomPreset })

This is useful in larger apps where you want one shared style preset rather than repeating pt objects everywhere.

Method 6: Design Tokens and Theme-Level Styling

If your goal is not just one component tweak but broader visual consistency, use PrimeVue design tokens or theme variables instead of repeating local overrides.

This is usually better than CSS overrides because:

  • it keeps the whole theme consistent
  • it avoids selector conflicts
  • it scales better than one-off patches

Use tokens when the change should affect multiple components, such as brand colors, spacing, or component states.

Can You Still Use Plain CSS?

Yes. Plain CSS still works, especially for quick fixes or rare cases that are not covered by pt or tokens.

Example:

.p-button {
  border-radius: 10px;
}

But plain CSS should usually be a secondary tool, not your first one.

Why:

  • it can become brittle across library updates
  • it often leads to higher-specificity selectors
  • it tempts people to overuse !important

When !important Makes Sense

Most PrimeVue guides used to recommend !important too quickly. That is usually not the best long-term choice.

Use !important only when:

  • you are fixing a stubborn third-party clash
  • you cannot target the right section with pt
  • you need a temporary patch during migration

If you find yourself adding !important to most PrimeVue rules, it is a sign you are using the wrong customization layer.

Recommended PrimeVue CSS Strategy

If you are unsure which method to choose, use this order:

  1. Need to style component internals? Use pt.
  2. Need a reusable style system? Use global pt config or usePassThrough.
  3. Need full ownership of styling? Use unstyled mode.
  4. Need app-wide visual consistency? Use tokens or theme variables.
  5. Need a quick patch? Use plain CSS carefully.

Conclusion

The cleanest way to change CSS in PrimeVue is not to fight its generated classes with stronger selectors. In most projects, pt is the best first choice because it targets component internals directly, works well with utility classes, and is easier to maintain.

For bigger styling systems, combine global pt config, design tokens, or unstyled mode. That gives you much more control than relying on scattered CSS overrides.

References

  • PrimeVue Official Documentation - Pass Through
  • PrimeVue Configuration
  • Vue Lifecycle API