1.notes - Intro To HTML-696
1.notes - Intro To HTML-696
1.notes - Intro To HTML-696
What is HTML?
HTML is the most basic building foundation of any web page. Follow along with this guide
to get started.
● HTML is the HyperText Markup Language.
● HTML is used to create an overall website structure.
● HTML is used to provide content (words, images, audio, video, etc.) to web pages.
● HTML is a language based on tags. They are defined in the angle brackets.
● A text editor such as Visual Studio Code, Sublime, or ATOM can be used to create
an HTML file.
● You can download sublime text editor from here: https://www.sublimetext.com/3
Create a file in any text editor like Visual Studio Code and ATOM, and type the above code
and save it as a .html file.
Comments in HTML
You can write a comment by placing the comment text between <! > tags.
For example:
Comments can’t be nested, which means a comment can’t be put inside another
comment.
TAGS
Tags are used to represent HTML elements. These can be seen as keywords that define how
a web browser will format and display the website content.
● Tags define all document elements, i.e. they give meaning to the plain HTML text.
● Two characters < and > surround HTML tags (They are called angle brackets).
● The name of the tag can either begin with an alphabet or an underscore(_).
● The element contents are displayed between the start and end tags
● Tags that have an opening and closing can have any number of tags within them.
● The <H1> and <h1> tags in HTML have the same meaning, i.e. tags are not case
sensitive.
● The HTML tags are usually available in pairs, i.e. opening and closing (it's the
same, with the tag name '/' at the beginning) tag.
Eg: <html> and </html> is a tag that comes in pairs and <hr> does not have a closing
tag.
NOTE: There are also "self-closing" tags, whereby a br tag, for eg., will look like "<br/>"
instead of simply "<br>".
Tag Description
1 <!DOCTYPE html> Specifies that HTML version 5 is used to create the web page
2 <html> </html> Root container for all other HTML elements of the web page
(including the head tag)s
3 <head> </head> Contains information related to the website and is not shown in
the browser
4 <title> </title> Provides the title of the document and is displayed in the tab in
the browser
EXTRA:
To get the list of all valid tags in HTML5, visit:
https://developer.mozilla.org/en-US/docs/Web/HTML/Element
These can be explored whenever required while making a website.
DOCTYPE
The DOCTYPE declaration specifies the HTML version used to create the page.
It's the first thing you see on every web page when you open your HTML document.
The declaration of doctype is not an HTML tag. It's the one HTML5 recommends.
The basic elements used till now have been briefly described below
Paragraphs
Paragraphs are blocks of text separated from each other by some space.
They are defined using the <p> and </p> tags. When the p element ends, the next element
appears in the next line.
Eg: here's a sample of code for <p> tag:
It appears on a web browser like this:
NOTE: When formatting without a p-tag, new lines are appended on the current
line. This happens because the spacing of text doesn’t matter to the browser.
Headings
These are HTML tags that are used to indicate that some content should be treated as
headings. The headings are divided into six levels: h1, h2, h3, h4, h5, and h6. among
them, h1 is the highest level heading and h6 is the lowest-level heading.
<br> tag can be used to make a single line split between the contents of the tab. This
means that when this tag is used between a single line, the contents after this tag will
pass to the next line. Do not use it to allow space between a block of elements ( eg.,
paragraph and heading).
Eg.,
LISTS
Lists are used to group different pieces of information together so that they are easily
linked and easy to read.
Lists help construct a well-structured, more open, and easy-to-maintain document from a
structural standpoint.
There are three types of lists to pick from: ordered, unordered, and description lists.
Unordered Lists
It's used to group a group of similar objects that aren't arranged in any specific order.
Where the counting of objects isn't necessary, unordered lists are used.
Bullets are used by default to separate the items.
HTML provides an interesting feature to change the style of the list item marker.
There are 4 types of styles in unordered lists:
Ordered Lists
When the numbering of items is necessary, ordered lists are used. By default, numerical
numbers follow the items.
Similarly, like the unordered lists, there are also different types of ways to number the
ordered lists using the 'type' attribute:
Now, what if you want to change the starting numbering of the lists?
HTML has got the solution for it: the 'start' attribute. So, if we change <ol> to <ol start="7"
Description Lists
A list of definitions is not the same as a list of items. This is a collection of items with an
explanation.
Tag Description
In comparison to ordered and unordered lists, description lists are very specific in their
application and thus are rarely used. However, whenever a structure such as a list of terms
and their descriptions is required, description lists are ideal.
Eg:
The output is as follows:
NESTING ELEMENTS
HTML elements can be nested i.e. elements can contain elements. Actually, all HTML
documents consist of nested HTML elements
Eg:
IMAGES IN HTML
The <img> tag is used to specify images in HTML.
Attribute Description
alt to specify alternate text (it gets displayed if due to some issue image
doesn’t get displayed)
You must use the src attribute to display an image on a page. Src is the 'source.' The
src's value is the URL of the picture that you wish to show on your page.
The URL may be relative or absolute.
We'll discuss them later.
<img src="images/logo.png">
We wrote 'images/logo,' as you can see, in the src attribute. This is a relative url example.
The image will now be displayed on the page like
● image tag is a self-closing tag which means that it doesn't contain the closing tag.
● The src tag can contain both relative and absolute paths, as well as internet image
links.
The ALT Attribute
The alt attribute or alternative text will inform the reader what it lacks on a page when
the browser cannot load pictures. Instead of the picture, the browser displays the
alternative text.
NOTE: It is a good practice to include the "alt" attribute for each image on a page
You may explicitly specify the height and width of an image with the attributes
Eg.,
This will fix the height and width of the image to 500px (pixel). There is an alternative for
height and width attributes in CSS. We can come to this later.
NOTE: The value provided should be in numerical form. Pixel is a unit of measurement, to
set
the dimensions of the image.
ATTRIBUTES
HTML elements can have certain characteristics associated with them which are called
attributes. These attributes provide more information about the element For example:
● The alt attribute defines the alternate text which will be shown if the image doesn’t
load due to any reason; the Coding Ninjas image will be shown as alternate text.
● The height attribute can be used to set the image’s height in pixels.
● Similarly, the width attribute is used to set the width of the image in
pixels.
Enables navigation between different web Enables navigation within a web page. Eg:
pages without having to type its URL each link to the page-top or link to a particular
time. Helps to connect to other websites. page material.
href Attribute
The <a> element's most significant attribute, href, indicates the destination of the link. T
his means that the href attribute is used to refer to the document that is linked to the
relation.
Eg;
You will see this:
An anchor tag may indicate any web-based resource: an HTML page, a picture, a sound
file, a video, etc. Both of these are referred to as external connections.
NOTE: You need to remember that here also, we can provide the relative URL of a file as a
value to href attribute. Eg: href="/home/myPC/Documents/test.html".
For specifying local links, relative links are used, i.e. links to root files. Absolute links
are used in external links, i.e. the web page's URL. The browser searches for file locations
concerning the current page when a user clicks the relative connection.
● The file is present in the same folder - In this case, the name of the file is provided.
Eg: <a href="relativeFile.html">Click Me</a>, will look for the file
inside the same folder.
● The file is present in the subfolder - In this case, the name of the file provided is
preceded by the folder names according to hierarchy.
Eg: <a href="subfolder/down/relativeFile.html">Click Me</a>, will
move to the 'subfolder' folder, then to 'down' folder and look for the file inside it.
● The file is present somewhere in the parent folder - In this case, to move one
folder above use '../'. For instance: <a href="../relativeFile.html"> Click Me</a>, step
into the parent folder and search for the inside address.
● The file is present in another subfolder of the parent folder - This case covers
the above two cases.
For instance: <a href="../subfolder/relativeDateien.html"> Click Me</a> to switch to
the parent folder, then to the 'subfolder' folder, and search for the inside of the folder.
The full web address of the web page you want to go to is indicated by absolute links.
eg:: <a href="https://1603.de/"> Click Me</a> to guide the browser to the URL you like.
The target attribute defines where the linked document will be opened. It has the
following values:
● _self: Load the URL to the current tab on its own. This is the default setting.
● _blank: Load the URL to the new tab or browser window.
● _parent: Load the URL in the context of the parent browsing. It's the same thing as
itself if there are no parents.
● _top: Load URLs in the high-level context of browsing. It is the same thing if there is no
parent.
NOTE: By default, the linked page will be displayed in the current browser window. It can
be cumbersome to remember all this HTML code. This HTML cheatsheet can be
downloaded from the link below to refer to all HTML tags and attributes without the following:
https://html.com/wp-content/uploads/html-cheat-sheet