Short answer. Yes, this condition is legally valid. Article 874 of the Civil Code provides a specific exception: the general rule voiding no-marriage conditions does not apply when the condition is imposed on a widow or widower by the deceased spouse. Your late husband had the legal authority to include that restriction in his will.
What the law says
unless such condition has been imposed on the widow or widower by the deceased spouse, or by the latter's ascendants or descendants
Civil Code, Article 874 — Conditions About Marrying. Read the full provision →
The general rule and the exception
Article 874 starts with a broad rule: an absolute condition not to marry shall be considered as not written. This protects people from having their inheritance tied to surrendering their personal freedom. But the article immediately carves out an exception: the rule does not apply when the condition is imposed on a widow or widower by the deceased spouse, or by the deceased spouse's ascendants or descendants. Because the condition in your husband's will fits squarely within this exception, it is legally valid and enforceable against you.
Why the law permits this exception
The legislature recognised that a different logic applies when the restriction comes from a spouse rather than a parent or sibling. A deceased husband leaving property to his wife, on the condition that she not remarry, is exercising a kind of testamentary autonomy over assets that were part of a shared life. The Civil Code treats this as a permissible arrangement, presumably because the deceased spouse is the source both of the property and of the personal relationship that underlies the condition. It is a narrower category of restriction, and the law treats it differently from a parent controlling a child's marriage choices.
What 'losing' the inheritance actually means
If the condition is valid and you remarry, the consequence is whatever the will specifies — typically forfeiture of the bequest. What happens to the property then depends on the will's other provisions: it may pass to named substitutes, revert to the estate, or be distributed among other heirs. Article 874 does not itself dictate the consequence; it simply confirms the condition is effective. If you are considering remarrying and are unsure of the financial implications, review the specific language of the will to understand exactly what is forfeited and where it goes.
The alternative: rights tied to remaining unmarried
Article 874 also notes that a testator may grant a usufruct, allowance, or personal prestation to any person for the time during which that person remains unmarried or in widowhood. This is a softer version of the same concept: rather than forfeiting an outright gift, a periodic benefit or right of use simply ends upon remarriage. If your husband's will takes this form — granting you a life income or right to reside in a property only while you remain a widow — the same logic applies: the restriction is valid, and the benefit ceases when you remarry.