<p>You can use <code>{% js %}</code> Twig tag.
It is essential to using JS in Twig. It takes JS code passed to it and appends it at end of the template, right before ending body tag. Multiple js tags can be used - content from each of them will be concated with the rest. You don't need to wrap code passed to <code>{% js %}</code> into <code>&lt;script&gt;</code> tags - js will do that for you.</p>
<pre><code>{% js %} 
    console.log('Hello World');
    /* you can add your js code here */
{% endjs %}
</code></pre>

CC BY-SA 4.0
2020-12-30T09:28:42.980Z
2020-12-30T09:28:42.980Z
ZealousWeb
<p>Is there any way to add javascript in craft</p>

<craft3><javascript>
How to include Inline JavaScript?
# How to include Inline JavaScript?

(Asked by: username_0 on 2020-12-30)

Is there any way to add javascript in craft

**Tags:** craft3, javascript


---

## 1 answers

### Answer by username_1 on 2020-12-30. Score: 2

You can use `{% js %}` Twig tag.
It is essential to using JS in Twig. It takes JS code passed to it and appends it at end of the template, right before ending body tag. Multiple js tags can be used - content from each of them will be concated with the rest. You don't need to wrap code passed to `{% js %}` into


---

