Include external CSS file in Vue.js component
Tutorial on how to include external or local css in vue globally or only in one component.
Tutorial on how to import local or external CSS files in Vue.js application.
Here we will see how to include the CSS file in Vue:
- Only in one component ( in a separate file )
- Globally
Import CSS files into a single file component
In Vue.js app, we have to work with many components. And if we want to include a local or external CSS file in only one component then we have to import it in the <style></style> tags.
For example, we want to include the style.css file from the assets folder to a single component. To import it we have to do is:
<style> @import '@/assets/css/style.css'; </style>
or if you want to include a cdn (like bootstrap) only in one component then:
<style> @import 'https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css'; </style>
Now the styles from style.cssfile will only be applied to the single component only.
Include CSS globally in Vue
In vuejs , to include a CSS file that is globally accessible to all the components in your vue project, we have to import it in the main.js file.
Example:
We have a style.css file in the assets folder. To load it in our Vue.js app we have to import it to main.js :
import './assets/css/style.css'
You can also include cdn in the main.js :
import 'https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css';
In main.js file:

Now all the CSS code in the style.css file will be applied to your entire Vue.js app.
Related Topics:
How To Add Common Header And Footer In Vuejs.
How To Add Dynamic HTML Attributes In VueJS ?
Related Posts
Easy Way to use localStorage with Vue
Short article on how to use local storage with Vue and learn saving and storing data in local storage with the setItem() and getItem() methods.
Force update Vue to Reload/Rerender component
Short tutorial on how to correctly force update Vue.js component to reload or rerender. The component is reinitialized without having to do a browser refresh.
Set and get cookies in a browser in Vue App
Find out how to set and get cookies in a browser for your webpage in Vue using vue-cookies package.
Save vuex state after page refresh in Vue App
Short tutorial on how to save (or persist) data in a vue application using Vuex and vuex-persist npm package.
