How do i add a custom CSS stylesheet in Magento?

How do i add a custom CSS stylesheet in Magento?

August 16, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How do i add a custom CSS stylesheet in Magento?

Adding Custom CSS Stylesheets in Magento

If you’re working on a Magento theme and want to add your own custom stylesheet, it’s important to follow the correct syntax and file structure. In this post, I’ll guide you through adding a custom CSS file and resolving the issue you encountered with the unexpected * error.

Understanding Magento’s Skin Paths

Magento uses skin paths to locate static files like CSS and JavaScript. The theme’s skin path is determined by its configuration in the theme.xml and style.css files. When you want to link your custom stylesheet, you need to reference it within this skin path using Magento’s built-in functions.

Correctly Linking Your Custom Stylesheet

To link a custom CSS file (let’s call it custom.css) to your theme, follow these steps:

  1. Place the custom.css file in the following directory:

    /path/to/your/magento/installation/app/design/frontend/your_vendor/your_theme/web/css
    
  2. Update your theme’s style.css file and add a reference to your custom stylesheet at the bottom, before the closing </style> tag:

/* style.css */
...
@import url('custom.css');

/* Rest of your styles here */
  1. Save the file.

  2. Go to the admin panel, navigate to Content > Design > Configurations and select your theme.

  3. Click on “Edit” for your theme configuration.

  4. Under “HTML Head”, find the “Custom layout update XML” field.

  5. Add the following content inside <reference name="head">:

<head>
    <css src="Magento_Theme::css/custom.css"/>
</head>
  1. Save the changes and flush your Magento cache.

The getSkinUrl() Function

You encountered an error because you tried to use PHP’s getSkinUrl() function inside a JavaScript file (script tag) which is not allowed in Magento 2. This function should only be used within PHP files like layout XML, phtml templates, and controller actions.

Here’s how to correctly use it:

<?php echo $block->getViewFileUrl('css/custom.css') ?>

Conclusion

Adding a custom CSS stylesheet to your Magento theme involves understanding the skin path structure and using the correct functions. By placing your file in the appropriate directory and referencing it correctly, you can ensure that your styles are applied without errors.

Remember to flush your cache after making changes to see the updates immediately. If you’re still having trouble or need further assistance with Magento development, feel free to reach out to our team at Laravel Company.

Happy theming!

API Themes Admin Configuration

Our network