An infant learns to recognize their parents within their first few months of life by sight, sound, and smell. And until they're about 6 months old, babies usually seem interested in other adults as well and may sometimes engage with them in fun games or cooing and laughing.
After 6 months, some children undergo a period of what's called stranger anxiety, where they feel unhappy and frightened around any adult except for their parents. For instance, the child may burst into tears or shrieking if someone they're unfamiliar with makes eye contact or holds them.
Parents should know that stranger anxiety is a normal part of a child's cognitive development. Children can have stranger anxiety feelings until they're 2 years old. Separation anxiety, another normal behavior, also develops during this period.
Both of these stages, stranger anxiety and separation anxiety, happen because your baby is reaching a stage of cognitive development where they can recognize faces other than their parents'. Naturally, children have a strong preference for faces they recognize, and if they're in a situation where they can't see or be with you, developmentally they think you're not around (even though you're nearby), which results in crying and becoming upset.
It's important to know that stranger anxiety and separation anxiety are not an indicator of emotional problems but rather of typical mental development.