0% found this document useful (0 votes)
13 views

HTML notes 2

Introductory HTML for Class 12 & 12 students studying Bangladesh NCTB Curriculum 2024

Uploaded by

shahriar.pgcb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

HTML notes 2

Introductory HTML for Class 12 & 12 students studying Bangladesh NCTB Curriculum 2024

Uploaded by

shahriar.pgcb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

HTML Elements

An HTML element is defined by a start tag, some content, and an end tag. The HTML
element is everything from the start tag to the end tag:

<tagname>Content goes here...</tagname>


Examples of some HTML elements:
<h1>My First Heading</h1>
<p>My first paragraph.</p>
Some HTML elements have no content (like the <br> element). These elements are called
empty elements. Empty elements do not have an end tag!

HTML elements can be nested (this means that elements can contain other elements). All
HTML documents consist of nested HTML elements.

Some HTML elements will display correctly, even if you forget the end tag:
<p>This is a paragraph
<p>This is a paragraph
However, errors may occur if you forget the end tag!

HTML elements with no content are called empty elements. The <br> tag defines a line
break, and is an empty element without a closing tag:
<p>This is a <br> paragraph with a line break.</p>
Output:
This is a
paragraph with a line break.

HTML is Not Case Sensitive


HTML tags are not case sensitive: <P> means the same as <p>. The HTML standard does
not require lowercase tags, but W3C recommends lowercase in HTML, and demands
lowercase for stricter document types like XHTML.
HTML Attributes
HTML attributes provide additional information about HTML elements.
 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"

All HTML elements can have attributes


The href attribute of <a> specifies the URL of the page the link goes to
The src attribute of <img> specifies the path to the image to be displayed
The width and height attributes of <img> provide size information for images
The alt attribute of <img> provides an alternate text for an image
The style attribute is used to add styles to an element, such as color, font, size, and more

5
The lang attribute of the <html> tag declares the language of the Web page
The title attribute defines some extra information about an element

The href Attribute


The <a> tag defines a hyperlink. The href attribute specifies the URL of the page the link
goes to:
<a href="https://www.buet.ac.bd/web/#/">BUET Website</a>

The src Attribute


The <img> tag is used to embed an image in an HTML page. The src attribute specifies the
path to the image to be displayed:
<img src="BUETlogo.jpg">

There are two ways to specify the URL in the src attribute:

Absolute URL - Links to an external image that is hosted on another website.


Example: src="https://www.buet.ac.bd/web/assets/img/logoBIRN.png".

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="BUETlogo.jpg". If the URL begins with a slash, it will be relative to the
domain. Example: src="/images/ BUETlogo.jpg".
Tip: It is almost always best to use relative URLs. They will not break if you change domain.
Relative references work well when you have a bunch of interconnected web pages. If you
create a lot of pages about the same topic and put them in the same directory, you can use
relative references between the pages. If you decide to move your pages to another server,
all the links still work correctly.
If you're referring to a page on somebody else's site, you have to use an absolute reference.
If you're linking to another page on your site, you typically use a relative reference.
The width and height Attributes
The <img> tag should also contain the width and height attributes, which specify the width
and height of the image (in pixels): you can write ‘px’ after the value.
<img src="BUETlogo.jpg" width="500" height="600">

The alt Attribute


The required alt attribute for the <img> tag specifies an alternate text for an image, if the
image for some reason cannot be displayed. This can be due to a slow connection, or an
error in the src attribute, or if the user uses a screen reader.
<img src="BUETlogo.jpg" alt="BUET logo">

The style Attribute


The style attribute is used to add styles to an element, such as color, font, size, and more.
<p style="color:red;">This is a red paragraph.</p>
<p style="color:blue;font-size:50px;">I am blue</p>

6
The lang Attribute
You should always include the lang attribute inside the <html> tag, to declare the language
of the Web page. This is meant to assist search engines and browsers.
The following example specifies English as the language:
<!DOCTYPE html><html lang="en">

Country codes can also be added to the language code in the lang attribute. So, the first two
characters define the language of the HTML page, and the last two characters define the
country.
The following example specifies English as the language and United States as the country:
<!DOCTYPE html>
<html lang="en-US">

The title Attribute


The title attribute defines some extra information about an element.
The value of the title attribute will be displayed as a tooltip when you mouse over the
element:
<h2 title="I'm a header">The title Attribute</h2>
<p title="I'm a tooltip">This is a paragraph.</p>

