Hello Shopify Community,
I am a one-man army trying to customize my Shopify store, and I am currently struggling with adding custom CSS code to display different images on desktop and mobile. Specifically, I want to display a specific image (“shopifybackground-Recovered_a3…b-4eb1-4ced-94b4-376521ffd8ba”) on desktop while having another image displayed on mobile. I have been trying to add the code in the theme editor, but I have not been successful so far. I have also tried different codes suggested by Chat GPT, but none of them seem to work. As someone with no coding experience, I am hoping to get help from the Shopify community to add the correct custom CSS code for this task. Any help or guidance would be greatly appreciated.
See below one of the codes I’ve tried:
@media screen and (min-width: 768px) {
body {
background-image: url('shopifybackground-Recovered_a3…
Thank you in advance for your assistance.
Hello there
To display different images on desktop and mobile using custom CSS in your Shopify store, you can use media queries to target specific screen sizes. Here’s an example of how you can achieve this:
-
Upload your desktop and mobile images to your Shopify store and note the file names or URLs.
-
In your Shopify theme editor, navigate to the “Assets” folder and open the “theme.scss.liquid” file.
-
Scroll to the bottom of the file and add the following code:
/* Desktop image */
@media (min-width: 768px) {
body {
background-image: url("{{ 'shopifybackground-desktop.jpg' | asset_url }}");
}
}
/* Mobile image */
@media (max-width: 767px) {
body {
background-image: url("{{ 'shopifybackground-mobile.jpg' | asset_url }}");
}
}
Note that you should replace the file names in the code with the actual file names or URLs of your desktop and mobile images.
- Save the changes to the “theme.scss.liquid” file and refresh your website to see the changes.