From this page of the Valheim guide, you'll learn how to repair damaged items and buildings.
Non-disposable items are subject to wear and tear with every use. The current status of the given item is shown by the bar appearing below its icon. When it goes to zero, the item won't be usable any more. The same applies to buildings, which are damaged with enemy attacks or bad weather.
How to repair items?
The individual items can be repaired at the workbench. For it to be possible, the workbench has to have a roof. To get one, simply place a wall next to it and add roofing.
Now, you have a new interaction with the workbench - a crafting panel will appear on the right. There is a hammer icon next to it - click on it to repair an item. Nevertheless, you need to understand that the game won't allow you to choose the item, and you need to click the icon until the sought object is chosen.
How to repair buildings?
To repair buildings, you need to have a hammer. When you manage to get one, enter the building menu (right mouse button by default) and find the repair option. When the tool is working in that mode, all you have to do is choose the segment to repair and confirm your selection.
Remember that repairing ships and carts is conducted through the same means.