Replies: 1   Views: 823
Use highlight instead of background color
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by admin  · 15-10-2021 - 06:23


A shading color can be added using the backgroundColor option available in addText:

$paragraphOptions = array(
    'backgroundColor' => 'FF0000'
$docx->addText('Lorem ipsum.', $paragraphOptions);

A highlight color can be added using the highlightColor option:

$paragraphOptions = array(
    'highlightColor' => 'red'
$docx->addText('Lorem ipsum.', $paragraphOptions);

Please note, as explained on the API doc page (, that backgroundColor (shading color) can be a HEX value, but highlightColor is limited to specific color values (MS Word only supports the following highlight colors: black, blue, cyan, green, magenta, red, yellow, white, darkBlue, darkCyan, darkGreen, darkMagenta, darkRed, darkYellow, darkGray, lightGray, none).

If you are using HTML methods:

$docx->embedHTML('<p style="background-color: #FF0000;">Lorem ipsum.</p>');

$docx->embedHTML('<p><span style="background-color: #FF0000;">Lorem ipsum.</span></p>');

phpdocx always adds a shading style, not a highlight style.

UPDATE: phpdocx 12.5 added the data-highlight style to apply a highlight style when importing HTML in Premium licenses (HTML Extended and CSS Extended features).

Also note that you can use the searchAndHighlight method to highlight specific keywords in a DOCX.

If you are transforming HTML to DOCX and you need to add highlight styles (instead of or in addition to the default shading styles), please send an email to contact[at] with the most simple sample that illustrates your case and we'll check it. Maybe HTML Extended can include a new specific extended style to accomplish your needs.