• Increase font size
  • Default font size
  • Decrease font size
Home FAQs Developers How can I add a link to a stylesheet in document header?

How can I add a link to a stylesheet in document header?

When a Joomla! extension needs a custom stylesheet, a <link> tag must be programmatically inserted in the document header (i.e. between the <head> and </head> tags of the page that is generated by Joomla!).

To do so you can use JHTML::stylesheet().

Syntax

JHTML::stylesheet(file, path, attribs);

  • file: stylesheet file name.
  • path: path to the folder where the stylesheet (.css file) is located. It can be absolute or relative to Joomla! folder
  • attribs: additional <link> tag attributes

Example

If you want to use a stylesheet to add styles to the markup generated by a component (com_mycomponent) and the .css file (mystyle.css) is located in

[Joomla! folder]/components/com_mycomponent/css/

The code you need to use is

JHTML::stylesheet('mystyle.css','components/com_mycomponent/css/',
array('media'=>'all'));
 
English Italiano

Mootools

banner

Support the development of our open source products.
FeedSubscribe to our feed with announcements of new products and updates