Articles

PrimeVue Style Override

Aug 3 3 min read primevue
scssprime-vuetips-tricks

Intro

The PrimeVue UI component library provides a wide range of components with their own design. In some cases, we need to customize them to better suit our own needs. There are different ways we can override the default styles of PrimeVue, but we need to keep a few things in mind to reduce headaches later down the line 😅.

Examples

When working with CSS, we sometimes use the !important rule to override existing styles. Although it might get the job done in most cases, it can also create a lot of style conflicts as a project grows. Therefore, custom styles should be put into scoped styles, not in a global style. Funny enough, sometimes even scoped styles don't work 😝. But there are still other workarounds we know but might have forgotten about. I wanted to give a refresher.

Scoped

main.scss
<style scoped>
// Primarily works for single element components
.p-inputtext {
  background-color: #f0f4f8;
  border: 2px solid transparent;
  border-radius: 5px;
  padding: 10px 15px;
  font-size: 16px;
  color: #333;
}
</style>

In Vue, we can use a selector called :deep() to override child component styles when they have nested elements, such as the TabView component. If you want to change the tab header text color, just putting it into scoped styles will not work. We need to wrap the class with the :deep() selector to override the style.

Deep Selector

main.scss
<style scoped>
.p-tabview-header a {
  color: brown; // won't have any effect
}

:deep(.p-tabview-header a) {
  color: brown; // will change the color to brown
}
</style>

However, there are some components where even these two methods won't work. The reason behind it is that those components are appended to the body. We need to add a custom class and then apply the style so that it doesn't conflict with other components. An important note is to maintain specificity, or else it won't work.

Custom Class

main.scss
<style lang="scss">
.custom-modal {
  background-color: red; // won't have any effect
}
.custom-modal .p-dialog-content {
  background-color: red;
}
</style>

All the above methods can be used with any component library. Lastly, PrimeVue provides a pass-through method where we can easily pass in styles and PrimeFlex classes to customize the components based on our needs.

Explanation

https://primevue.org/passthrough/

All rights reserved.
Hasib • © 2026