Search code examples
htmlcssvisual-studio-codepug

Load external CSS after compiling .pug to html


I have a example.pug and a example.css. On the command line I use pug example.pug which generates a example.html page. Only problem is, the external styling doesn't link when I open the page in a browser. How do I fix this?

Most questions similar to this involve Express, which I'm not using.

Thanks! I'll add the file directory below. -Directory |-Styles |-example.css |-Examples |-examples folder |-example.pug

Hopefully that makes sense. I've also moved the .css directly into the same as my .pug, like so. -Directory |-example.pug |-example.css

I then link as link(href='./tailwater.css', rel='stylesheet', type='text/css') and the css still won't load on the page.


Solution

  • It may be due to writing incorrect path to css files

    Suppose this is your directory structure

    -Directory
    |- example.css
    |- example.html(generated file)
    |- example.pug
    

    Then write link as

    link(rel="stylesheet", href="./example.css")
    

    this way your example.html will contain

    <link rel="style" href="./example.css">
    

    If directory is not of given structure, then adjust href accordingly