Per the data released by survey 2021 of Stackoverflow, HTML, CSS and JavaScript are the most popular languages used worldwide.
These three languages are the backbone of the web development; Without these languages, we can not imagine web development.
See the diagram below.
Let’s start with each language and learn some basics about them.
HTML stands for Hyper Text Markup Language, in which most websites are written.
Here –
Hyper Text:- Where Hypertext refers to how documents (HTML documents) are linked together, the links available on a webpage are called Hypertext.
These links allow the reader to jump to other places in the document or to another document altogether.
Markup Language:- As HTML is a “mark-up” language, we use “mark-up” to represent text. This “mark-up” is processed by computer and presented to you.
For example:-
<h1>This is the Heading.</h1>
Here <h1> is the tag and Tags are used to “markup” the text.
Current version of HTML is HTML5.
HTML can be written in any text editor and we can save that file as example.html.
But the most preferable and widely used text editor is VS Code.
Microsoft build VS Code with many features like syntax highlighting, autocomplete, debugging, etc.
See the image of the complete features of VS Code.
There are so many online editors which are very helpful to write the code without setting any environment.
Let’s make a simple webpage using HTML so we can study some basics of it.
We will follow the below steps to make our webpage.
Step 1:-
Open VS Code, create a new file and save it as index.html.
Step 2:-
In this, we will write our HTML code.
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h1>My Heading</h1>
<p>My paragraph.</p>
</body>
</html>
Step 3:-
Run the code output will be a web page with a title, heading and paragraph.
See the image below to understand it more –
Congratulations 🎉 you have made your first web page.
Let’s discuss more about the above HTML code :-
An Attributes contain additional information about tags.
for example <h1 class=”blue”>My Heading<h1>, The “class” is an attribute and “blue” is the value of that attribute.
The HTML style attribute is used to add styles to an element.
Styles can be color, font, border, size and more.
For example :-
<tagname style="property:value;"></tagname>
Color property of HTML changes the color of the fonts.
Example :-
We can represents color either by color names, or with RGB, HEX, HSL, RGBA, or HSLA values.
We can adjust/change the size of HTML text by using font-size property of HTML.
For Example :-
<p style="font-size: 20px;">This is the paragraph.</p>
In the above example the HTML set the font-size of the paragraph element to 20px.
Mostly used units for HTML font-size are px, rem, em and %.
We can write any number of properties into the style attribute of the HTML.
For Example :-
<div class="color: blue; font-size: 30px; text-align:center;">I am a div.</div>
In the above example we have applied three properties to the div element of the HTML.
This is also called Inline style.
The lengthy inline style has some disadvantages like they make HTML code messy.
To avoid the disadvantage of inline style, we can make a separate styles in the style element inside the <head> element of HTML.
For Example :-
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
color: blue;
text-align: center;
}
p {
font-family: verdana;
font-size: 20px;
}
</style>
<head>
<body>
<h1>My Heading.</h1>
<p>My Paragraph.</p>
</body>
</html>
Now we have slowly moved to CSS.
We can write and link CSS in three different ways, Those are
By using the Style attribute inside the HTML element.
<h1 style="color: blue;">Heading</h1>
By using <style> tag inside the <head> tag.
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
color: blue;
}
</style>
<head>
<body>
<h1>Heading</h1>
</body>
</html>
By using the <link> element inside the <head> element.
The <link> element link the external CSS file to our current HTML document.
The rel attribute specifies the relationship between the current document and the linked document.
<!DOCTYPE html>
<html>
<head>
<title>My Document</title>
<link rel="stylesheet" href="style.css">
<head>
<body>
<h1>Heading</h1>
</body>
</html>
Let’s learn more about HTML and CSS by doing a Project, we will make a Navbar section of a website design.
This project is the combination of a Navbar and Hero section of the website.Using these two section we will learn the following properties-
A Navbar of a website generally consists of a logo (may be text or image) and different links of a website.
We have a semantic element for Navbar i.e <nav>.
Let’s write the structure of navbar using HTML.
<nav>
<div class="logo">
<a href="#">logo</a>
</div>
<ul>
<li><a href="#">home</a></li>
<li><a href="#">projects</a></li>
<li><a href="#">about</a></li>
<li><a href="#">contact us</a></li>
</ul>
</nav>
Step 1:-
In the first step, we will do some basic resettings. we do basic resettings so that the default properties set by HTML can be removed. Like HTML default padding or margin set to 0.
The CSS for basic resettings –
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
The Box Model :-
The Box model define our layout and design.
See the below image for the reference.
Different parts of the box model are –
Total width of the element is calculated as –
Total element width = width + left padding + right padding + left border + right border + left margin + right margin.
Step 2:-
In this step, we will add styles to our nav element.
nav {
max-width: 1000px;
margin: auto;
display: flex;
justify-content: space-between;
align-items: center;
padding: 8px 16px;
}
Let’s discuss the properties from above code snippet.
1. The max-width :-
The max-width property specifies the maximum width of the element. If an element has smaller width than the max-width then the max-width property has no effect.
If the max-width is less than the width of the element than it automatically change the height of the element.
2. The flex property :-
One of the most important property of CSS is the flexbox.
It makes complex layouts look simpler and it is very useful property for responsive web design.
Let’s learn some of the flex properties using images.
3. Margin and Padding :-
margin: auto – means that the browser calculates the margin.
padding: 8px 16px; – top-bottom padding is 8px and right-left padding 16px.
4. HTML lists and link tags :-
To make the nav link, we will make use of the unordered list of the HTML.
HTML is having two types of list –
1. Unordered List :-
An unordered list starts with the <ul> tag. Each list starts with <li> tag.
For Example :-
<ul>
<li>Eat</li>
<li>Sleep</li>
<li>Code</li>
<li>Exercise</li>
<li>Repeat</li>
</ul>
2. Ordered List :-
An ordered list starts with <ol>tag. Each list starts with <li> tag.
For Example :-
<ol>
<li>Eat</li>
<li>Sleep</li>
<li>Code</li>
<li>Exercise</li>
<li>Repeat</li>
</ol>
Let’s write the CSS for the nav bar.
/* CSS */
ul{
list-style-type: none;
display: flex;
}
li:not(:last-child){
margin-right: 10px
}
a{
text-decoration: none;
color: black;
text-transform: uppercase;
}
We have learned HTML and CSS.
1. Choosing Random name from the list of names :-
This code snippets will choose the random name, which will be helpful in situations like lucky draw.
HTML
<p id="output"></p>
JavaScript
let x = document.getElementById('output');
let names = ["John", "Smith", "Warner", "Cummins"];
let rand = Math.floor((Math.random() * names.length));
x.innerText = names[rand];
➞ If you run the above program then output will be different every time.
2. Changing the Image on click of a button :-
➞ The below program changes the Image on the click of a button.
<img src="https://images.pexels.com/photos/15286/pexels-photo.jpg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=2" alt="" id="img">
<button onclick="document.getElementById('img').src='https://images.pexels.com/photos/572897/pexels-photo-572897.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=2'">Click</button>
We have seen the two practical examples of JavaScript.
Now let’s make a quick summary of the main differences between HTML, CSS and JavaScript.