Hello Usman
Yes, this will function correctly. Since both ports on both switches are access ports, there is no VLAN information sent in the frames that are exchanged. As a result, communication will occur correctly.
It is a good idea however to keep some sort of consistency on the VLANs on all switches within an enterprise network. In the future, you may want to connect those switches using a trunk. You may want to span a particular VLAN across multiple switches. You would not be able to do so unless the VLAN numbers and subnets match correctly. It can be a time consuming exercise to have to change the VLAN numbers and subnets on L3 switches throughout your network in order to get such a configuration to function. It’s best practice to keep these consistent from the beginning..
I hope this has been helpful!
Laz