Welcome to WebmasterWorld Guest from

Forum Moderators: not2easy

Message Too Old, No Replies

external CSS - How do you specify css file using an absolute path?

How do you specify css file using an absolute path?



11:50 pm on Apr 27, 2009 (gmt 0)

5+ Year Member

Hi Friends,

I am new to CSS and HTML, so this might be a very trivial question. I have a directory named "htdocs/css", where I store all of .css files. Then I have various webpages "htdocs/dir-1/.../dir-n/index.html" spread all around in htdocs directory for different parts of the site. I want to link the each index file with respective .css file using an absolute path like
<LINK ....... href="$somevariable/css/example.css >

and not a relative path like

<LINK ....... href="../../css/example.css >

is there a way I can do it? Please let me know

Su Ti


12:10 am on Apr 28, 2009 (gmt 0)

WebmasterWorld Senior Member swa66 is a WebmasterWorld Top Contributor of All Time 10+ Year Member

Presuming that htdocs directory is where your documentroot is.


in HTML:
<link rel="stylesheet" type="text/css" href="/css/example.css">
in xhtml:
<link rel="stylesheet" type="text/css" href="/css/example.css" />

Put that in your head section.


2:10 pm on Apr 28, 2009 (gmt 0)

5+ Year Member

Thanks SWA,

That worked beautifully. Really appreciate your quick responce.



9:33 am on Jun 1, 2009 (gmt 0)

5+ Year Member

I have a similar problem.

I have a file head.php which contains all the links to css files and script files (basically everything that goes in the <head> tag).

If I include that file in two pages, one in the root folder and one in a subfolder, the one in the subfolder will not be referenced properly since the link to the css file is relative to the root folder:

<link type="text/css" src="css/style.css" />

Adding the '/' to the front of the filepath does not resolve the issue in this case.


Featured Threads

Hot Threads This Week

Hot Threads This Month