In Windows 10 you could pin a folder to the taskbar by creating a new Toolbar and placing a shortcut for the folder in that Toolbar, however, Windows 11 deprecated that feature.
There is still a way to pin a folder to the taskbar in Windows 11. You can also pin a file using this method.
1. Right-click or press and hold on to the folder and then click/tap on Show more options > Send to > Desktop (create shortcut).
2. Right-click or press and hold on the folder shortcut on your desktop, then click/tap on Properties.
3. In the Shortcut tab, add the word "explorer" followed by a space, (don't include the quotes) in front of the Target path. Then click/tap on Apply.
4. Click/tap on the Change icon button.
5. Under Look for icons in this file: type imageres.dll and press Enter as in the screenshot below. From the folder icons that appear, select a folder icon that you like, and click/tap on OK.
6. Then, in the folder Properties, click/tap on OK.
7. The icon of the folder's shortcut on your desktop would have changed to the icon you had selected. Right-click or press and hold on the folder shortcut, then click/tap on Show more options > Pin to taskbar, as in the screenshot below.
8. Your folder is now pinned to the taskbar. Just open with a click/tap.
9. Delete the folder shortcut on your desktop.