PHP
Joomla! 6
Joomla! 5
Joomla! 3 (Legacy)
Template
Basic
Load External CSS Stylesheet with WebAssetManager
Registers and enqueues external or local CSS files into the document head using Joomla 5 and 6 WebAssetManager.
templates/seu_template/index.php
<?php
declare(strict_types=1);
use Joomla\CMS\Factory;
$wa = Factory::getApplication()->getDocument()->getWebAssetManager();
$wa->registerAndUseStyle(
'custom.external.css',
'https://cdn.example.com/styles/main.min.css',
['version' => 'auto'],
['media' => 'all']
);
Official Joomla 5 and 6 standard with automatic deduplication and version cache-busting.
templates/seu_template/index.php
<?php
$document = JFactory::getDocument();
$document->addStyleSheet('https://cdn.example.com/styles/main.min.css');
Legacy Joomla 3 method using JFactory::getDocument()->addStyleSheet().
Technical explanation and best practices
In Joomla 5 and 6, WebAssetManager replaces legacy $document->addStyleSheet(), adding dependency resolution, deduplication, cache-busting versions and custom HTML attributes.
Call registerAndUseStyle() to register and enqueue a stylesheet in one clean statement.