We are given the ratio of boys to girls in Mrs. Xavier's class as 2 to 3. This means that for every 2 boys, there are 3 girls.
Given that there are 18 girls in the class, we can use the ratio to find the number of boys.
Let’s denote the number of boys as \( b \) and the number of girls as \( g \).
The ratio of boys to girls can be expressed mathematically as:
\[ \frac{b}{g} = \frac{2}{3} \]
Since we know there are 18 girls in the class, we can set \( g = 18 \). Substituting this into the equation gives:
\[ \frac{b}{18} = \frac{2}{3} \]
To find \( b \), we can cross-multiply:
\[ 3b = 2 \times 18 \] \[ 3b = 36 \]
Now, dividing both sides by 3, we find:
\[ b = \frac{36}{3} = 12 \]
So there are 12 boys in the class.
To find the total number of students in Mrs. Xavier's class, we add the number of boys and girls:
\[ \text{Total number of students} = b + g = 12 + 18 = 30 \]
Thus, the total number of students in Mrs. Xavier's class is
\[ \boxed{30}. \]