HTML Basics Grade X Handout
HTML Basics Grade X Handout
UNIT 1
HTML
HTML is hypertext markup language.It is used to write codes that make up a webpage.HTML uses
tags to build a web page such as images, text, tables etc.
CSS handles the look and feel part of a web page. Using CSS, you can control the color of the text,
the style of fonts, the spacing between paragraphs, how columns are sized and laid out, what
background images or colors are used, layout designs, variations in display for different devices and
screen sizes as well as a variety of other effects.
JavaScript
JavaScript is used to write programs that interact with other computers and web pages, and access
codes.
What Is HTML?
If you want to build a website, the first language that you need to learn is HTML.HTML, which
stands for Hypertext Markup Language, is a pretty simple language. It consists of different elements
which we use to structure a web page.
The element usually starts with an opening tag, which consists of the name of the element. It's
wrapped in opening and closing angle brackets. The opening tag indicates where the element begins.
Similar to the opening tag, the closing tag is also wrapped in opening and closing angle brackets. But
it also includes a forward slash before the element's name.
For example, the <img> element is used to embed an image file, or the <input> element is used to
insert an input onto the page.
In the example above, the <img> element only consists of one tag that does not have any content. This
element is used to insert an image file from “Unsplash” in the document.
Elements also have attributes, which contain extra information about the element that will not appear
in the content.
In the example above, the <img> element has 2 attributes: src or source to specify the path of the
image, and width to specify the width of the image in pixels.
With this example, you can see the following characteristics of attributes:
Section elements
These elements are used to organize the content into different sections. They are usually
self-explanatory, for example, <header> usually represents a group of the introduction and navigation
section, <nav> represents the section that contains navigation links, and so on.
Text content
First, let's open Visual Studio Code (or your favorite code editor). In the folder of your choice, create
a new file and name it index.html.
In the index.html file, type ! (exclamation mark) and press enter. You will see something like this:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
</body>
</html>
This is the minimal code that an HTML document should have to make up a website. And here we
have:
<!DOCTYPE html>: First we have Doctype. For some weird historical reason in HTML we have to
include the doctype for everything to work correctly.
<html lang="en"></html>: The <html> element wraps all the content on the page, also known as the
root element. And we should always include the lang attribute to declare the language of the page.
<head></head>: The <head> element is a container for everything you want to include, but not
content that you show to your users.
<meta charset="UTF-8" />: The first meta element is used to set the character set to be UTF-8, which
includes most characters from written languages.
<body></body>: The <body> element contains all the content on the page.
HTML Headings
Code:
Output
HTML Paragraphs
A paragraph always starts on a new line, and browsers automatically add some white space (a margin)
before and after a paragraph.
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
The <div> element is by default a block element, meaning that it takes all available width, and comes
with line breaks before and after.
The <div> element is often used to group sections of a web page together.
<div>
<h2>India</h2>
<p>Delhi is the capital city of India.</p>
<p>Delhi has over 20 million inhabitants.</p>
</div>
HTML Images
code:
HTML Lists
HTML lists come in three main categories: unordered lists, ordered lists, and definition lists. Each
type serves a specific purpose
Unordered lists
Unordered lists are perfect for presenting items that do not have a particular sequence or order. They
are typically displayed with bullet points, which make them visually distinct from ordered lists. An
example might be a grocery shopping list.To create an unordered list, you can use the <ul> (unordered
list) element and nest individual list items within <li> (list item) elements:
Code:
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
Output:
● Item 1
● Item 2
● Item 3
Ordered lists
Ordered lists, as the name suggests, are useful when you want to present items in a specific sequence
or order. They are displayed with numbers or letters by default, but you can customize the numbering
style using CSS. An example might be a ranked list of your favorite movies.
To create an ordered list, use the <ol> (ordered list) element and nest list items within <li> elements:
Code:
<ol>
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
</ol>
Output:
This code will produce an ordered list like this:
1. First item
2. Second item
3. Third item
Ordered lists are useful for creating step-by-step instructions, ranking items, or any situation where a
specific order matters.
Code:
<dl>
<dt>HTML</dt>
<dd>HyperText Markup Language, used for structuring content on the web.</dd>
<dt>CSS</dt>
<dd>Cascading Style Sheets, used for styling web documents.</dd>
<dt>JavaScript</dt>
<dd>A programming language used for adding interactivity to web pages.</dd>
</dl>
Output:
HTML
HyperText Markup Language, used for structuring content on the web.
CSS
Cascading Style Sheets, used for styling web documents.
JavaScript
A programming language used for adding interactivity to web pages.
Definition lists are particularly handy for glossaries and dictionaries, where you need to pair terms
with their meanings.
Using HTML tags like <head>, <body>, and so on can help you organize your web page content
nicely, but only up to a point.
HTML-only pages can be pleasant and easy to read – which is hugely important – but, after a while,
they all do tend to look the same.
Cascading style sheets, known universally as CSS, aren't really sheets, and it can take some work to
figure out what "cascading" means. But the markup standard adds real power to your web
development work. Let's look at some of that CSS magic in action.
Code:
<link rel="stylesheet" href="/main.css">
That example uses the stylesheet attribute to point to a CSS file called main.css that's in the web root
directory on its server.
Alternatively, you can add it between <style> tags within the <head> section of your HTML. That'll
look something like this:
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
p{
color: red;
text-align: center;
}
/* This is formatting for bullet points: */
ul {
color: blue;
text-align: left;
}
</style>
</head>
When you look at the above code, you'll see that there are two style definitions within the curly
braces: the text color should be red, and the text alignment should be centered:
<style>
p{
color: red;
text-align: center; }
Notice how each definition ends with a semicolon. That's really important and leaving those out will
break stuff. Also notice how we can refer to colors by name. We'll see more examples of that later, but
be aware that you can also identify colors by their hexadecimal codes. The hexadecimal code for an
attractive shade of red could be #F5733.
In general, of course, you want this kind of note to make your code more readable and understandable.
But I added it here specifically to show you how commenting works in CSS, using a forward slash
and an asterisk at the start, and an asterisk and forward slash at the end. HTML-style comments won't
work here.
This next style will apply to any unordered list within your HTML, using blue as the text color and
aligning text to the left.
ul {
color: blue;
text-align: left;
}
</style>
There's a lot more you can do here and, of course, you can apply styles to all kinds of HTML
elements. But we've got to start somewhere, right?
The actual HTML is further down in the <body> section. To show you how our CSS will work, I've
written some text within a regular paragraph, and a couple of bullet points between <ul> tags.
<body>
<h2>Basic CSS</h2>
<p>This text exists within a regular paragraph.</p>
<ul>
<li>This is a bullet point
<li>This is another bullet point
</ul>
</body>
</html>
Now pop that code into a text file with a .html file extension and open it up in a browser. The colors
and the alignment should reflect our preferences.
HTML Forms
Forms are a fundamental part of web development, allowing users to input and submit data efficiently.
Creating forms in HTML is a relatively straightforward process. In this article, we'll explore how to
build basic forms using HTML <form>, <input>, and <button> elements. We'll also cover various
input types such as text, password, radio buttons, checkboxes, and submit buttons.
Code:
<form>
<!-- Form elements will go here -->
</form>
Text Input
Text input fields are used for collecting single-line text data, such as a name or email address. You can
create a text input field using the <input> element with the type attribute set to "text.
Code:
<label for="name">Name:</label>
<input type="text" id="name" name="name" placeholder="Enter your name">
In this code snippet, the for attribute in the <label> element associates the label with the input field,
making it more accessible and user-friendly.
Password Input
Password input fields are like text inputs, but the entered characters are hidden as dots or asterisks for
security.
Code:
<label for="password">Password:</label>
<input type="password" id="password" name="password" placeholder="Enter your password">
Radio Buttons
Radio buttons are used when you want users to select one option from a list. Each option is
represented by a radio button.
To create radio buttons, use the <input> element with the type attribute set to "radio."
<form>
</form>
In this example, using the same name attribute for both radio buttons groups them together, allowing
the user to select one option.
Checkboxes
Checkboxes are used when you want users to select one or more options from a list. Each option is
represented by a checkbox.
To create checkboxes, use the <input> element with the type attribute set to "checkbox."
<label>Interests:</label>
<input type="checkbox" id="music" name="interest" value="music">
<label for="music">Music</label>
With checkboxes, users can select multiple options based on their preferences.
Submit Button
A submit button is used to send the form data to the server for processing. You can create a submit
button using the <button> element with the type attribute set to "submit."
<button type="submit">Submit</button>
This button triggers the form's submission when clicked.