Web Lucas
Coming back fresh ...
Calendar 07.05.2021

wp_kses() will do the sanitization of html output but keep the html.

While using wp_kses you need to tell it what tags to allow.

Alternatively you can use wp_kses_post() which allows html tags you can add to a post. This one may not be strict enough for most cases so I’d suggest using the first option.

$var = "Here is my html string";

echo wp_kses( $var, array( // array of allowed tags
    'a' => array(
        'href' => array(),
        'title' => array()
    'br' => array(),
    'em' => array(),
    'strong' => array(),
) );

Check the wordpress codex for more info.