Three names come up constantly, and they do different jobs.
UK GDPR and the Data Protection Act 2018. These cover how you collect, use, store and protect personal data. Personal data includes names, email addresses and also online identifiers, which can include IP addresses and cookie IDs. They require a lawful basis for processing, transparency about what you do, and respect for individual rights such as access and deletion.
PECR, the Privacy and Electronic Communications Regulations. This is the rule that specifically governs cookies and similar technologies, as well as electronic marketing such as email and text messages. Under PECR, you generally need consent before storing or accessing information on a visitor's device, unless it is strictly necessary for the service they requested.
The ICO, the Information Commissioner's Office. The ICO is the UK regulator. It publishes guidance on cookies and consent, and it is the best place to check current expectations. The framework has been subject to reform in recent years, so confirm details on the ICO website rather than relying on any single article, including this one.
In practice, PECR decides whether you need to ask before setting a cookie, and UK GDPR decides what counts as valid consent and what you must tell people about the data you gather.