Simple HTML and JavaScript Example Tutorial For Beginners

Jumping into the world of web development can seem daunting at first, but with HTML (HyperText Markup Language) and JavaScript, you'll be well on your way to creating dynamic and interactive webpages. Let's start with some simple examples to get you going.

HTML input types
HTML input types

HTML is the backbone of webpages, used to structure and describe the content. JavaScript, on the other hand, adds interactivity and dynamic elements. Together, they form a powerful duo for web development.

HTML,CSS JAVASCRIPT cheatsheet
HTML,CSS JAVASCRIPT cheatsheet

Setting Up Our First HTML Page

First, let's create a simple HTML file. Open a text editor, write the following, and save the file with a .html extension – let's call it 'index.html'.

login form html css
login form html css

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My First Webpage</title>
</head>
<body>
</body>
</html>

Adding Basic Content

the different types of web pages are shown
the different types of web pages are shown

Now, let's add some content to our page. Between the <body> tags, add a heading and a paragraph:

<h1>Welcome to My First Webpage!</h1>
<p>This is my first webpage created with HTML. I'm excited to learn more!</p>

Save your file and open it in a web browser. You should see your heading and paragraph displayed on the page.

Update HTML in DOM: Change Text Live
Update HTML in DOM: Change Text Live

Using Headings and Paragraphs

HTML offers six levels of headings, from <h1> (largest) to <h6> (smallest), and the <p> tag for creating paragraphs. Here's an example of using them:

<h1>Headings in Action</h1>
<h2>Subheading</h2>
<h3>Sub-subheading</h3>
<p>Paragraphs can have many lines. Here's a longer one to demonstrate.</p>

Animation Login Form | Html&Css.
Animation Login Form | Html&Css.

Introducing JavaScript

JavaScript brings interactivity to our webpages. Let's add a simple script to alert a message.

How To Create Autocomplete In Pure Javascript
How To Create Autocomplete In Pure Javascript
Website cupcake design using html and css.mp4
Website cupcake design using html and css.mp4
Create Lists From JSON Data in Javascript (Simple Examples)
Create Lists From JSON Data in Javascript (Simple Examples)
html css download button animation
html css download button animation
How To Create Rainbow Text Using CSS JS
How To Create Rainbow Text Using CSS JS
Embedding Images in HTML using <img>
Embedding Images in HTML using <img>
Création d'un site CV monopage responsive en HTML et CSS - Pierre Giraud
Création d'un site CV monopage responsive en HTML et CSS - Pierre Giraud
the cover of 52 html and css project ideas save this for later
the cover of 52 html and css project ideas save this for later
Blinking Text & Background With HTML CSS
Blinking Text & Background With HTML CSS
Simple Fade Animation In HTML CSS
Simple Fade Animation In HTML CSS
Fullscreen Spinner With Pure HTML CSS
Fullscreen Spinner With Pure HTML CSS
CSV To HTML Table In Javascript
CSV To HTML Table In Javascript
📘 JavaScript Basics| Linking JS File to HTML | Chapter 2 📖 Part 2
📘 JavaScript Basics| Linking JS File to HTML | Chapter 2 📖 Part 2
login and register form in HTML CSS #webdevelopment #software
login and register form in HTML CSS #webdevelopment #software
Position Text Over Image In HTML CSS (Simple Examples)
Position Text Over Image In HTML CSS (Simple Examples)
an image of a computer screen with text
an image of a computer screen with text
#CSS Animations Tips and Tricks
#CSS Animations Tips and Tricks
an image of the back side of a computer screen with text that reads, add css to html
an image of the back side of a computer screen with text that reads, add css to html
Your First Step Into Web Development
Your First Step Into Web Development
an image of a web page with the words'body'and'reader '
an image of a web page with the words'body'and'reader '

Add the following between the <head> and </head> tags of our 'index.html':

<script>
<!--
alert('Hello from JavaScript!');
//-->
</script>

Refresh your webpage. You should now see a pop-up message saying 'Hello from JavaScript!' when the page loads. This is a simple JavaScript alert.

Adding an Interactive Button

Let's make our page more interactive by adding a button that, when clicked, displays a message.

Insert the following HTML and JavaScript code into your 'index.html' file:

<button id="myButton>Click me</button>
<script>
document.getElementById('myButton').onclick = function() {
  <script>alert('You clicked the button!');
</script>
};
</script>

The button is now interactive, displaying an alert message when clicked.

Changing HTML with JavaScript

JavaScript can also modify the HTML content. Let's change the heading text using a button click.

Update your code with the following:

<h1 id="heading">Original Heading</h1>
<button onclick="document.getElementById('heading').innerHTML = 'New Heading from JavaScript';">Change Heading</button>

When you click the button, the heading text changes to 'New Heading from JavaScript'.

These simple examples have barely scratched the surface of what's possible with HTML and JavaScript. The journey ahead is exciting and filled with endless possibilities.

Related Articles

What Is Responsive Web Design And Why Is It Important Https Www Tutorialspoint Com Microsoft Html Help Workshop Tutorial Html Tutorial For Beginners In Amharic Html Tags And Attributes List With Examples Html To Zip Converter Free Filetype Pdf Tutorial Convert Html To Zip File Html Tutorial In Amharic Pdf Thenewboston Css