This question is the subject of a vast amount of philosophical inquiry which includes idealist views, realist views, and everything in between.
Since Kant has been mentioned by other users, and your question is about the idealist view, I thought I’d tempt fate by attempting to summarize Kant’s “idealist” position - if nothing else, it will be helpful to me.
For Kant, space and time are not “things in themselves”; they are “forms of experience”. This is to distinguish between what we experience and the nature of experience - i.e., what we find in our experience and the nature of our experience. Another way of saying this is that we do not experience things in time and space, rather we experience things spatially and temporally. Note the noun/adverb distinction.
At this point, it is probably safer for me to continue by directly quoting a professional philosopher, Adrian Bardon :
Just like Parmenides and Augustine, Kant concludes that reality itself is atemporal. Is such a thing (i.e., the atemporality reality) even thinkable? Yes and no, Kant would say. His theory explains imagination’s inevitable failure in this regard: Because this way of experiencing things is an irreducible part of our sensibility, we literally cannot imagine any other way for things to be. Yet we can intellectually come to terms with the ideality of time. In this way the ideality of time is like the mathematical concept of infinity : We cannot imagine the infinite (we cannot call up a mental image of, say, an infinite number of apples), but we can understand what it means. Kant thinks that an atemporal reality is something we can grasp in the abstract, even if it can never mean anything to us in practical terms.
As Bardon notes, Kant has been roundly criticized for this view.
Bardon summarises Kant’s position as follows :
Just as space and time are forms of sensibility, the concepts of substance and cause are just rules for organizing experiences in time and space. The idea of temporal succession is innately present in our cognitive make-up, via a set of organizing principles. Thinking in terms of temporal succession of experiences depends on relating those experiences to successions of events outside us; and we can only do that because we already have a certain schema built in for interpreting our sensory inputs in these terms. Part of our innate information-processing scheme is that we interpret our perceptions on the presumption that we are dealing with a world of enduring items and events, interconnected by causal relations.... We are guided by this scheme into imposing a pattern on experience consistent with such a world; this scheme involves sequences of events occurring in accordance with causal rules. So this is how we come to have the idea of succession: It is a pattern corresponding to the concept of objectivity itself that we ourselves impose on sense data to make them tell a coherent story.