See the following from Add your Desktop and Documents files to iCloud Drive - Apple Support
Store your files in iCloud and save space on your device
The files that you keep in iCloud Drive use your iCloud storage. And as long as you have enough space in iCloud and on your device, you can store as many files as you like. If you need more space on your device, iCloud Drive can help. On your Mac, go to Apple menu > System Preferences > iCloud. Next to iCloud Drive, click Options and turn on Optimize Mac Storage. Then your Mac keeps all of your recent files on your computer, but keeps your older ones only in iCloud, ready for you to download when you need them again. If you want to free up more space on your Mac, follow these steps. On your iPhone, iPad, or iPod touch, you can search and browse files from all of your devices and download them only as you need them.
Note that those instructions are in the Desktop and Documents article but you do not need to turn on the Desktop and Documents option of iCloud Drive in order to turn on Optimize Mac Storage for iCloud Drive.).