adverb
for no particular reason; somehow or other; without thinking
Expresses doing something without a clear reason or intention, often with a nuance of absent-mindedness or vague impulse.
何とはなしに空を見上げた。
I looked up at the sky for no particular reason.
何とはなしに彼のことが気になった。
Somehow or other, I found myself thinking about him.
Similar meaning, but 何とはなしに is slightly more literary and emphasizes the lack of a clear reason or intention.
Combination of 何 (what) + と (quotative) + は (topic) + なし (without) + に (adverbial). Literally 'without there being a what', i.e., without a particular reason.