[SOLVED] Hugo Not Rendering CSS but Hugo Server Is

I think my BaseURL is messed up but the past issues in Support all involve a trailing ‘/’ at the baseURL. I have the slash included but whenever I run hugo and open the index.html from hugo\site\public the css refuses to load.

Where am I going wrong with pathing?
Edit:None of the paths are working. When I click on a link it returns a 404.

Output from hugo with config.toml baseURL set to "http://www.adhocref.com/"

Check the link to your CSS file in your page’s source. That should show you why it’s not loading.

link rel=“stylesheet” href=“http://www.adhocref.com/css/style.css” is what I have in the source.

Do I need to set the realativeURLs to true if I’m just browsing the generated site locally?

Here’s how I do it.

<link rel="stylesheet" href="{{ .Site.BaseURL }}/css/style.css">

Also in your config.toml it is considered best practice not to define the protocol.

e.g.

baseURL = "//adhocref.com"

1 Like

[Solved]

Changed baseURL to “/” and everything rendered almost correctly when viewing the output locally.

I would advise against constructing URLs in this fashion. Use absURL and relURL instead:

<link rel="stylesheet" href="{{ "css/style.css" | relURL}}">

Cleaner and you don’t need to worry about discrepancies in the way baseURL is implemented or changing your baseURL to / for local dev, etc…

2 Likes

These are new to me. I guess that I should be paying more attention to the docs with every new release.

But with my setup, I never had a need to change my baseURL to / for Hugo Server.

Anyway thanks!

1 Like

Yes, but only if you want to. Both absURL and relURL have been around for a long time now, and FWIW, I only recommend these because there has been so much confusion over the last year or so about baseURL, etc. HTH. Cheers.

I tried this on my machine but the css doesn’t render.
I still get the localhost:1313/before the css path. I also tried removing baseurl to “/”. Still doesn’t work when I publish i.e hugo -d public server.
Is there something I am missing?

Yes. Need to open a new topic that describes your problem because this is a 5 year old topic.

Also see the Requesting Help guidelines.