« Web, HTML, Tech Forum

is it possible to define your own colors in css?

Posted by Motte

posted

Forum: Web, HTML, Tech

i feel crazy but i swear i saw someone do this

i know css has a bunch of pre-defined colors, where you just type color:tomato; and itll automatically know you mean #ff6347, but i thought there was some way to define your own colors? i want to make a few classes that all have the same color text and i know i could just copy/paste it, but i feel like i saw someone somewhere just define their own colors so, say, "my green" was always some specific shade of green not already defined by css alone.


actually now im wondering if i just do body{color:#idfkwhatitwas;} if itll just automatically apply to everything??


Report Topic

2 Replies

Sort Replies:

Reply by rappa

posted
updated

you can! but not exactly in the way you said -- for example from my code I have something like this:


:root {

    --light-blue: #7E868F;

    --darker-blue: #43505D;

    --darkest-blue: #273747; (except I typoed it blye in my code lmao)

    --base-white: #EDEDED;

    --pronoun-blue: #b1b3b4;

    --links: #908857;

}


you'll need to write up a :root section (I did at the top of my <style>) and fill it in with variables like that! to use them you'd type something like:

background: var(--base-white);  or color: var(--darkest-blue);


maybe there's another way to do it but that's what I saw when looking at other people's SpaceHey code


Report Reply

Reply by Motte

posted

this is overdue but THANK YOU!!!! this is exactly what i wanted!!!!!


Report Reply