Hello,
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 (https://www.phpdocx.com/api-documentation/word-content/add-paragraph-text-Word-document-with-PHP), 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]phpdocx.com 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.
Regards.