« Video on the Web | Main | TPAC 2007 - W3C meets the Web community »

Setting the default style sheet language on your Web site

Very often Web creators are using an external style sheet, or a style element to add style information to their html pages. By doing, we specify what is the style language used in the Web page. For example using the `link` element.

<link href="cute.css" rel="stylesheet" type="text/css"/>

But if your page is using the style attribute, the user agent may not know what is the language used for styling. This is a principle of orthogonality. A company could launch a user agent with a new style language and a new mime-type. It will be difficult to impose and ensure interoperability because of the deployment base, but it is still possible.

If you want to set up a default style sheet language for your Web site, there are a few choices. You can use a meta name in each of your page:

<meta http-equiv="Content-Style-Type" content="text/css"/>

or you can specify an HTTP header:

Content-Style-Type: text/css

With Apache http server 2.0, you can use mod_headers and mod_setenvif in the general configuration file or at a directory level in .htaccess:

SetEnvIf response Content-Type [text/html|application/xhtml+xml] html-content=1
Header add "Content-Style-Type: text/css" env=html-content

PS: mod_headers and mod_setenvif are not activated in the base configuration of Apache httpd, you have to activate them.

Examples given for xhtml documents served as application/xhtml+xml

Filed by Karl Dubost on September 27, 2007 6:45 AM in CSS, HTML, HTTP, Technology 101
| | Comments (4) | TrackBacks (0)

Comments

David Dorward # 2007-09-27

It is probably worth fixing the code examples to make them conform to Appendix C of XHTML 1.0. The space before the / is missing.

I also suggest removing the word 'only' from second paragraph. Linking to a style sheet written in one language doesn't mean that the style attributes are going to be using the same language, does it?

You might also want to link to the relevant section of the specification.

karl dubost, w3c # 2007-09-27

Hi David,

I have added a PS explaining the examples were XHTML served as application/xhtml+xml.

And fixed the only. Note that the user agents default to text/css anyway.

Jitendra Vyas # 2009-11-26

so no need to do this if i'm using content="text/html;

Mark Shaw # 2013-03-04

I can't get this to work in Apache 2.2 (Debian). Apache documentation doesn't list

response
as an acceptable attribute for
SetEnvIf
and recommends against the use of
add
with
Header
.

A simple: Header set Content-Style-Type text/css

Works to add the header to all content. Will it do any harm to send the header on non-HTML content?

Leave a comment

Note: this blog is intended to foster polite on-topic discussions. Comments failing these requirements and spam will not get published. Please, enter your real name and email address. Every individual comment is reviewed by the W3C staff. This may take some time, thank you for your patience.

You can use the following HTML markup (a href, b, i, br/, p, strong, em, ul, ol, li, blockquote, pre) and/or Markdown syntax.

Your comment


About you

This blog is written by W3C staff and working group participants,
 and maintained by Coralie Mercier.
Authorized parties may log in to create a new entry.
Powered by Movable Type, magpierss and a lot of Web Technology