5 ways to change component colors and styles using Vuetify
Tags: vue, vuetify, javascript, css
Published: 2020-02-16 22:14:14

---
title: 5 ways to change component colors and styles using Vuetify
published: true
description: Different ways to change styling available when using Vuetify, and which one is best.
tags: Vuejs, Vuetify, JavaScript, CSS
---

When I started using using Vue as my front-end framework, I tried to use it with Bootstrap of just plain old CSS. However soon, I realized that things were not as fast as I wished. Then I discovered Vuetify as the Material Design CSS/Components framework that can be used along Vue.js to supercharge your development tools. So what I wanted to quickly address in this article is how can you style your components using Vue. The most common way that come to mind is using plain old CSS. However Vuetify has slightly different approach. So let’s digg in and see the different way you can style components, and which way is the productive way.

#1- Using component props
Many components has props that allow quick style change. For instance the `v-card` `v-btn` `v-chip` and many components have the `color` property which you can set like this:

`<v-card color="orange">...</v-card>`

Other props that allow for quick style change would be something like:

`<v-container px-2>...</v-container>`

in this case we are changing the paddings on this component by using this prop.

{% gist https://gist.github.com/mtermoul/056f041e62449f7dd3a9fae9d0b486a0 %}

![HomePage preview](https://miro.medium.com/max/2368/1*eY0y4WW9WfGUiJvtx9z3DQ.png)

As you can see above, you can simply control the color, padding, alignment of the card component by just using few props without the need to use CSS at all

#2- Using the class property

Every Vuetify component comes with a very handy property called class . And you can use that class to change many styling props like the color, font, padding, alignment… However you need to know which CSS classes to use in order to make the changes. Vuetify have already defined many CSS classes to control many style. For instance to change the font color to red you simply say `class="red--text"` or to change the typography or the fonts you can use one of the predefined font styles like this `class="subtitle-2"` . You can also change the background color of a component using the class prop like this `class="grey"` let’s change the the example above to use the class property.

{% gist https://gist.github.com/mtermoul/5a476d7373e6f01e14840d38911d4901 %}

As you can see in the code above, we changed the color of text and background using class prop. We also change the font in the same way. I also want to mention that Vuetify have created the CSS classes for all these styles and made them available for us to use without the need to touch the actual CSS.

![HomePage preview](https://cdn-images-1.medium.com/max/1600/1*AraNUUmcO4wIljHjI1tEhw.png)

#3- Using in-component style and CSS
The third option that Vuetify encourages is using CSS styling within the single file components. In this method you simply write plain old css inside the `<style>...</style>` tag within your component. Let's see how we can change few styles using this approach

{% gist https://gist.github.com/mtermoul/01230043cded6f6d486149c79e146bc9 %}

It is worth mentioning that in order for you to use css, you need to know CSS selection queries syntax. Meaning if you want to change the card tilte text to italic, then you need to know how to select that div only. For this I used the Chrome dev tools to inspect the title to see what's the class name for that div. Then I used css to change the style like this `.v-card__title { font-style: italic; }` so in this case I relied on Vuetify classes. Other than that this method will allow you to use your plain old CSS tricks to style about anything. My rule of thumb, is don't use this method unless Vuetify does not have any prop or class that does what you are looking for.

![HomePage preview](https://cdn-images-1.medium.com/max/1600/1*FftRe7GCHMvx6CzZcvJ5Hg.png)

#4- Using a stand alone CSS file
In this method, we will be using plain old CSS tricks like the method above, except that we will be writing our css in an external CSS file. This method would be more suitable if we have shared css that will be used by multiple components. The way to implement this is to save the css file under `assets/styles/main.css` then import it within specific component or from the `App.vue` like this:

```
<template>
...
</template>
<script>
...
</script>
<style>
@import './assets/styles/main.css'
</style>
```

#Conclusion
As you can see in the example above, Vuetify and Vue is very flexible in terms how to acheive some tasks. However you have to use some caution on how to use the methods mentioned above and use the recomended way first before unleashing the power of the full raw CSS files.
Also coming in another article the 5th way which will be covered in my next article on how to change styles using themes and SASS variables.
Thanks for reading and let me know what is your prefered way or may be another way not mentioned here.