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.

Updated on 24 November 2026 110 copies 397 views
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.

Direct Engineering

Have a Joomla project or technical challenge in mind?

From architectural diagnosis to production deployment, directly with the engineer.