HTML NOTES
HTML NOTES
HTML Documents
All HTML documents must start with a document type declaration: <!DOCTYPE html>.
The HTML document itself begins with <html> and ends with </html>.
The visible part of the HTML document is between <body> and </body>.
HTML Headings
HTML headings are defined with the <h1> to <h6> tags.
<h1> defines the most important heading. <h6> defines the least important heading
HTML Paragraphs
HTML paragraphs are defined with the <p> tag:
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
HTML Link
HTML links are defined with the <a> tag:
HTML Images
HTML images are defined with the <img> tag.
The source file (src), alternative text (alt), width, and height are provided as
attributes:
The following example contains four HTML elements ( <html>, <body>, <h1> and <p>):
Example Explained
The <html> element is the root element and it defines the whole HTML document.
The <br> tag defines a line break, and is an empty element without a closing tag:
HTML Attributes
All HTML elements can have attributes
Attributes provide additional information about elements
Attributes are always specified in the start tag
Attributes usually come in name/value pairs like: name="value"
<img src="img_girl.jpg">
There are two ways to specify the URL in the src attribute:
Notes: External images might be under copyright. If you do not get permission to use it,
you may be in violation of copyright laws. In addition, you cannot control external images;
it can suddenly be removed or changed.
2. Relative URL - Links to an image that is hosted within the website. Here, the URL does
not include the domain name. If the URL begins without a slash, it will be relative to the
current page. Example: src="img_girl.jpg". If the URL begins with a slash, it will be
relative to the domain. Example: src="/images/img_girl.jpg".
Tip: It is almost always best to use relative URLs. They will not break if you change
domain.
The value of the title attribute will be displayed as a tooltip when you mouse over the
element:
<p>In some situations, when the attribute value itself contains double quotes, it is
necessary to use single quotes:</p>
<p>Move your mouse over the paragraphs below to see the effect:</p>
HTML Headings
HTML Headings
HTML headings are defined with the <h1> to <h6> tags.
<h1> defines the most important heading. <h6> defines the least important heading.
<h1>Heading 1</h1>
<h2>Heading 2</h2>
<h3>Heading 3</h3>
<h4>Heading 4</h4>
<h5>Heading 5</h5>
<h6>Heading 6</h6>
HTML Paragraphs
The HTML <p> element defines a paragraph.
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>
With HTML, you cannot change the display by adding extra spaces or extra lines in your
HTML code.
The browser will automatically remove any extra spaces and lines when the page is
displayed
The <hr> element is used to separate content (or define a change) in an HTML page:
Use <br> if you want a line break (a new line) without starting a new paragraph:
<p>
My Bonnie lies over the ocean.
The text inside a <pre> element is displayed in a fixed-width font (usually Courier), and it
preserves both spaces and line breaks
<pre>
My Bonnie lies over the ocean.
HTML Styles
The HTML style attribute is used to add styles to an element, such as color, font,
size, and more.
<tagname style="property:value;">
Background Color
The CSS background-color property defines the background color for an HTML element.
<body style="background-color:powderblue;">
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
Text Color
The CSS color property defines the text color for an HTML element:
Fonts
The CSS font-family property defines the font to be used for an HTML element:
Text Size
The CSS font-size property defines the text size for an HTML element:
Text Alignment
The CSS text-align property defines the horizontal text alignment for an HTML element:
<blockquote cite="http://www.worldwildlife.org/who/index.html">
For nearly 60 years, WWF has been protecting the future of nature.
</blockquote>
OUTPUT
For nearly 60 years, WWF has been protecting the future of nature.
<p>WWF's goal is to: <q>Build a future where people live in harmony with
nature.</q></p>
OUTPUT
WWF's goal is to: “Build a future where people live in harmony with nature.”
The WHO(on putting mouse on WHO it will show full form) was founded in
1948.
<address>
Visit us at:<br>
Example.com<br>
USA
</address>
HTML Comments
Comments can be used to hide content.
<p>This is a paragraph.</p>
Hello World
Text Color
You can set the color of text:
Border Color
You can set the color of borders:
Hello World
HTML Links
HTML Links - Syntax
The HTML <a> tag defines a hyperlink. It has the following syntax:
_self - Default. Opens the document in the same window/tab as it was clicked
_blank - Opens the document in a new window or tab
A local link (a link to a page within the same website) is specified with a relative
URL (without the "https://www" part):
<h2>Absolute URLs</h2>
<p><a href="https://www.w3.org/">W3C</a></p>
<p><a href="https://www.google.com/">Google</a></p>
<h2>Relative URLs</h2>
<p><a href="html_images.asp">HTML Images</a></p>
<p><a href="/css/default.asp">CSS Tutorial</a></p>
Image as a Link
The image below is a link. Try to click on it.
smily face with link
Button as a Link
To use an HTML button as a link, you have to add some JavaScript code.
JavaScript allows you to specify what happens at certain events, such as a click of a
button:
Example
<button onclick="document.location='default.asp'">HTML Tutorial</button>
Link Titles
The title attribute specifies extra information about an element. The information is most
often shown as a tooltip text when the mouse moves over the element.
Example
<a href="https://www.w3schools.com/html/" title="Go to W3Schools HTML
section">Visit our HTML Tutorial</a>
Title – mouse leke jaane se title dikha dega
To create a bookmark - first create the bookmark, then add a link to it.
When the link is clicked, the page will scroll down or up to the location with the bookmark.
Example
First, use the id attribute to create a bookmark:
<p><a href="#C4">Jump to Chapter 4</a></p>
<h2>Chapter 1</h2>
<h2>Chapter 2</h2>
<h2>Chapter 3</h2>