Last Updated : 27 Feb, 2024
The integrity attribute is used to permit the Browser to check the fetched script to ensure the source code is never loaded. It is used to check whether the third party has altered the resource or not.
Subresource Integrity(SRI) is a security feature developed by w3comsortium that is used to permit a Browser to verify all the external scripts that would be fetched. It gives surety that the scripts are not altered by the third party.
The working process of SRI is going to follow the steps:
Syntax
<script integrity="filehash">permit
Attribute Values:
Example 1:
HTML
<!DOCTYPE html>
<html>
<head>
<title>
HTML script integrity Attribute
</title>
</head>
<body style="text-align:center;">
<h1>
GeeksForGeeks
</h1>
<h2>
HTML script integrity Attribute
</h2>
<script id="myGeeks" type="text/javascript"
src="my_script.js"
integrity=
"sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo">
</script>
<br>
<button>Submit</button>
</body>
</html>
Output:
Example 2:
HTML
<!DOCTYPE html>
<html>
<head>
<title>
script tag
</title>
<style>
body {
text-align: center;
}
h1 {
color: green;
}
</style>
</head>
<body>
<h1>GeeksforGeeks</h1>
<h2>
HTML integrity Attribute
in <script> Element
</h2>
<p id="Geeks"></p>
<script charset="UTF-8" integrity=
"e0d123e5f316bef78bfdf5a008837577OOo_2.0.1_LinuxIntel_install.tar.gz">
document.getElementById("Geeks")
.innerHTML = "Hello GeeksforGeeks!";
</script>
</body>
</html>
Output:
Supported Browsers:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4