you can add your CSS styles in an external file and reference it in the head section of your HTML document using the link tag.
<head>
<link rel="stylesheet" href="path/to/your/styles.css">
</head>
Finally, when rendering the HTML document with DOMPDF, make sure to set the isRemoteEnabled option to true to allow loading of external resources such as CSS files. Here's an example PHP code snippet that shows how to use DOMPDF with CSS styles:
use Dompdf\Dompdf;
// create a new instance of Dompdf
$dompdf = new Dompdf();
// load your HTML content with CSS styles
$html = '<html><head>
//css link
</head><body>Hello, world!</body></html>';
$dompdf->loadHtml($html);
// set the PDF rendering options
$dompdf->setPaper('A4', 'portrait');
// enable remote file access (e.g., to load external CSS files)
$dompdf->setOptions([
'isRemoteEnabled' => true,
]);
// render the PDF document
$dompdf->render();
// output the PDF document to the browser or save it to a file
$dompdf->stream('document.pdf');