I have been studying Japanese a few months and consider myself an absolute newbie, so bare with me if this is a really silly question... I do understand the difference between hiragana and katakana, but I sometimes see both mixed in a away that is not very clear to me. Today I saw for example きれい spelled in katakana and I don\t really understand why in this case.. What is the difference between キレイ and きれい, and when should you use one or the other?
As you know, katakana is often used for loanwords, but it does have a few other uses.
Onomatopoeic words (of which there are a lot in Japanese) are often written in katakana.
Some other things are often written in katakana, like the names of animals, e.g. サル - 'monkey'. This is especially true in scientific contexts.
Katakana can be used similar to the way italics are used in English, to emphasise something in text.
Some common words might be written in katakana - I think this feels more conversational (so, among other things, it's natural to use it when you're writing dialogues).
In some contexts (e.g. manga), katakana is used to indicate that the speaker is speaking Japanese, but with an unusual accent.
In graphic design, katakana is 'cool' and hiragana is 'cute', and the designer might decide between the two based only on that.
In the case of キレイ, I'd imagine it's simply because it's a common word (jisho.org actually does list the katakana as another form of the word, so it's probably about the word itself more than the context). You should generally stick with the hiragana in formal writing (it's rarely written in kanji), but the katakana is useful if you want to write in a more conversational tone.