Forum


Replies: 3   Views: 18
Replacevariable to link

Posted by admin  · 11-03-2026 - 14:10

Hello,

All versions of phpdocx, including the oldest ones, apply the following default inline styles to links:

color: 0000ff
underline: single

These styles (blue color and single underline) match the default styles used by MS Word when a hyperlink is added.

Please note that inline styles can't be overridden using a custom character style (rPr styles have a higher priority). You can set a custom color and underline style with the available options (https://www.phpdocx.com/api-documentation/word-content/insert-link-Word-document-with-PHP) as a link added as regular content:

$docx->addLink('A link', ['url' => 'https://www.phpdocx.com', 'color' => '000000', 'underline' => 'none']);

or in a WordFragment:

$linkFragment = new WordFragment($docx);
$linkFragment->addLink('A link', ['url' => 'https://www.phpdocx.com', 'color' => '000000', 'underline' => 'none']);

Premium licenses also include the stylesReplacementType option in replaceVariableByWordFragment and replaceVariableByHTML methods, which allows placeholder styles to be automatically used and mixed during replacements. We recommend upgrading to Premium to use this option.

Regards.