async
async attribute
The async
attribute in HTML instructs the browser to load and execute a script asynchronously, meaning it won’t block the page from loading.
Syntax
<script src="URL" async>
Example
<script id="el" src="/example.js" async></script>
async
attribute is used in the <script>
tag to indicate that the script should load and execute independently of the page's parsing process. This allows the browser to continue rendering the document without waiting for the script to complete.Values
- The URL or file path of the script.
Applies To
The async
attribute is applicable to the following HTML element:
Example
<script async src="myscript.js"></script>
Conclusion
The async
attribute enhances webpage performance by allowing scripts to load and execute without delaying HTML parsing. When used in the <script>
tag, it prevents scripts from blocking page rendering, resulting in faster page loads. However, since async
scripts execute as soon as they are available, developers should ensure that dependencies are not affected.
anchor
The anchor attribute in HTML links a positioned element to a specific anchor, allowing precise placement relative to another element using CSS anchor positioning. This feature enables dynamic layouts but lacks broad browser support, making it experimental.
charset
The charset attribute in HTML defines the document's character encoding, ensuring proper display of text, especially for non-ASCII characters.