Well yes, if you have a mountain bike or a hybrid one, you can still connect a bike basket to it. But, it also depends on the type of basket you are using. Some are detachable, and you can attach them to your handlebars. Contrary, some other baskets that come with straps are also used for a similar purpose. Others require brackets to offer a more sturdy, permanent, and longer-lasting installation. So keep these things in mind before buying a basket for a bike or bicycle.
There is a second option as well; you can buy a bike with a basket in case you do not want to assemble it manually. There are many bikes with baskets available online and you can buy the best one after going through their specs and features.