2011 iMacs support Target Display Mode, using Thunderbolt input, but Apple added restrictions on Target Display Mode. No current Macs support using any iMac as a Target Display.
See the bad news here: Use your iMac as a display with target display mode - Apple Support
Even if Apple had not added the restrictions, you would need $80+ in specialized Thunderbolt gear (a $50 Apple Thunderbolt 3-to-2 adapter + a $30+ Thunderbolt 1/2 cable) to use the old iMac as a Target Display. Once iMacs got Thunderbolt, Target Display Mode required Thunderbolt input. It was only the 24" and 27" iMacs from 2009 and 2010 that could accept regular DisplayPort input.
Based on your tag line, it appears that you have a 21.5" iMac with a 1920x1080 pixel display. These days, you can buy
- 24" 1920x1080 pixel displays with poor color accuracy for about $80
- 24" 1920x1080 pixel displays with IPS panels and 100% or near-100% coverage of sRGB for about $150
- 27" 3840x2160 pixel displays with IPS panels and 100% or near-100% coverage of sRGB for as little as $300 to $350.
So even if there weren't restrictions on the video source, the cost of making the connection, versus the value, and age, of that old display, would argue for buying a real standalone monitor.