The ~
in LESS is used to interpret the string that follows it as it is. No adaptions has to be made with it. That is because LESS parses the file and can encounter errors if you do the following (simplified example);
.transition2x( @props ) {
transition: @props;
}
.element {
.transition2x(width 2s, height 2s)
}
The intend of the transition2x
is to have a transition of an element to a new dimension in 2 seconds.
However, when parsing the above block in LESS, it will encounter a syntax error. The main culprit is the little ,
in the above. LESS takes that character as a separator for argument, so it thinks that .transition2x
has two arguments. But there is only one expected. So LESS does not know what to do.
A starter in LESS may think "oh, let's see if it gets fixed if we put quotes around it" by
.element {
.transition2x("width 2s, height 2s")
}
But, when parsing LESS, we get as end result the following CSS rule
transition: "width 2s, height 2s";
which is not what we want. It may be a valid CSS (gets parsed) but the animation keyframes aren't built with this. What you get is a sudden hop in dimension without any animation.
That is where the ~
comes into the play. If we add it in front of our quoted string,
.element {
.transition2x(~"width 2s, height 2s")
}
then we are saying LESS "hey fam, I want you to see this literally, don't parse it". The end result of that is
transition: width 2s, height 2s;
which is the right CSS syntax. That adds animation keyframes.
That is what ~
before any string does in LESS: "get this string, don't interpret it and strip its quotes".