Yes, 'while' can be used to contrast two things.
While most people are suffering under the cost of living crisis, some people are actually getting richer.
Young people will often happily socialise online while older people generally prefer to meets friends in person.
'While' can be placed at the start or in the middle of the sentence. Note that the while clause is followed by a comma when it begins the sentence.