Skip to content
PHP Ecosystem
Explore

Svg

API reference › HTML SVG › Svg

Represents the SVG <svg> (svg) element for scalable vector graphics containers.

Provides a concrete implementation of the SVG <svg> container element that returns SvgBlock::SVG and inherits attribute methods from BaseSvg for viewport, paint, and transform attributes.

The <svg> element defines a new coordinate system and viewport for SVG graphics. It is used as the outermost element of SVG documents, or to embed SVG fragments within HTML or SVG documents.

Usage example:

use UIAwesome\Html\Svg\{Circle, Svg};
echo Svg::tag()
->xmlns('http://www.w3.org/2000/svg')
->viewBox('0 0 100 100')
->title('Circle example')
->content(Circle::tag()->cx(50)->cy(50)->r(40)->fill('currentColor'))
->render();

See also: https://developer.mozilla.org/en-US/docs/Web/SVG/Element/svg (BaseSvg for the base implementation.).

PropertyTypeDescriptionDefined by
$attributes protectedmixed[]HTML attributes array used by the implementing class. Default: [].UIAwesome\Html\Mixin\HasAttributes
$content protectedstringContent string assigned to the element. Default: ''.UIAwesome\Html\Mixin\HasContent
MethodDescriptionDefined by
__construct() finalInitializes a new tag instance.UIAwesome\Html\Core\Base\BaseTag
__toString()Returns the rendered tag string.UIAwesome\Html\Core\Base\BaseTag
accesskey()Sets the accesskey attribute.UIAwesome\Html\Attribute\Global\HasAccesskey
addAriaAttribute()Sets an aria-* attribute.UIAwesome\Html\Attribute\Global\HasAria
addAttribute()Adds or updates a single HTML attribute for the element.UIAwesome\Html\Mixin\HasAttributes
addDataAttribute()Sets a data-* attribute.UIAwesome\Html\Attribute\Global\HasData
addEvent()Sets an on* event attribute.UIAwesome\Html\Attribute\Global\HasEvents
ariaAttributes()Sets multiple aria-* attributes.UIAwesome\Html\Attribute\Global\HasAria
attributes()Adds or updates multiple HTML attributes for the element.UIAwesome\Html\Mixin\HasAttributes
autofocus()Sets the autofocus attribute.UIAwesome\Html\Attribute\Global\CanBeAutofocus
begin() finalStarts begin/end rendering for this instance.UIAwesome\Html\Core\Element\BaseBlock
class()Sets the class attribute.UIAwesome\Html\Attribute\Global\HasClass
clearContent()Clears encoded and raw content without changing other component state.UIAwesome\Html\Mixin\HasContent
config()Applies application-scoped config recipes to this tag.UIAwesome\Html\Core\Base\BaseTag
content()Appends encoded content.UIAwesome\Html\Mixin\HasContent
contentEditable()Sets the contenteditable attribute.UIAwesome\Html\Attribute\Global\HasContentEditable
dataAttributes()Sets multiple data-* attributes.UIAwesome\Html\Attribute\Global\HasData
dir()Sets the dir attribute.UIAwesome\Html\Attribute\Global\HasDir
draggable()Sets the draggable attribute.UIAwesome\Html\Attribute\Global\HasDraggable
end() static finalEnds the most recent begin/end rendering block for the current class.UIAwesome\Html\Core\Element\BaseBlock
events()Sets multiple on* event attributes.UIAwesome\Html\Attribute\Global\HasEvents
filePath()Sets the file path for the SVG file to be rendered.UIAwesome\Html\Svg\Base\BaseSvg
fill()Sets the SVG fill attribute for the element.UIAwesome\Html\Svg\Base\BaseSvg
fillOpacity()Sets SVG fill-opacity attribute for the element.UIAwesome\Html\Svg\Base\BaseSvg
fillRule()Sets SVG fill-rule attribute for the element.UIAwesome\Html\Svg\Base\BaseSvg
getAttribute()Returns the value of a single HTML attribute.UIAwesome\Html\Mixin\HasAttributes
getAttributes()Overrides the attribute retrieval to filter out the title attribute.UIAwesome\Html\Svg\Base\BaseSvg
getContent()Retrieves the content of the SVG element, injecting a <title> element when defined.UIAwesome\Html\Svg\Base\BaseSvg
height()Sets the height attribute.UIAwesome\Html\Svg\Base\BaseSvg
hidden()Sets the hidden attribute.UIAwesome\Html\Attribute\Global\CanBeHidden
html()Appends trusted raw HTML content without encoding or sanitizing it.UIAwesome\Html\Mixin\HasContent
icon() staticReturns a new Svg instance configured to render an icon bundled with the package.Svg
iconPath() staticResolves an icon reference to the absolute file path of the SVG asset shipped with this package.Svg
id()Sets the id attribute.UIAwesome\Html\Attribute\Global\HasId
itemId()Sets the itemid attribute.UIAwesome\Html\Attribute\Global\HasMicroData
itemProp()Sets the itemprop attribute.UIAwesome\Html\Attribute\Global\HasMicroData
itemRef()Sets the itemref attribute.UIAwesome\Html\Attribute\Global\HasMicroData
itemScope()Sets the itemscope attribute.UIAwesome\Html\Attribute\Global\HasMicroData
itemType()Sets the itemtype attribute.UIAwesome\Html\Attribute\Global\HasMicroData
lang()Sets the lang attribute.UIAwesome\Html\Attribute\Global\HasLang
opacity()Sets the SVG opacity attribute for the element.UIAwesome\Html\Svg\Base\BaseSvg
preserveAspectRatio()Sets the SVG preserveAspectRatio attribute for the element.UIAwesome\Html\Svg\Base\BaseSvg
removeAriaAttribute()Removes an aria-* attribute.UIAwesome\Html\Attribute\Global\HasAria
removeAttribute()Removes a specific HTML attribute from the element.UIAwesome\Html\Mixin\HasAttributes
removeDataAttribute()Removes a data-* attribute.UIAwesome\Html\Attribute\Global\HasData
removeEvent()Removes an on* event attribute.UIAwesome\Html\Attribute\Global\HasEvents
render() finalRenders the tag with lifecycle hooks.UIAwesome\Html\Core\Base\BaseTag
replaceAttributes()Replaces all HTML attributes for the element.UIAwesome\Html\Mixin\HasAttributes
role()Sets the role attribute.UIAwesome\Html\Attribute\Global\HasRole
spellcheck()Sets the spellcheck attribute.UIAwesome\Html\Attribute\Global\HasSpellcheck
stroke()Sets the SVG stroke attribute for the element.UIAwesome\Html\Svg\Base\BaseSvg
strokeDashArray()Sets the SVG stroke-dasharray attribute for the element.UIAwesome\Html\Svg\Base\BaseSvg
strokeLineCap()Sets the SVG stroke-linecap attribute for the element.UIAwesome\Html\Svg\Base\BaseSvg
strokeLineJoin()Sets the SVG stroke-linejoin attribute for the element.UIAwesome\Html\Svg\Base\BaseSvg
strokeMiterlimit()Sets SVG stroke-miterlimit attribute for the element.UIAwesome\Html\Svg\Base\BaseSvg
strokeOpacity()Sets SVG stroke-opacity attribute for the element.UIAwesome\Html\Svg\Base\BaseSvg
strokeWidth()Sets the SVG stroke-width attribute for the element.UIAwesome\Html\Svg\Base\BaseSvg
style()Sets the style attribute.UIAwesome\Html\Attribute\Global\HasStyle
tabIndex()Sets the tabindex attribute.UIAwesome\Html\Attribute\Global\HasTabindex
tag() staticCreates and configures a new tag instance.UIAwesome\Html\Core\Base\BaseTag
title()Sets the title attribute.UIAwesome\Html\Attribute\Global\HasTitle
transform()Sets the SVG transform attribute for the element.UIAwesome\Html\Svg\Base\BaseSvg
translate()Sets the translate attribute.UIAwesome\Html\Attribute\Global\HasTranslate
viewBox()Sets the SVG viewBox attribute for the element.UIAwesome\Html\Svg\Base\BaseSvg
width()Sets the width attribute.UIAwesome\Html\Svg\Base\BaseSvg
x()Sets the SVG x attribute for the element.UIAwesome\Html\Svg\Base\BaseSvg
xmlns()Sets the xmlns attribute for the SVG element.UIAwesome\Html\Svg\Base\BaseSvg
y()Sets the SVG y attribute for the element.UIAwesome\Html\Svg\Base\BaseSvg
afterRun() protectedPost-processes rendered output.UIAwesome\Html\Core\Event\HasAfterRun
beforeRun() protectedPre-run validation for SVG rendering.UIAwesome\Html\Svg\Base\BaseSvg
getTag() protectedReturns the tag enumeration for the <svg> element.Svg
isBeginExecuted() protectedIndicates whether this instance has an open or closing operation in the current context.UIAwesome\Html\Core\Element\BaseBlock
loadDefault() protectedReturns class-level default definitions.UIAwesome\Html\Core\Base\BaseTag
run() protectedExecutes the rendering routine for the SVG element.UIAwesome\Html\Svg\Base\BaseSvg
runBegin() protectedReturns the opening tag for begin/end rendering.UIAwesome\Html\Core\Element\BaseBlock
public static function icon(string $reference): self

