# How to globally change the color of tikz nodes?

I see here:

How to specify a fill color in RGB format in a node in tikzpicture?

It is possible to change the color of a node locally. However, I would like to add a background color globally to all nodes by default. Is that possible?

• Welcome to TeX-SE! Are you looking for something lie \tikzset{nodes={fill=blue}}?
– user121799
Jun 26, 2019 at 16:49
• yes, thanks! almost though. I am looking to do it only for nodes that have a border. is there a way to detect it latex-programmatically in the tikzset? Jun 26, 2019 at 16:54
• It probably is but is a nontrivial enterprise. What is the ultimate goal of all this?
– user121799
Jun 26, 2019 at 16:58

Here is a possible way. Please note that it is generally not recommended to globally set such styles. I do not offer anything of the sort "fill only nodes with a border" since this is too much of a hack, and I do not see why this would be better than defining a style Draw/.style={draw=#1,fill=fillcolor} and use this instead of draw. There is an if named \iftikz@mode@draw, but as you see it has @ inside, which indicates "do not mess with that unless you absolutely need to". So, unless you provide a very good argument why this is preferable to the above Draw there is not much point IMHO to go this route. Anyway, here is how you could globally switch off and on fills.

\documentclass{article}
\usepackage{tikz}
\definecolor{fillcolor}{RGB}{255,51,76}
\begin{document}
\tikzset{nodes={fill=fillcolor}} % switch on global settings

\tikz{\node[draw]{Hello};}

\tikz{\node{World};}

\colorlet{fillcolor}{green}
\tikz{\node{Duck};}

\tikz{\node{Koala};}

\tikzset{every node/.style={}} %switch off global settings

\tikz{\node{Squirrel};}

\end{document}