Text
API reference › HTML SVG › Text
Represents the SVG <text> (text) element for rendering text content in SVG graphics.
Provides a concrete <text> element implementation that returns SvgBlock::TEXT and provides text layout,
typography, paint, and transform attribute methods.
The <text> element defines text content with positioning, layout, and typography attributes.
Usage example:
use UIAwesome\Html\Svg\Text;
echo Text::tag() ->x(12) ->y(24) ->fontSize(16) ->fill('currentColor') ->content('Hello SVG') ->render();See also: https://developer.mozilla.org/en-US/docs/Web/SVG/Element/text (BaseBlock for the base block-level implementation.).
Properties
Section titled “Properties”| Property | Type | Description | Defined by |
|---|---|---|---|
$attributes protected | mixed[] | HTML attributes array used by the implementing class. Default: []. | UIAwesome\ |
$content protected | string | Content string assigned to the element. Default: ''. | UIAwesome\ |
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
__construct() final | Initializes a new tag instance. | UIAwesome\ |
__toString() | Returns the rendered tag string. | UIAwesome\ |
accesskey() | Sets the accesskey attribute. | UIAwesome\ |
addAriaAttribute() | Sets an aria-* attribute. | UIAwesome\ |
addAttribute() | Adds or updates a single HTML attribute for the element. | UIAwesome\ |
addDataAttribute() | Sets a data-* attribute. | UIAwesome\ |
addEvent() | Sets an on* event attribute. | UIAwesome\ |
ariaAttributes() | Sets multiple aria-* attributes. | UIAwesome\ |
attributes() | Adds or updates multiple HTML attributes for the element. | UIAwesome\ |
autofocus() | Sets the autofocus attribute. | UIAwesome\ |
begin() final | Starts begin/end rendering for this instance. | UIAwesome\ |
class() | Sets the class attribute. | UIAwesome\ |
clearContent() | Clears encoded and raw content without changing other component state. | UIAwesome\ |
config() | Applies application-scoped config recipes to this tag. | UIAwesome\ |
content() | Appends encoded content. | UIAwesome\ |
contentEditable() | Sets the contenteditable attribute. | UIAwesome\ |
dataAttributes() | Sets multiple data-* attributes. | UIAwesome\ |
dir() | Sets the dir attribute. | UIAwesome\ |
dominantBaseline() | Sets SVG dominant-baseline attribute for the element. | Text |
draggable() | Sets the draggable attribute. | UIAwesome\ |
dx() | Sets the SVG dx attribute for the element. | Text |
dy() | Sets the SVG dy attribute for the element. | Text |
end() static final | Ends the most recent begin/end rendering block for the current class. | UIAwesome\ |
events() | Sets multiple on* event attributes. | UIAwesome\ |
fill() | Sets the SVG fill attribute for the element. | Text |
fillOpacity() | Sets SVG fill-opacity attribute for the element. | Text |
fillRule() | Sets SVG fill-rule attribute for the element. | Text |
fontFamily() | Sets the SVG font-family attribute for the element. | Text |
fontSize() | Sets the SVG font-size attribute for the element. | Text |
fontStyle() | Sets SVG font-style attribute for the element. | Text |
fontWeight() | Sets the SVG font-weight attribute for the element. | Text |
getAttribute() | Returns the value of a single HTML attribute. | UIAwesome\ |
getAttributes() | Returns the array of HTML attributes for the element. | UIAwesome\ |
getContent() | Returns the content assigned to the element. | UIAwesome\ |
hidden() | Sets the hidden attribute. | UIAwesome\ |
html() | Appends trusted raw HTML content without encoding or sanitizing it. | UIAwesome\ |
id() | Sets the id attribute. | UIAwesome\ |
itemId() | Sets the itemid attribute. | UIAwesome\ |
itemProp() | Sets the itemprop attribute. | UIAwesome\ |
itemRef() | Sets the itemref attribute. | UIAwesome\ |
itemScope() | Sets the itemscope attribute. | UIAwesome\ |
itemType() | Sets the itemtype attribute. | UIAwesome\ |
lang() | Sets the lang attribute. | UIAwesome\ |
lengthAdjust() | Sets SVG lengthAdjust attribute for the element. | Text |
letterSpacing() | Sets the SVG letter-spacing attribute for the element. | Text |
opacity() | Sets the SVG opacity attribute for the element. | Text |
removeAriaAttribute() | Removes an aria-* attribute. | UIAwesome\ |
removeAttribute() | Removes a specific HTML attribute from the element. | UIAwesome\ |
removeDataAttribute() | Removes a data-* attribute. | UIAwesome\ |
removeEvent() | Removes an on* event attribute. | UIAwesome\ |
render() final | Renders the tag with lifecycle hooks. | UIAwesome\ |
replaceAttributes() | Replaces all HTML attributes for the element. | UIAwesome\ |
role() | Sets the role attribute. | UIAwesome\ |
rotate() | Sets the SVG rotate attribute for the element. | Text |
spellcheck() | Sets the spellcheck attribute. | UIAwesome\ |
stroke() | Sets the SVG stroke attribute for the element. | Text |
strokeDashArray() | Sets the SVG stroke-dasharray attribute for the element. | Text |
strokeLineCap() | Sets the SVG stroke-linecap attribute for the element. | Text |
strokeLineJoin() | Sets the SVG stroke-linejoin attribute for the element. | Text |
strokeMiterlimit() | Sets SVG stroke-miterlimit attribute for the element. | Text |
strokeOpacity() | Sets SVG stroke-opacity attribute for the element. | Text |
strokeWidth() | Sets the SVG stroke-width attribute for the element. | Text |
style() | Sets the style attribute. | UIAwesome\ |
tabIndex() | Sets the tabindex attribute. | UIAwesome\ |
tag() static | Creates and configures a new tag instance. | UIAwesome\ |
textAnchor() | Sets SVG text-anchor attribute for the element. | Text |
textDecoration() | Sets the SVG text-decoration shorthand attribute for the text element. | Text |
textLength() | Sets the SVG textLength attribute for the element. | Text |
title() | Sets the title attribute. | Text |
transform() | Sets the SVG transform attribute for the element. | Text |
translate() | Sets the translate attribute. | UIAwesome\ |
wordSpacing() | Sets the SVG word-spacing attribute for the element. | Text |
writingMode() | Sets SVG writing-mode attribute for the element. | Text |
x() | Sets the SVG x attribute for the element. | Text |
y() | Sets the SVG y attribute for the element. | Text |
afterRun() protected | Post-processes rendered output. | UIAwesome\ |
beforeRun() protected | Validates state before rendering. | UIAwesome\ |
getTag() protected | Returns the tag enumeration for the <text> element. | Text |
isBeginExecuted() protected | Indicates whether this instance has an open or closing operation in the current context. | UIAwesome\ |
loadDefault() protected | Returns class-level default definitions. | UIAwesome\ |
run() protected | Renders the block element. | UIAwesome\ |
runBegin() protected | Returns the opening tag for begin/end rendering. | UIAwesome\ |
Method details
Section titled “Method details”dominantBaseline()
Section titled “dominantBaseline() ”public function dominantBaseline(UIAwesome\Html\Svg\Values\DominantBaseline|string|null $value): staticSets SVG dominant-baseline attribute for the element.
Creates a new instance with the specified dominant baseline value for the rendered element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | UIAwesome\| | Dominant baseline value to set for the element. Accepts ‘auto’, ‘alphabetic’, ‘middle’, ‘central’, ‘hanging’, ‘mathematical’, ‘ideographic’, ‘text-top’, ‘text-bottom’, DominantBaseline enum, or null to unset. |
Returns
static: New instance with the updated dominant-baseline attribute.
Throws
InvalidArgumentException: If the provided value is not a validDominantBaselineenum or string.
public function dx(float|int|string|null $value): staticSets the SVG dx attribute for the element.
Creates a new instance with the specified dx-offset value for the rendered element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | float| | DX offset value (for example, ‘10’, ‘5 10 15’, or null to unset). |
Returns
static: New instance with the updated dx attribute.
public function dy(float|int|string|null $value): staticSets the SVG dy attribute for the element.
Creates a new instance with the specified dy-offset value for the rendered element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | float| | DY offset value (for example, ‘10’, ‘5 10 15’, or null to unset). |
Returns
static: New instance with the updated dy attribute.
fill()
Section titled “fill() ”public function fill(string|null $value): staticSets the SVG fill attribute for the element.
Creates a new instance with the specified fill value for the rendered element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | string| | Fill value (for example, ‘red’, ‘url(#gradient1)’, or null to unset). |
Returns
static: New instance with the updated fill attribute.
fillOpacity()
Section titled “fillOpacity() ”public function fillOpacity(float|int|string|null $value): staticSets SVG fill-opacity attribute for the element.
Creates a new instance with the specified fill opacity value for the rendered element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | float| | Fill opacity value (for example, ‘0.5’ or null to unset). |
Returns
static: New instance with the updated fill-opacity attribute.
Throws
InvalidArgumentException: If the value is outside the allowed range (‘0’-‘1’) and notnull.
fillRule()
Section titled “fillRule() ”public function fillRule(UIAwesome\Html\Svg\Values\FillRule|string|null $value): staticSets SVG fill-rule attribute for the element.
Creates a new instance with the specified fill rule value for the rendered element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | UIAwesome\| | Fill rule value to set for the element. Accepts ‘nonzero’, ‘evenodd’, FillRule enum, or null to unset. |
Returns
static: New instance with the updated fill-rule attribute.
Throws
InvalidArgumentException: If the provided value is not a validFillRuleenum or string.
fontFamily()
Section titled “fontFamily() ”public function fontFamily(string|null $value): staticSets the SVG font-family attribute for the element.
Creates a new instance with the specified font family value for the rendered element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | string| | Font family value (for example, ‘Arial’, ‘Arial, sans-serif’, or null to unset). |
Returns
static: New instance with the updated font-family attribute.
fontSize()
Section titled “fontSize() ”public function fontSize(float|int|string|null $value): staticSets the SVG font-size attribute for the element.
Creates a new instance with the specified font size value for the rendered element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | float| | Font size value (for example, ‘16’, ‘1.2em’, ‘120%’, or null to unset). |
Returns
static: New instance with the updated font-size attribute.
fontStyle()
Section titled “fontStyle() ”public function fontStyle(UIAwesome\Html\Svg\Values\FontStyle|string|null $value): staticSets SVG font-style attribute for the element.
Creates a new instance with the specified font style value for the rendered element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | UIAwesome\| | Font style value to set for the element. Accepts ‘normal’, ‘italic’, ‘oblique’, FontStyle enum, or null to unset. |
Returns
static: New instance with the updated font-style attribute.
Throws
InvalidArgumentException: If the provided value is not a validFontStyleenum or string.
fontWeight()
Section titled “fontWeight() ”public function fontWeight(int|string|null $value): staticSets the SVG font-weight attribute for the element.
Creates a new instance with the specified font weight value for the rendered element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | int| | Font weight value (for example, ‘700’, ‘bold’, or null to unset). |
Returns
static: New instance with the updated font-weight attribute.
lengthAdjust()
Section titled “lengthAdjust() ”public function lengthAdjust(UIAwesome\Html\Svg\Values\LengthAdjust|string|null $value): staticSets SVG lengthAdjust attribute for the element.
Creates a new instance with the specified length adjust value for the rendered element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | UIAwesome\| | Length adjust value (for example, ‘spacing’, LengthAdjust enum, or null to unset). |
Returns
static: New instance with the updated lengthAdjust attribute.
Throws
InvalidArgumentException: If the provided value is not a validLengthAdjustenum or string.
letterSpacing()
Section titled “letterSpacing() ”public function letterSpacing(float|int|string|null $value): staticSets the SVG letter-spacing attribute for the element.
Creates a new instance with the specified letter spacing value for the rendered element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | float| | Letter spacing value (for example, ‘2’, ‘0.1em’, ‘normal’, or null to unset). |
Returns
static: New instance with the updated letter-spacing attribute.
opacity()
Section titled “opacity() ”public function opacity(float|int|string|null $value): staticSets the SVG opacity attribute for the element.
Creates a new instance with the specified opacity value for the rendered element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | float| | Opacity value (for example, ‘0.5’ or null to unset). |
Returns
static: New instance with the updated opacity attribute.
Throws
InvalidArgumentException: If the value is outside the allowed range (‘0’-‘1’) and notnull.
rotate()
Section titled “rotate() ”public function rotate(float|int|string|null $value): staticSets the SVG rotate attribute for the element.
Creates a new instance with the specified rotation value for the rendered element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | float| | Rotate value (for example, ‘45’, ‘10 20 30 40’, or null to unset). |
Returns
static: New instance with the updated rotate attribute.
stroke()
Section titled “stroke() ”public function stroke(string|null $value): staticSets the SVG stroke attribute for the element.
Creates a new instance with the specified stroke value for the rendered element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | string| | Stroke paint value (for example, ‘black’, ‘url(#gradient1)’, or null to unset). |
Returns
static: New instance with the updated stroke attribute.
strokeDashArray()
Section titled “strokeDashArray() ”public function strokeDashArray(float|int|string|null $value): staticSets the SVG stroke-dasharray attribute for the element.
Creates a new instance with the specified dash array value for the rendered element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | float| | Dash array value (for example, ‘5.3’ or null to unset). |
Returns
static: New instance with the updated stroke-dasharray attribute.
See also
- https://www.w3.org/TR/SVG2/painting.html#StrokeDashing (Usage example: $element->strokeDashArray(5.3); $element->strokeDashArray(4); $element->strokeDashArray(null);)
strokeLineCap()
Section titled “strokeLineCap() ”public function strokeLineCap(string|UIAwesome\Html\Svg\Values\StrokeLineCap|null $value): staticSets the SVG stroke-linecap attribute for the element.
Creates a new instance with the specified stroke line cap value for the rendered element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | string|UIAwesome\| | Stroke line cap style (for example, ‘round’, StrokeLineCap enum, or null to unset). |
Returns
static: New instance with the updated stroke-linecap attribute.
Throws
InvalidArgumentException: If the provided value is not a validStrokeLineCapenum or string.
strokeLineJoin()
Section titled “strokeLineJoin() ”public function strokeLineJoin(string|UIAwesome\Html\Svg\Values\StrokeLineJoin|null $value): staticSets the SVG stroke-linejoin attribute for the element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | string|UIAwesome\| | Stroke line join style (for example, ‘miter’, StrokeLineJoin enum, or null to unset). |
Returns
static: New instance with the updated stroke-linejoin attribute.
Throws
InvalidArgumentException: If the provided value is not a validStrokeLineJoinenum or string.
strokeMiterlimit()
Section titled “strokeMiterlimit() ”public function strokeMiterlimit(float|int|string|null $value): staticSets SVG stroke-miterlimit attribute for the element.
Creates a new instance with the specified stroke miter limit value for the rendered element.
The stroke-miterlimit attribute controls the limit on the ratio of the miter length to the stroke width. When
the limit is exceeded, the join is converted from a miter to a bevel. The value must be a number ’>= 1’.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | float| | Stroke miter limit value (for example, ‘4’ or null to unset). |
Returns
static: New instance with the updated stroke-miterlimit attribute.
Throws
InvalidArgumentException: If value is not a number ’>= 1’ ornull.
See also
- https://www.w3.org/TR/SVG2/painting.html#StrokeMiterlimitProperty (Usage example: $element->strokeMiterlimit(4); $element->strokeMiterlimit(null);)
strokeOpacity()
Section titled “strokeOpacity() ”public function strokeOpacity(float|int|string|null $value): staticSets SVG stroke-opacity attribute for the element.
Creates a new instance with the specified stroke opacity value for the rendered element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | float| | Stroke opacity value (for example, ‘0.8’ or null to unset). |
Returns
static: New instance with the updated stroke-opacity attribute.
Throws
InvalidArgumentException: If the value is outside the allowed range (‘0’-‘1’) and notnull.
strokeWidth()
Section titled “strokeWidth() ”public function strokeWidth(int|string|null $value): staticSets the SVG stroke-width attribute for the element.
Creates a new instance with the specified stroke width value for the rendered element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | int| | Stroke width value (for example, ‘2’, ‘1.5em’, or null to unset). |
Returns
static: New instance with the updated stroke-width attribute.
textAnchor()
Section titled “textAnchor() ”public function textAnchor(string|UIAwesome\Html\Svg\Values\TextAnchor|null $value): staticSets SVG text-anchor attribute for the element.
Creates a new instance with the specified text anchor value for the rendered element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | string|UIAwesome\| | Text anchor value to set for the element. Accepts ‘start’, ‘middle’, ‘end’, TextAnchor enum, or null to unset. |
Returns
static: New instance with the updated text-anchor attribute.
Throws
InvalidArgumentException: If the provided value is not a validTextAnchorenum or string.
textDecoration()
Section titled “textDecoration() ”public function textDecoration(string|UIAwesome\Html\Svg\Values\TextDecorationLine|UIAwesome\Html\Svg\Values\TextDecorationStyle|null $value): staticSets the SVG text-decoration shorthand attribute for the text element.
Creates a new instance with the specified text decoration value for the rendered element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | string|UIAwesome\|UIAwesome\| | Text decoration shorthand value (for example, ‘underline wavy red’, TextDecorationLine enum, or null to unset). |
Returns
static: New instance with the updated text-decoration attribute.
textLength()
Section titled “textLength() ”public function textLength(float|int|string|null $value): staticSets the SVG textLength attribute for the element.
Creates a new instance with the specified text length value for the rendered element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | float| | Text length value (for example, ‘100’, ‘50%’, or null to unset). |
Returns
static: New instance with the updated textLength attribute.
title()
Section titled “title() ”public function title(string|Stringable|UnitEnum|null $value): staticSets the title attribute.
Usage example:
$element->title('SVG text');$element->title(null);Parameters
| Parameter | Type | Description |
|---|---|---|
$value | string|Stringable|UnitEnum| | Advisory title text, or null to remove the attribute. |
Returns
static: New instance with the updated title attribute.
transform()
Section titled “transform() ”public function transform(string|null $value): staticSets the SVG transform attribute for the element.
Creates a new instance with the specified transform value for the rendered element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | string| | Transform value (for example, ‘rotate(45)’, ‘scale(2)’, or null to unset). |
Returns
static: New instance with the updated transform attribute.
wordSpacing()
Section titled “wordSpacing() ”public function wordSpacing(float|int|string|null $value): staticSets the SVG word-spacing attribute for the element.
Creates a new instance with the specified word spacing value for the rendered element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | float| | Word spacing value (for example, ‘5’, ‘0.5em’, ‘normal’, or null to unset). |
Returns
static: New instance with the updated word-spacing attribute.
writingMode()
Section titled “writingMode() ”public function writingMode(string|UIAwesome\Html\Svg\Values\WritingMode|null $value): staticSets SVG writing-mode attribute for the element.
Creates a new instance with the specified writing mode value for the rendered element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | string|UIAwesome\| | Writing mode value to set for the element. Accepts ‘horizontal-tb’, ‘vertical-rl’, ‘vertical-lr’, ‘sideways-rl’, ‘sideways-lr’, WritingMode enum, or null to unset. |
Returns
static: New instance with the updated writing-mode attribute.
Throws
InvalidArgumentException: If the provided value is not a validWritingModeenum or string.
public function x(float|int|string|null $value): staticSets the SVG x attribute for the element.
Creates a new instance with the specified x-coordinate value for the rendered element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | float| | X coordinate value (for example, ‘10’, ‘10.3’, ‘50%’, or null to unset). |
Returns
static: New instance with the updated x attribute.
public function y(float|int|string|null $value): staticSets the SVG y attribute for the element.
Creates a new instance with the specified y-coordinate value for the rendered element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | float| | Y coordinate value (for example, ‘20’, ‘10.3’, ‘50%’, or null to unset). |
Returns
static: New instance with the updated y attribute.
getTag()
Section titled “getTag() ”protected function getTag(): BackedEnumReturns the tag enumeration for the <text> element.
Returns
BackedEnum: Tag enumeration instance for <text>. SvgBlock for valid SVG block-level tags.