Which iMac do you have? Retina 4K or non-retina?
iMac (21.5-Inch, 2017) <-- Assuming this one, as the problem would not happen on a Retina display
iMac (Retina 4K, 21.5-Inch, 2017)
First, you should set the display resolution to the default display mode, scaling it may make the situation worse. System Preferences -> Display.
There is an option you can try to change a setting via the Terminal:
(/Applications/Utilities/Terminal) or you can press CMD+Spacebar and search for Terminal to launch it.
Type in the following, be careful to type it precisely and press Return.
defaults write -g CGFontRenderingFontSmoothingDisabled -bool NO
Then shutdown the Mac and restart.
If the result is worse or you do not like it, you can turn it back on:
defaults write -g CGFontRenderingFontSmoothingDisabled -bool YES
Remember to restart the Mac.