A modifier wraps a function body, which runs where `_;` appears. They are ideal for access control and state guards, and keep the check in one auditable place.
modifier onlyOwner() {
require(msg.sender == owner, "not owner");
_;
}
function setRate(uint256 r) external onlyOwner { rate = r; }Keep modifiers small: complex logic hidden in a modifier is easy to misread during review.