They can be, but the oral absorption pathways are complicated. You need to be sufficient in other vitamins, I can’t remember which, in order to absorb vitamin D from your food.
Generally it’s recommended that sun > supplements, for a few reasons. But if you can’t get some sunlight supplements are not a bad choice at all.