5. Let real numbers $a, b$ satisfy $|a| \leqslant 1,|a+b| \leqslant 1$. Then the range of $(a+1)(b+1)$ is $(\quad)$.
(A) $\left[0, \frac{9}{4}\right]$
(B) $\left[-2, \frac{9}{4}\right]$
(C) $[0,2]$
(D) $[-2,2]$
5. B.

Let $t=a+b$. Then
$$
|t| \leqslant 1 \text {, }
$$

and $(a+1)(b+1)=(a+1)(t-a+1)$ is a linear function of $t$, with the coefficient of the linear term $a+1 \geqslant 0$.

Thus, its maximum and minimum values are attained when $t=1$ and $t=-1$, respectively.

When $t=1$, the original expression is $(a+1)(2-a)$, and its maximum value is attained when $a=\frac{1}{2}$, which is $\frac{9}{4}$.

When $t=-1$, the original expression is $(a+1)(-a)$, and its minimum value is attained when $a=1$, which is -2.
Therefore, the required range of values is $\left[-2, \frac{9}{4}\right]$.