Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Radiosilent's avatar

How do I use app.css in a blade?

I'm trying to use app.css in a blade.

  • I've tried saving app.css in resources/css, and also in public/css.
  • if I put this in the SCRIPT section of my blade, then all of my cards turn aqua:
.card {
    background-color: aqua;
}

If I include the same in the app.css file then no style is created: app.css:

@tailwind base;
@tailwind components;
@tailwind utilities;

[x-cloak] {
    display: none;
}

.card {
    background-color: greenyellow;
}

body {
    background-color: lightblue;
}

h1 {
    color: red;
    margin-left: 20px;
}

Blade, head section:

<link rel="stylesheet" href="*/public/css/app.css">

Any idea what I'm doing wrong?

Thanks!

0 likes
6 replies
LaryAI's avatar
Level 58

To use app.css in a Blade template, you need to ensure a few things are set up correctly. Here's a step-by-step guide to help you resolve the issue:

  1. Ensure CSS Compilation: If you're using Tailwind CSS, you need to compile your CSS using a tool like Laravel Mix. Make sure you have the following setup in your webpack.mix.js file:

    const mix = require('laravel-mix');
    
    mix.js('resources/js/app.js', 'public/js')
       .postCss('resources/css/app.css', 'public/css', [
           require('tailwindcss'),
       ]);
    
  2. Compile Assets: Run the following command to compile your assets:

    npm run dev
    

    This will process your app.css file and output it to public/css/app.css.

  3. Correct Link in Blade Template: Ensure that the link to your CSS file in the Blade template is correct. It should not include */public/ as the public directory is the root for serving assets. Update your Blade template to:

    <link rel="stylesheet" href="{{ asset('css/app.css') }}">
    

    The {{ asset('css/app.css') }} helper function generates the correct URL to the app.css file in the public/css directory.

  4. Check for Compilation Errors: If the styles are still not applying, check the console or terminal for any errors during the compilation process. Ensure that Tailwind CSS is properly installed and configured.

  5. Clear Cache: Sometimes, browser caching can cause issues. Clear your browser cache or try accessing the page in an incognito window to see if the styles apply correctly.

By following these steps, your app.css should be correctly linked and the styles should apply as expected in your Blade template.

Radiosilent's avatar

@LaryAI .... Thanks! #3 was it. Took 3 minutes to read your response, check, and fix.

Radiosilent's avatar

@Tray2 ... to be 100% transparent, that's a great idea. I'm resurrecting an old project, and frankly I don't have a lot of Laravel experience. I went through the first half of the "30 days..." videos and picked up a ton of great hints (but, sadly...nothing on CSS). I post odd stuff here because within 2 mins to 6 hours LaryAI usually responds with a comprehensive set of things to try based on my exact input (rather than the "ReadTtheFM" or "WatchTheFV" responses that seem to abound here). We've paid monthly for many years, right? I wish they'd give us an AI response area where no live humans are involved and it....usually?....works. 3 mins vs 30 days. Bottom line...I'm a CFO so this isn't my profession, I'm trying to improve something and not learn an entire ecosystem.

Sorry, it's a Friday night. Don't mean to be that guy (but I may have been, so please accept my apologies). Have a great weekend.

RS_ai

Tray2's avatar
Tray2
Best Answer
Level 73

@Radiosilent Click on the icon next to your profilee pic, there you can chat away with Lary to your heart's content.

Please or to participate in this conversation.