The Mid 2011 21" iMac has a feature called Target Display Mode. It is no longer supported as of High Sierra, but people are reporting that it still work with the source Mac with Mojave and Catalina.
It will require an expensive adapter that only Apple Makes, the bidirectional TB2/TB3 adapter. Also, a TB1 or TB2 cable.
Here is the bidirectional adapter:
Effortlessly connect your Mac to a Thunderbolt 2 device with the Apple Thunderbolt 3 Adapter. Buy now at apple.com
www.apple.com
Here is Apple's TB cable, but you can use third party cables for this one:
Apple Thunderbolt Cable lets you conduct fast data transfers by connecting Thunderbolt-enabled devices to your Mac. Get fast, free shipping.
www.apple.com
There are plenty of guides on how to do Target Display Mode, but basically once everything is connected, boot up both devices and press and hold "Command" and "F2" on the iMac that you want to use as a display.
I would keep the Mid 2011 on High Sierra which is the highest official MacOS for it, and don't upgrade/patch it to Mojave or above.