`esc_url()` is a function in WordPress that is used for sanitizing and validating URLs(Uniform Resource Locator) to ensure that they are safe and valid to be used in HTML or database queries.
The function take 3 parameter ($url, $protocals, $_context) return string which is cleaned URl after the ‘clean_url’ filter is applied.
The main purpose of using `esc_url()` is to prevent ant malicious input in the URL that could potentially harm the website or it’s users. It sanitizes the URLs by removing any characters or code that are not allowed in a URL by checking if it is a valid URL according to the syntax rules defined by the Internet Engineering Task Force(IETF).
Simple Example would in search form action attribute.
<form method="get" action="<?php echo esc_url(site_url('/')); ?>">
<input type="search" name="s">
<input type="submit" value="search">
</form>