Skip to content

Try our new Crash Courses!

Buy one of our new Crash Courses, now hosted on Teachable.

Inline script – JavaScript


To create an inline script, place your JavaScript code directly inside a script element:

  console.log("Test message");


When writing JavaScript, you have the option of placing JavaScript code directly inside a script element in an HTML file. Please note, however, that this is generally not recommended. Inline scripts are acceptable for quick testing of JavaScript code, but the best practice is to store your JavaScript code in a separate JavaScript file.

Note that you do not need the src attribute when creating an inline script.


inline script demo


Try recreating the code snippet from the lesson in the index.html file.


The Script element on MDN

Back to: JavaScript Reference > JS Introduction