Welcome to WebmasterWorld Guest from

Forum Moderators: not2easy

Message Too Old, No Replies

Put an <a href=""> into a CSS sheet?

8:08 pm on Mar 22, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Sept 8, 2006
votes: 0

Can you put a hyperlink into a CSS sheet?
9:48 pm on Mar 22, 2007 (gmt 0)

Full Member

10+ Year Member

joined:Jan 17, 2007
votes: 0

11:07 pm on Mar 22, 2007 (gmt 0)

Preferred Member

10+ Year Member

joined:Feb 28, 2005
votes: 0


Lol :) To expand on that, no you cannot, CSS is to determine the style (presentation) of content, not to define content itself.

Defining content is the job of (X)HTML. And outputting to that medium, Javascript, PHP, ASP, etcetera.

Having said that, within limits, you can put a hyperlink reference in through CSS-through the



property only works in standards-compliant browsers (or, at least, those nearing it) so it will not work in IE 6. But you can do stuff like this:

<p id="content-property-example">You can head down to:</p>

p#content-property-example:after { content: ' www.spoons.com.au'; }

... while not a particularly practical example (one would argue that the content in the

pseudoclass was necessary and required in the markup itself,) that is how it is done.

There are limitations - Opera 9.10 (as far as I remember) has the best support for the

pseudoclass and the
property, being able to import attribute values of the element, for example:

img:after { content: 'Caption: ' attr(title); }

... where this would not work in Firefox 2 (last I checked.)

Some would argue that content is never necessary in CSS - that CSS is for defining presentation, not content - and I tend to agree with them. One thing I do use

for is in my print styles: when a user prints out a page from one of the websites I've written, it dumps the
value from anchors after the anchor's content itself - thus, a printed document with good reference back to the web if necessary.

[edit]Oh, I forgot to mention: the reason I use such a thing in my print styles is degradation: it doesn't impact IE 6 negatively by not supporting it, it doesn't ruin functionality, it is merely "icing on the cake" for those UAs that can support it. I believe that "without CSS, the markup should stand up for itself." - and try to keep that in mind whenever doing CSS-Presentation.

[/edit][edited by: Setek at 11:11 pm (utc) on Mar. 22, 2007]