Are there best practices for handling CSS formatting based on JavaScript status in PHP?

When needing to handle CSS formatting based on JavaScript status in PHP, one approach is to pass the JavaScript status as a parameter to a PHP function that generates the CSS class dynamically. This way, the CSS formatting can be adjusted based on the JavaScript status without directly mixing JavaScript and CSS code.

<?php
function generateCssClass($jsStatus) {
    if ($jsStatus) {
        return 'active';
    } else {
        return 'inactive';
    }
}

$jsStatus = true; // Set JavaScript status here
$cssClass = generateCssClass($jsStatus);
?>

<div class="<?php echo $cssClass; ?>">
    <!-- Content here -->
</div>