How to delete cookie in Magento 2?

Magento 2, You can delete the cookie using Magento’s Own Magento\Framework\Stdlib\CookieManagerInterface interface class.

You can delete cookie using deleteCookie() function from CookieManagerInterface Interface.

If you have set the cookie using cookie’s $metadata property, You need to inject Magento\Framework\Stdlib\Cookie\CookieMetadataFactory factory in your class to delete the cookie.

Model class for delete cookie,

<?php
namespace Rbj\DeleteCookie\Model;

class Cookie
{
    /**
     * @var \Magento\Framework\Stdlib\CookieManagerInterface CookieManagerInterface
     */
    private $cookieManager;

    /**
     * @var \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory CookieMetadataFactory
     */
    private $cookieMetadataFactory;

    public function __construct(
        \Magento\Framework\Stdlib\CookieManagerInterface $cookieManager,
        \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory $cookieMetadataFactory
    ) {
        $this->cookieManager = $cookieManager;
        $this->cookieMetadataFactory = $cookieMetadataFactory;
    }

    /** Delete custom Cookie */
    public function deleteCookie()
    {
        if ($this->cookieManager->getCookie('magento2cookie')) {
            $metadata = $this->cookieMetadataFactory->createPublicCookieMetadata();
            $metadata->setPath('/');

            return $this->cookieManager->deleteCookie(
                'magento2cookie',$metadata);
        }
    }
}

In the above function, the cookie name is magento2cookie. first check if a cookie is set, if Yes, delete a cookie with help of cookieMetadataFactory.