Load external CSS file into Vue.js component

in Code Write a comment

In this tutorial, you’ll learn how to import external/local CSS files in Vue.js components.

Include CSS file in one component

If you want to include the external CSS file in only one component you can import it in the <style></style> tag.

For example, we want to include Bootstrap 4 CSS file in a single component. It will only work for that component. Here’s how you can do it.

@import 'https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css';

Include globally

If you want your external CSS file to be globally accessible you can include it in your main.js file.

import '@/scss/main.scss';

Main.scss CSS styles will apply to your entire Vue.js app. You can also replace it with an external CSS file by changing the path, like so:

import 'https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css';

Include in index.html

You can also include external CSS files in your index.html file. This will make them available globally, but you won’t be able to include .SCSS files and have full control over SCSS variables.

I suggest including external CSS files in main.js file instead.

If you find this post useful, please let me know in the comments below. 
Renat Galyamov

Want to share this with your friends?

PS: Make sure you check other Vue.js tutorials, e.g. commenting out code in Vue.jshow to stop mouse event propagation in Vue.js and remove duplicate values from Vue.js array using ES6.

Incoming search terms:

Write a Comment



  1. When trying to do so via main.js, getting:

    > Failed to compile.
    > ./src/main.js
    > Module not found: Error: Can’t resolve ‘https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css’ in ‘yourpath/src’