- Courses
- HTML
- HTML top level tags
- <style>
- Nonce attribute's role in style security
How does the nonce
attribute enhance security in the <style>
element?
The nonce attribute allows inline styles to be securely applied by using a unique, unpredictable value.
The nonce
attribute is used in conjunction with a Content Security Policy (CSP) to allow inline styles while preventing unauthorized scripts. The server generates a unique nonce value for each request, which must match the nonce in the policy. This ensures that only styles with the correct nonce are executed, enhancing security by preventing cross-site scripting (XSS) attacks.
<style nonce="random123">
p { color: red; }
</style>
More cards6
Show allWhat is the purpose of the
What is the function of the blocking
attribute in the <style>
element?
In the following code, what background color will the paragraph have?
<style>
p { background-color: blue; }
</style>
<style>
p { background-color: yellow; }
</style>
<p>This is my paragraph.</p>