When I close the lid of my notebook it becomes black.
How exactly does a modern notebook recognize when the screen is being closed?
Are there magnets?
There is no single answer. Magnets are a common one, but there can also be switches near the hinge. (There may be other mechanisms as well - For example it could also use a light sensor)
The preferred detection method for older laptops was a physical, mechanical switch placed near the hinges or the top of the display. Once the lid closes, the controller would signal the operating system to initiate the configured power setting, whether sleep, hibernate, shut down or do nothing.
Newer laptops use magnets and hall effect sensors to detect every time the display is closed. The sensor typically gets engaged when the lid is closed, turning off the internal LCD. The sensor then moves the display output to the external monitor if present or puts the laptop to sleep or hibernation.
Source: How Does the Laptop Know the Lid Is Closed? (Explained for Beginners) - Pigtou
That will depend on the manufacturer. The easiest way to find the exact location is to use something small that will be attracted to the magnet, for example a metal paper clip. (1)
(1) Note that computers/laptops may in addition contain multiple other magnets, inside HDDs and speakers.
See Also: hardware failure - Nearby electronic devices turn off laptop's display - Super User