Always Use Lowercase Attributes


The HTML standard does not require lowercase attribute names. The title attribute (and all
other attributes) can be written with uppercase or lowercase like title or TITLE.
However, W3C recommends lowercase attributes in HTML, and demands lowercase
attributes for stricter document types like XHTML.
Always Quote Attribute Values
The HTML standard does not require quotes around attribute values. However,
W3C recommends quotes in HTML, and demands quotes for stricter document types like
XHTML.
Good:
<a href="https://www.w3schools.com/html/">Visit our HTML tutorial</a>

Bad:
<a href=https://www.w3schools.com/html/>Visit our HTML tutorial</a>

Single or Double Quotes?


Double quotes around attribute values are the most common in HTML, but single quotes can
also be used. In some situations, when the attribute value itself contains double quotes, it
is necessary to use single quotes:
<p title='John "ShotGun" Nelson'>
Or vice versa:
<p title="John 'ShotGun' Nelson">

7
HTML Headings
HTML headings are titles or subtitles that you want to display on a webpage.
<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 headings are defined with the <h1> to <h6> tags. <h1> defines the most important
heading. <h6> defines the least important heading. Browsers automatically add some white
space (a margin) before and after a heading.

Headings Are Important


Search engines use the headings to index the structure and content of your web pages.
Users often skim a page by its headings. It is important to use headings to show the
document structure.
<h1> headings should be used for main headings, followed by <h2> headings, then the less
important <h3>, and so on.
Use HTML headings for headings only. Don't use headings to make text BIG or bold.

Bigger Headings
Each HTML heading has a default size. However, you can specify the size for any heading
with the style attribute, using the CSS font-size property:
<h1 style="font-size:60px;">Heading 1</h1>

HTML Paragraphs
A paragraph always starts on a new line, and is usually a block of text. 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>

HTML Display
You cannot be sure how HTML will be displayed. Large or small screens, and resized
windows will create di erent results. 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.
HTML Horizontal Rules
The <hr> tag defines a thematic break in an HTML page, and is most often displayed as a
horizontal rule.
The <hr> element is used to separate content (or define a change) in an HTML page:
The <hr> tag is an empty tag, which means that it has no end tag.

8
HTML Line Breaks
The HTML <br> element defines a line break.
Use <br> if you want a line break (a new line) without starting a new paragraph:
<p>This is<br>a paragraph<br>with line breaks.</p>

The <br> tag is an empty tag, which means that it has no end tag.

The HTML <pre> Element


The HTML <pre> element defines preformatted text.
The text inside a <pre> element is displayed in a fixed-width font (usually Courier), and it
preserves both spaces and line breaks:

HTML Styles
The HTML style attribute is used to add styles to an element, such as color, font, size, and
more.
 Use the style attribute for styling HTML elements
 Use background-color for background color
 Use color for text colors
 Use font-family for text fonts
 Use font-size for text sizes
 Use text-align for text alignment

<!DOCTYPE html> I am normal


<html>
<body> I am red

<p>I am normal</p> I am blue


<p style="color:red;">I am red</p>
<p style="color:blue;">I am blue</p>
<p style="font-size:50px;">I am big</p>
I am big
</body>
</html>

The HTML Style Attribute


Setting the style of an HTML element, can be done with the style attribute.
The HTML style attribute has the following syntax:
<tagname style="property:value;">

The property is a CSS property. The value is a CSS value.

Background Color
The CSS background-color property defines the background color for an HTML element.
<body style="background-color:powderblue;">
Background color for two di erent elements can be set:

9
<h1 style="background-color:powderblue;">This is a heading</h1>
<p style="background-color:tomato;">This is a paragraph.</p>

Text Color
The CSS color property defines the text color for an HTML element:
<h1 style="color:blue;">This is a heading</h1>
<p style="color:red;">This is a paragraph.</p>

Fonts
The CSS font-family property defines the font to be used for an HTML element:
<h1 style="font-family:verdana;">This is a heading</h1>
<p style="font-family:courier;">This is a paragraph.</p>

Text Size
The CSS font-size property defines the text size for an HTML element:
<h1 style="font-size:300%;">This is a heading</h1>
<p style="font-size:160%;">This is a paragraph.</p>

Text Alignment
The CSS text-align property defines the horizontal text alignment for an HTML element:
<h1 style="text-align:center;">Centered Heading</h1>
<p style="text-align:center;">Centered paragraph.</p>

10

You might also like