Returns a new Svg instance configured to render an icon bundled with the package.

Accepts a reference of the form Collection:name (for example, Bootstrap5:globe). Icons resolve against the path assets/icons/{Collection}/{name}.svg shipped with this package. Chain additional fluent methods (width, height, fill, …) before rendering.

Usage example:

echo \UIAwesome\Html\Svg\Svg::icon('Bootstrap5:globe')
->width(32)
->height(32)
->fill('currentColor')
->render();

Parameters

ParameterTypeDescription
$referencestringIcon reference in the form Collection:name. Each segment must match [A-Za-z0-9_-]+.

Returns

self: New instance with the resolved SVG file path configured.

Throws

  • InvalidArgumentException: if $reference does not match the Collection:name format, or if the resolved path is not a bundled SVG file.
public static function iconPath(string $reference): string

Resolves an icon reference to the absolute file path of the SVG asset shipped with this package.

Accepts a reference of the form Collection:name (for example, Bootstrap5:globe). Useful when the file path is needed without instantiating a Svg (for example, when configuring iconFilePath() on another component).

Usage example:

$component->iconFilePath(\UIAwesome\Html\Svg\Svg::iconPath('Bootstrap5:globe'));

Parameters

ParameterTypeDescription
$referencestringIcon reference in the form Collection:name. Each segment must match [A-Za-z0-9_-]+; references containing path separators, .., or empty segments are rejected to keep the resolved path inside the bundled assets/icons directory.

Returns

string: Absolute path to the resolved SVG file.

Throws

  • InvalidArgumentException: if $reference does not match the Collection:name format, or if the resolved path is not a bundled SVG file.
protected function getTag(): BackedEnum

Returns the tag enumeration for the <svg> element.

Returns

BackedEnum: Tag enumeration instance for <svg>. SvgBlock for valid SVG block-level tags.