How do I automate what’s selected on my navbar?

So, I have different elements on the navigation menu selected depending on what page a visitor is on. For example, on the home page, the nav looks like this:

but on the Try it free page, it should look like this:

i’m using CSS to do the selected effect.

However, I want to have a common header.php file across all my pages; how do I automate what navigation element is selected based on what page the user is on with one common header, without having to manually change it for each page?