You can easily code this in your header.php file and it will work fine but it’s not a good practice to do so. A better option is to use the functions and hooks provided by WordPress. You can add the following code to your functions.php file
add_action( 'wp_enqueue_scripts', 'enqueue_conditional_style' );
function enqueue_conditional_style() {