We just remodeled our kitchen and the cabinet opening is 35 inches high but newly bought dishwasher is only 31.5 inches. How can I properly install it with the height difference?
Looks like you got about 3.5" to make up. I'd put a couple of 2x4s front to back stacked flat and screwed down where the DW feet go. My wife and I are both tall and when we built our house we decided on a 39" counter height, meaning we had to build up for the range and dishwashers. Worked fine. It also means not having to bend over the dishwasher as far to load and unload it, nice.
So IMHO shim/build up as needed under the DW, I think it would look odd to make up that much space above it.
Every dishwasher I've ever installed has adjustable feet so that you can raise/lower and level it in the opening.
If yours doesn't have that, you'll need to shim under the feet to get it level and to the correct height.
If there isn't enough adjustment in the feet or it takes too many shims, you can also get a spacer for the top of the opening from the cabinet dealer that will help fill the space. Generally, you should be able to get a piece of finished 1x that will match your cabinets exactly.
The installation manual should have the appropriate instructions.