The referrerpolicy attribute is a small instruction attached to an HTML element. Its job is to control how much referring URL is sent. It is easier to remember when you can see it in a real piece of markup.
What referrerpolicy is used for
Control how much referring URL is sent. The attribute appears inside an element’s opening tag. Depending on its definition, it may take a specific string, a number, an enumerated keyword, or be a boolean attribute.
The example below uses it in a iframe context. Other elements may support it too, or may give the same attribute a different meaning.
Example you can try
<section>
<iframe title="Embedded lesson" src="/lesson-preview" referrerpolicy="strict-origin-when-cross-origin"></iframe>
</section>
How the example works
Look for referrerpolicy in the snippet. Here the example shows the value strict-origin-when-cross-origin. This is a concrete input the browser can interpret; it is not just text shown to the reader.
The effective policy also depends on browser defaults and response-level referrer policies.
Values and important behavior
Common values include no-referrer, same-origin, and strict-origin-when-cross-origin.
This detail matters most when the page receives user input, navigates to another document, or loads an external resource. In those cases, check the browser behavior and any server-side requirements separately.
Small practice task
Copy the code and change referrerpolicy to another sensible value, or remove it entirely if it is optional. Test the difference in the browser and inspect any submitted value or network request.
Common Beginner Mistakes
- The effective policy also depends on browser defaults and response-level referrer policies.
- Using
referrerpolicyon an element that does not support it. - Believing that an HTML hint or client-side check replaces real server validation or a security policy.
Key Takeaways
referrerpolicyis used to control how much referring URL is sent.- The effective policy also depends on browser defaults and response-level referrer policies.
- Choose valid values and test the result instead of guessing what the browser will do.