How to Bind the Background Image in VueJS ? Last Updated : 28 Apr, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report In VueJS, the background images can be set from different types of properties like data property, computed property, or directly from an image source. In this article, we will see the different approaches to bind the background image in VueJS as listed below: Table of Content Using Inline StyleUsing CSS ClassesUsing Inline StyleIn this approach, we directly bind the background image by specifying inline styles using the style attribute. Syntax:<div :style="{ backgroundImage: 'url(\'your-image-url.jpg\')' }"></div> Example: The below code example will explain the use of the inline style binding to bind the background image HTML <!DOCTYPE html> <html> <head> <title> Background Image binding in VueJS </title> <style> #app{ text-align: center; } #app div{ height: 300px; width: 800px; background-size: cover; background-repeat: no-repeat; margin: auto } h1 { color: green; } </style> </head> <body> <div id="app"> <h1> GeeksforGeeks </h1> <div :style="{ backgroundImage: 'url(' + img + ')'}"> <h3> Background Image binding using the inline styles in VueJS. </h3> <h4> This Background image is bounded using the inline styles in VueJS. </h4> </div> </div> <!-- VueJS CDN Link --> <script src= "https://cdn.jsdelivr.net/npm/vue@2"> </script> <script> new Vue({ el: '#app', data: { img: 'https://media.geeksforgeeks.org/wp-content/cdn-uploads/20220131222755/Vue.js-Tutorial.png', } }) </script> </body> </html> Output: Using CSS ClassesIn this approach we use CSS clases to bind background image, if you have styles for different background images then this approach helps in bind them dynamically. Syntax:<div :class="{ 'background-class-1': condition, 'background-class-2': !condition }"></div>Example: The below example explains the use of the classes to bind the styles using VueJS. HTML <!DOCTYPE html> <html> <head> <title> Background Image binding in VueJS </title> <style> #app{ text-align: center; } .backgroundBindClass{ background-image: url('https://media.geeksforgeeks.org/wp-content/cdn-uploads/20220131222755/Vue.js-Tutorial.png'); height: 300px; width: 800px; background-size: cover; background-repeat: no-repeat; margin: auto } h1 { color: green; } </style> </head> <body> <div id="app"> <h1> GeeksforGeeks </h1> <div :class="{'backgroundBindClass': condition}"> <h3> Background Image binding using the CSS Classes in VueJS. </h3> <h4> This Background image is bounded using the CSS Classes in VueJS. </h4> </div> </div> <!-- VueJS CDN Link --> <script src= "https://cdn.jsdelivr.net/npm/vue@2"> </script> <script> new Vue({ el: '#app', data: { condition: true } }) </script> </body> </html> Output: Comment More infoAdvertise with us Next Article How to set Background Image in react-native ? R raushanpavwbi Follow Improve Article Tags : JavaScript Web Technologies Geeks Premier League Vue.JS Geeks Premier League 2023 +1 More Similar Reads How to Set Background Images in ReactJS Setting the background images in React improves the UI and user experience of web apps by making the appearance better. These images can be some shape or shade using color gradients. In this tutorial, we will look at different methods to apply background images to your react application. How to Set 4 min read How to set Background Image in react-native ? In this article, we will see how to set background Image in react-native. In our project, we will simply set a background image and show a text input on top of it. Setting background images requires using the ImageBackground component in React Native. You can style it further to adapt to different s 5 min read How to Pass Variable to Inline Background Image in VueJS ? In this article, we will learn how we can pass variables to inline background images in VueJS. We will explore two different approaches with practical implementation in terms of examples and outputs. Table of Content Using :style BindingUsing :class BindingUsing :style BindingIn this approach, we ar 2 min read How to Add a Background Image in Next.js? Next.js is a powerful React framework that allows for server-side rendering and the generation of static websites. Adding a background image to your Next.js application can enhance the visual appeal of your web pages. This article will guide you through the process of adding a background image to a 3 min read How to set background-image for the body element using CSS ? In this article, we set the image into the background using CSS property. The background-image property is used to set one or more background images to an element. By default, it places the image in the top left corner. To specify two or more images, separate the URLs with a comma. Syntax: backgroun 2 min read How to add background-image using ngStyle in Angular2 ? The ngStyle Attribute is used to add some style to an HTML element. In this article, we will learn How to add background-image using ngStyle in Angular. To achieve this, we will follow the below approaches.Table of ContentSteps for Installing & Configuring the Angular ApplicationProject Structur 3 min read Like