You're just a witness, you don't even have to wear formal clothing, normal clothing is fine, altough I recommend wearing the kind of clothing you'd wear for a job interview or a business meeting, IE something formal. You just don't want to show up to court shirtless or looking like a bum, or something, and even then the worst that can happen because of that is having people look at you funny and maybe an appropriate comment by the judge.
Just be chill and tell the judge what you know according to what you're asked about. If you really don't remember something, just say you don't remember, better to say that than to risk unintetionaly lying.
Also, remember that the judge is your friend, since he/she is there to make sure you're questioned and treated fairly, after all, you're just a witness. Just follow the judge's lead and he/she should painlessly guide you through it.
All this. Though, if you were the defendant, I'd have some recommendations. Since I've been a defendant before, it would start like this.
NEVER WEAR ORANGE. Judges associate that with criminals. Replace orange with whatever color the uniform of prisoners/jailed-persons in your area/country is. Black and white stripes, for an old-tyme example.
Dress nicely, but not overly nice. Wear a suit and tie, but take the suit jacket off, kind of thing. Makes you seem well mannered, responsible, but also human and relatable.
Wear glasses, even if you aren't needing them. It makes you seem harmless, weak, and in need of allies.
Show emotional responses to disturbing accusations ("The defendant then proceeded to break down their door and assault them!" -gasps in shock, shakes head-)
Basically try to manipulate basic psychology and body language to make yourself appear less convictable, because if you're a defendant, you don't need to think about "Did I do it?" you need to think about "How do I make these people do what I want them to do, which is release me from these charges?"