HTML (Introduction)
HTML (Introduction)
My first paragraph.
Web Browsers
Example Explained
The purpose of a web browser (Chrome, Edge, Firefox, Safari) is to
read HTML documents and display them correctly.
HTML History
A browser does not display the HTML tags, but uses them to Since the early days of the World Wide Web, there have been many versions of HTML:
determine how to display the document:\
Year Version
Below is visualization of an HTML page structure. 1999 W3C Recommendation: HTML 4.01
Note: The content inside the <body> section (the white area above) will be
displayed in a browser. The content inside the <title> element will be shown in
the browser's title bar or in the page's tab.
The <!DOCTYPE> declaration represents the document type, and helps
2.HTML Basic Examples browsers to display web pages correctly.
In this chapter we will show some basic HTML examples. It must only appear once, at the top of the page (before any HTML
tags).
Don't worry if we use tags you have not learned about yet.
The <!DOCTYPE> declaration is not case sensitive.
All HTML documents must start with a document type declaration: <!
DOCTYPE html>.
The HTML document itself begins with <html> and ends with </html>. HTML Headings
The visible part of the HTML document is HTML headings are defined with the <h1> to <h6> tags.
between <body> and </body>.
<h1> defines the most important heading. <h6> defines the least
important heading:
Example
Examples:
<!DOCTYPE html>
<html>
<body> <h1>This is heading 1</h1>
<h2>This is heading 2</h2>
<h3>This is heading 3</h3>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</body>
This is heading 1
</html>
This is heading 2
The <!DOCTYPE> Declaration
This is heading 3
Table 1
2
The source file (src), alternative text (alt), width, and height are
provided as attributes:
HTML Paragraphs
Example
HTML paragraphs are defined with the <p> tag:
HTML links are defined with the <a> tag: View HTML Source Code:
HTML Images
3.HTML Elements
Nested HTML Elements
HTML elements can be nested (this means that elements can contain
An HTML element is defined by a start tag, some content, and an end other elements).
tag.
All HTML documents consist of nested HTML elements.
The HTML element is everything from the start tag to the end tag: Example
</body>
Start tag Element content End tag </html>
My first paragraph.
It has a start tag <p> and an end tag </p>:
Example Explained
Never Skip the End Tag
The <html> element is the root element and it defines the whole HTML
document. Some HTML elements will display correctly, even if you forget the end
tag:
It has a start tag <html> and an end tag </html>.
<body>
<html>
<h1>My First Heading</h1> <body>
<p>My first paragraph.</p>
<p>This is a paragraph</p>
</body> <p>This is a paragraph</p>
Then, inside the <body> element there are two other This is a paragraph.
elements: <h1> and <p>:
This is a paragraph.
<h1>My First Heading</h1>
<p>My first paragraph.</p>
Example
HTML Attributes
The HTML standard does not require lowercase tags, but All HTML elements can have attributes
W3C recommends lowercase in HTML, and demands lowercase for Attributes provide additional information about elements
stricter document types like XHTML. Attributes are always specified in the start tag
Attributes usually come in name/value pairs
like: name="value"
The <a> tag defines a hyperlink. The href attribute specifies the URL
HTML Tag Reference of the page the link goes to:
Tag Description
<a href="https://www.w3schools.com">Visit W3Schools</a>
<html> Defines the root of an HTML document
</body>
</html>
You will learn more about links in our HTML Links chapter.
There are two ways to specify the URL in the src attribute:
1. Absolute URL - Links to an external image that is hosted on Example
another website.
Example: src="https://www.w3schools.com/images/img_girl.jpg".
See what happens if we try to display an image that does not exist:
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. <img src="img_typo.jpg" alt="Girl with a jacket">
2. Relative URL - Links to an image that is hosted within the website. You will learn more about images in our HTML Images chapter.
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: 4.HTML Headings
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. HTML headings are titles or subtitles that you want to display on a
webpage.
The <img> tag should also contain the width and height attributes,
which specifies the width and height of the image (in pixels):
Heading 1
Example
<h1> defines the most important heading. <h6> defines the least
important heading
Note: Use HTML headings for headings only. Don't use headings to
<!DOCTYPE html> make text BIG or bold.
<html> Heading 1
<body>
You can change the size of a heading with
<h1 style="font- the style attribute, using the font-size
property. Bigger Headings
size:60px;">Heading 1</h1>
Each HTML heading has a default size. However, you can specify the
<p>You can change the size size for any heading with the style attribute, using the CSS font-
of a heading with the style size property:
attribute, using the font-
size property.</p>
Example
</body>
</html>
<h1 style="font-size:60px;">Heading 1</h1>
HTML Tag Reference
A paragraph always starts on a new line, and is usually a block of text.
W3Schools' tag reference contains additional information about these
tags and their attributes.
HTML Paragraphs
Example
<body> Defines the document's body
HTML Display
HTML Paragraphs
You cannot be sure how HTML will be displayed.
Large or small screens, and resized windows will create different Example
results.
With HTML, you cannot change the display by adding extra spaces or <h1>This is heading 1</h1>
extra lines in your HTML code. <p>This is some text.</p>
<hr>
The browser will automatically remove any extra spaces and lines <h2>This is heading 2</h2>
when the page is displayed: <p>This is some other text.</p>
<hr>
Example
This is heading 1
<p>
This paragraph This is some text.
contains a lot of lines
in the source code,
but the browser
ignores it.
</p> This is heading 2
<p>
This paragraph This is some other text.
contains a lot of spaces
in the source code,
but the browser
ignores it.
</p>
This is heading 2
This is some other text.
<pre>
Example My Bonnie lies over the ocean.
Example
The pre tag preserves both spaces and line breaks:
My Bonnie lies over the ocean. Oh, bring back my Bonnie to me.
I am big
Tag Description
blue</p>
<p> Defines a paragraph <p style="font-size:50px;">I
am big</p>
<hr> Defines a thematic change in the content
</body>
<br> Inserts a single line break </html>
Example </body>
<!DOCTYPE html>
<!DOCTYPE html>
<html> This is a
<html>
<body style="background-
This is a <body>
heading
color:powderblue;"> heading <h1 style="background-
color:powderblue;">This is a
<h1>This is a heading</h1>
heading</h1> This is a paragraph.
<p>This is a paragraph.</p> This is a paragraph.
<p style="background-
color:tomato;">This is a
</body>
paragraph.</p>
</html>
</body>
</html>
The CSS color property defines the text color for an HTML element:
<body style="background-color:powderblue;">
<h1>This is a heading</h1>
<p>This is a paragraph.</p> Example
</body>
<h1 style="color:blue;">This is a heading</h1>
<p style="color:red;">This is a paragraph.</p>
Example
This is a heading
<h1 style="color:blue;">This is a
Set background color for two different elements: heading</h1> This is a paragraph.
<p style="color:red;">This is a
paragraph.</p> Example
<!DOCTYPE html>
Fonts
This is a
<!DOCTYPE html>
<html>
<body>
<h1 style="font-family:verdana;">This
heading
Text Alignment
is a heading</h1>
<p style="font-family:courier;">This is This is a The CSS text-align property defines the horizontal text alignment for
a paragraph.</p> paragraph. an HTML element:
</body>
</html> Example
Text Size
The CSS font-size property defines the text size for an HTML Centered Heading
element:
Centered paragraph.
Chapter Summary
The HTML <b> element defines bold text, without any extra
importance.
This text is bold
Example
This text is italic
Example
<strong>This text is important!</strong> The HTML <small> element defines smaller text:
Example
HTML <i> and <em> Elements
The HTML <i> element defines a part of text in an alternate voice or <small>This is some smaller text.</small>
mood. The content inside is typically displayed in italic.
Tip: The <i> tag is often used to indicate a technical term, a phrase
from another language, a thought, a ship name, etc.
HTML <mark> Element
Example The HTML <mark> element defines text that should be marked or
highlighted:
The HTML <del> element defines text that has been deleted from a
<em>This text is emphasized</em> document. Browsers will usually strike a line through deleted text:
Example
</body>
</html>
Example
Marking abbreviations can give useful information to browsers,
HTML <blockquote> for Quotations translation systems and search-engines.
The HTML <blockquote> element defines a section that is quoted Tip: Use the global title attribute to show the description for the
from another source. abbreviation/acronym when you mouse over the element.
Example
<p>The <abbr title="World Health Organization">WHO</abbr> was
founded in 1948.</p>
<p>Here is a quote from WWF's website:</p>
<blockquote cite="http://www.worldwildlife.org/who/index.html">
For 50 years, WWF has been protecting the future of nature. HTML <address> for Contact Information
The world's leading conservation organization,
WWF works in 100 countries and is supported by The HTML <address> tag defines the contact information for the
1.2 million members in the United States and author/owner of a document or an article.
close to 5 million globally.
</blockquote> The contact information can be an email address, URL, physical
address, phone number, social media handle, etc.
HTML <q> for Short Quotations
The text in the <address> element usually renders in italic, and
browsers will always add a line break before and after
The HTML <q> tag defines a short quotation. the <address> element.
Example
<address>
Written by John Doe.<br>
<p>WWF's goal is to: <q>Build a future where people live in Visit us at:<br>
harmony with nature.</q></p> Example.com<br>
Box 564, Disneyland<br>
USA
HTML <abbr> for Abbreviations </address>
The HTML <bdo> tag is used to override the current text direction:
<cite> Defines the title of a work
Example
<bdo dir="rtl">This text will be written from right to <q> Defines a short inline quotation
left</bdo>
Notice that there is an exclamation point (!) in the start tag, but not in
the end tag. <p>This is a paragraph.</p>
You can also hide more than one line, everything between
the <!-- and the --> will be hidden from the display.
DodgerBlue
HTML Colors
MediumSeaGreen
HTML colors are specified with predefined color names, or with RGB,
HEX, HSL, RGBA, or HSLA values.
Gray
Color Names
Violet
Tomato
Background Color
Hello World
Example
Hello World
Hello World
<h1 style="background-color:DodgerBlue;">Hello World</h1>
<p style="background-color:Tomato;">Lorem ipsum...</p>
Example
Hello World
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam
nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam Color Values
erat volutpat.
In HTML, colors can also be specified using RGB values, HEX values,
Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper HSL values, RGBA values, and HSLA values.
suscipit lobortis nisl ut aliquip ex ea commodo consequat.
The following three <div> elements have their background color set
with RGB, HEX, and HSL values:
Example
hsl(9, 100%, 64%) In HTML, a color can be specified as an RGB value, using this formula:
The following two <div> elements have their background rgb(red, green, blue)
color set with RGBA and HSLA values, which add an Alpha
channel to the color (here we have 50% transparency) Each parameter (red, green, and blue) defines the intensity of the
color with a value between 0 and 255.
This means that there are 256 x 256 x 256 = 16777216 possible
Example
colors!
<h1 style="background-color:rgba(255, 99, 71, To display black, set all color parameters to 0, like this: rgb(0, 0, 0).
0.5);">...</h1>
To display white, set all color parameters to 255, like this: rgb(255,
<h1 style="background-color:hsla(9, 100%, 64%, 255, 255).
0.5);">...</h1>
Experiment by mixing the RGB values below:
#ff0000,#0000ff,#3cb371,#ee82ee,
#ffa500,#6a5acd
In HTML, a color can be specified using a hexadecimal value in the In HTML, a color can be specified using hue, saturation, and lightness
form: (HSL) in the form:
Where rr (red), gg (green) and bb (blue) are hexadecimal values Hue is a degree on the color wheel from 0 to 360. 0 is red, 120 is
between 00 and ff (same as decimal 0-255). green, and 240 is blue.
For example, #ff0000 is displayed as red, because red is set to its Saturation is a percentage value, 0% means a shade of gray, and
highest value (ff), and the other two (green and blue) are set to 00. 100% is the full color.
Another example, #00ff00 is displayed as green, because green is set Lightness is also a percentage value, 0% is black, and 100% is white.
to its highest value (ff), and the other two (red and blue) are set to 00.
To display black, set all color parameters to 00, like this: #000000.
Saturation
To display white, set all color parameters to ff, like this: #ffffff.
Saturation can be described as the intensity of a color. What is CSS?
100% is pure color, no shades of gray Cascading Style Sheets (CSS) is used to format the layout of a
webpage.
50% is 50% gray, but you can still see the color.
With CSS, you can control the color, font, the size of text, the spacing
0% is completely gray, you can no longer see the color. between elements, how elements are positioned and laid out, what
background images or background colors are to be used, different
displays for different devices and screen sizes, and much more!
<!DOCTYPE html>
<html>
<body>
<h1 style="background-color:hsl(0, 100%, 50%);">hsl(0, 100%, 50%)</h1> Tip: The word cascading means that a style applied to a parent element
will also apply to all children elements within the parent. So, if you set the
<h1 style="background-color:hsl(240, 100%, 50%);">hsl(240, 100%, 50%)</h1>
color of the body text to "blue", all headings, paragraphs, and other text
<h1 style="background-color:hsl(147, 50%, 47%);">hsl(147, 50%, 47%)</h1> elements within the body will also get the same color (unless you specify
<h1 style="background-color:hsl(300, 76%, 72%);">hsl(300, 76%, 72%)</h1> something else)!
</body>
</html>
The most common way to add CSS, is to keep the styles in external
CSS files. However, in this tutorial we will use inline and internal
styles, because this is easier to demonstrate, and easier for you to try
it yourself.
Inline CSS
An inline CSS is used to apply a unique style to a single HTML element. </style>
</head>
An inline CSS uses the style attribute of an HTML element. <body>
The following example sets the text color of the <h1> element to blue, <h1>This is a heading</h1>
and the text color of the <p> element to red: <p>This is a paragraph.</p>
</body>
Example </html>
An external style sheet is used to define the style for many HTML
<p style="color:red;">A red paragraph.</p>
pages.
An internal CSS is used to define a style for a single HTML page. Example
</body>
Example </html>
The external style sheet can be written in any text editor. The file
<!DOCTYPE html>
must not contain any HTML code, and must be saved with a .css
<html>
extension.
<head>
<style>
body {background-color: powderblue;} Here is what the "styles.css" file looks like:
h1 {color: blue;}
p {color: red;}
"styles.css": <style>
h1 {
color: blue;
font-family: verdana;
body {
font-size: 300%;
background-color: powderblue;
}
}
p {
h1 {
color: red;
color: blue;
font-family: courier;
}
font-size: 160%;
p {
}
color: red;
</style>
}
</head>
<body>
Tip: With an external style sheet, you can change the look of an entire web site, <h1>This is a heading</h1>
by changing one file! <p>This is a paragraph.</p>
</body>
</html>
CSS Colors, Fonts and Sizes
Result;
Here, we will demonstrate some commonly used CSS properties. You
will learn more about them later.
This is a heading
The CSS color property defines the text color to be used.
This is a paragraph.
The CSS font-family property defines the font to be used.
The CSS font-size property defines the text size to be used. CSS Border
<!DOCTYPE html>
Use of CSS border property:
<html>
<head>
p { This is a heading
border: 2px solid powderblue;
}
This is a paragraph.
<!DOCTYPE html>
This is a paragraph.
<html>
This is a paragraph.
<head>
<style>
p {
CSS Padding
border: 2px solid powderblue;
The CSS padding property defines a padding (space) between the text
} and the border.
</style>
Example
</head>
<h1>This is a heading</h1> p {
border: 2px solid powderblue;
padding: 30px;
}
<p>This is a paragraph.</p>
CSS Margin
<p>This is a paragraph.</p>
The CSS margin property defines a margin (space) outside the border.
<p>This is a paragraph.</p>
Example
</body>
<!DOCTYPE html>
<html>
This is a paragraph.
<head>
<style>
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p> External style sheets can be referenced with a full URL or with a path
relative to the current web page.
<p>This is a paragraph.</p>
</body>
Example
Result;
<link rel="stylesheet" href="https://www.w3schools.com/html/ Use the CSS font-family property for text fonts
styles.css"> Use the CSS font-size property for text sizes
Use the CSS border property for borders
Use the CSS padding property for space inside the border
Example Use the CSS margin property for space outside the border
This example links to a style sheet located in the html folder on the current
web site: HTML Links
This example links to a style sheet located in the same folder as the current
page: HTML Links - Hyperlinks
When you move the mouse over a link, the mouse arrow will turn into
You can read more about file paths in the chapter HTML File Paths. a little hand.
Note: A link does not have to be text. A link can be an image or any other HTML
element!
Chapter Summary
Clicking on the link text, will send the reader to the specified URL
address.
<a href="https://www.w3schools.com/">Visit W3Schools.com!</a> The target attribute can have one of the following values:
Example
Example
<h2>Absolute URLs</h2>
<a href="default.asp">
<p><a href="https://www.w3.org/">W3C</a></p>
<img src="smiley.gif" alt="HTML
<p><a href="https://www.google.com/">Google</a></p>
tutorial" style="width:42px;height:42px;">
</a>
<h2>Relative URLs</h2>
<p><a href="html_images.asp">HTML Images</a></p>
<p><a href="/css/default.asp">CSS Tutorial</a></p>
<!DOCTYPE html>
<html>
Image as a Link
<!DOCTYPE html> Absolute URLs <body>
<html>
The image below is a link. Try to
<body> W3C <h2>Image as a Link</h2>
click on it.
<p>The image below is a link. Try to click on
<h2>Absolute URLs</h2>
Google it.</p>
<p><a href="https://www.w3.org/">W3C</a></p>
<p><a <a href="default.asp"><img src="smiley.gif"
Button as a Link
JavaScript allows you to specify what happens at certain events, such The title attribute specifies extra information about an element. The
as a click of a button: 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>
Link to a page located in the html folder on the current web site:
Example
More on Absolute URLs and Relative URLs
Example
Chapter Summary
Use the <a> element to define a link Here, an unvisited link will be green with no underline. A visited link will be
Use the href attribute to define the link address pink with no underline. An active link will be yellow and underlined. In
Use the target attribute to define where to open the linked addition, when mousing over a link (a:hover) it will become red and
document underlined:
Use the <img> element (inside <a>) to use an image as a link
Use the mailto: scheme inside the href attribute to create a
link that opens the user's email program
<style>
a:link {
color: green;
background-color: transparent;
text-decoration: none;
HTML Link Tags }
For a complete list of all available HTML tags, visit our HTML a:visited {
Tag Reference. color: pink;
background-color: transparent;
text-decoration: none;
HTML Links - Different Colors }
a:hover {
color: red;
background-color: transparent;
An HTML link is displayed in a different color depending on whether it text-decoration: underline;
has been visited, is unvisited, or is active. }
a:active {
color: yellow;
background-color: transparent;
text-decoration: underline;
HTML Link Colors
}
</style>
By default, a link will appear like this (in all browsers):
To create a bookmark - first create the bookmark, then add a link to it.
Tag Description When the link is clicked, the page will scroll down or up to the location
with the bookmark.
<a> Defines a hyperlink
Example
<head>
<style>
a:link, a:visited {
Link Button First, use the id attribute to create a bookmark:
background-color: #f44336;
color: white; <h2 id="C4">Chapter 4</h2>
padding: 15px 25px;
text-align: center;
A link styled as a button:
text-decoration: none; Then, add a link to the bookmark ("Jump to Chapter 4"), from within
display: inline-block;
} This is a link the same page:
Chapter Summary Images are not technically inserted into a web page; images are linked
to web pages. The <img> tag creates a holding space for the
referenced image.
Use the id attribute (id="value") to define bookmarks in a
page
Use the href attribute (href="#value") to link to the bookmark The <img> tag is empty, it contains attributes only, and does not have
a closing tag.
<img src="img_girl.jpg" alt="Girl in a jacket"> Note: When a web page loads, it is the browser, at that moment, that
gets the image from a web server and inserts it into the page.
Therefore, make sure that the image actually stays in the same spot in who are visually impaired or learning disabled
relation to the web page, otherwise your visitors will get a broken link
icon. The broken link icon and the alt text are shown if the browser
cannot find the image.
You can use the style attribute to specify the width and height of an
<img src="img_chania.jpg" alt="Flowers in Chania"> image.
Example
The alt Attribute
The value of the alt attribute should describe the image: Alternatively, you can use the width and height attributes:
Example Example
Example
Note: Always specify the width and height of an image. If width and height are
not specified, the web page might flicker while the image loads.
<img src="wrongname.gif" alt="Flowers in Chania">
Tip: A screen reader is a software program that reads the HTML code, and
allows the user to "listen" to the content. Screen readers are useful for people
If you have your images in a sub-folder, you must include the folder
name in the src attribute:
However, we suggest using the style attribute. It prevents styles <img src="/images/html5.gif" alt="HTML5
sheets from changing the size of images: Icon" style="width:128px;height:128px;"
Example
Image as a Link
Image Floating
To use an image as a link, put the <img> tag inside the <a> tag:
Use the CSS float property to let the image float to the right or to the
left of a text:
Example
Example
<
Abbreviatio File Format File Extension a
n <p><img src="smiley.gif" alt="Smiley
h face" style="float:right;width:42px;height:42px;">
r The image will float to the right of the text.</p>
APNG Animated .apng e
Portable Network f
Graphics <p><img src="smiley.gif" alt="Smiley
=
face" style="float:left;width:42px;height:42px;">
"
The image will float to the left of the text.</p>
GIF Graphics .gif d
Interchange e
Format f
a Tip: To learn more about CSS Float, read our CSS Float Tutorial.
ICO Microsoft Icon .ico, .cur u
l
t
.
JPEG Joint Photographic .jpg, .jpeg, .jfif, .pjpeg, .pjp a
Expert Group s
Common Image Formats
image p
"
> Here are the most common image file types, which are supported in
PNG Portable Network .png all browsers (Chrome, Edge, Firefox, Safari, Opera):
Graphics
<
SVG Scalable Vector .svg i
Graphics m
g
Example
Here is the HTML source code for the image map above:
Chapter Summary
Note: Loading large images takes time, and can slow down your web
page. Use images carefully.
HTML Image Maps The idea behind an image map is that you should be able to perform
different actions depending on where in the image you click.
To create an image map you need an image, and some HTML code
that describes the clickable areas.
With HTML image maps, you can create clickable areas on an image.
The Image
The image is inserted using the <img> tag. The only difference from
other images is that you must add a usemap attribute:
Image Maps
<img src="workplace.jpg" alt="Workplace" usemap="#workmap">
The HTML <map> tag defines an image map. An image map is an
image with clickable areas. The areas are defined with one or The usemap value starts with a hash tag # followed by the name of the
more <area> tags. image map, and is used to create a relationship between the image
and the image map.
Try to click on the computer, phone, or the cup of coffee in the image
below:
Tip: You can use any image as an image map!
Shape="rect"
The coordinates for shape="rect" come in pairs, one for the x-axis
and one for the y-axis.
Create Image Map
So, the coordinates 34,44 is located 34 pixels from the left margin and
Then, add a <map> element.
44 pixels from the top:
<map name="workmap">
Example
The Areas
<area shape="rect" coords="34, 44, 270,
Then, add the clickable areas. 350" href="computer.htm">
A clickable area is defined using an <area> element. This is the area that becomes clickable and will send the user to the
page "computer.htm":
Shape
You must define the shape of the clickable area, and you can choose
one of these values:
Shape="circle"
rect - defines a rectangular region
circle - defines a circular region To add a circle area, first locate the coordinates of the center of the
poly - defines a polygonal region circle:
default - defines the entire region
337,300
You must also define some coordinates to be able to place the
clickable area onto the image. Then specify the radius of the circle:
44 pixels
Example
We have to find the x and y coordinates for all edges of the croissant:
<map name="workmap">
<area shape="circle" coords="337,300,44" href="coffee.htm" onc
lick="myFunction()">
The coordinates come in pairs, one for the x-axis and one for the y- </map>
axis:
<script>
function myFunction() {
alert("You clicked the coffee cup!");
}
</script>
Example
Chapter Summary
Add a background image on a HTML element:
Use the HTML <map> element to define an image map
Use the HTML <area> element to define the clickable areas in
the image map <p style="background-image: url('img_girl.jpg');">
Use the HTML usemap attribute of the <img> element to point
to an image map
For a complete list of all available HTML tags, visit our HTML Tag
Tag Description
Reference
<img> Defines an image
<map> Defines an image map
<area> Defines a clickable area inside an image map
<picture> Defines a container for multiple image resources
<p>A background image for a p element:</p> You can specify background images
for any visible HTML element.
A background image can be specified for almost any HTML element. <p style="background-image: url('img_girl.jpg');"> In this example, the background image
You can specify background images<br>
is specified for a p element.
for any visible HTML element.<br>
In this example, the background image<br> By default, the background-image
is specified for a p element.<br> will repeat itself in the direction(s)
By default, the background-image<br> where it is smaller than the element
will repeat itself in the direction(s)<br> where it is specified. (Try resizing the
Background Image on a HTML element where it is smaller than the element<br> browser window to see how the
where it is specified. (Try resizing the<br> background image behaves.
browser window to see how the<br>
To add a background image on an HTML element, use the background image behaves.
</p>
HTML style attribute and the CSS background-image property:
</body> <style>
</html>
body {
background-image: url('img_girl.jpg');
}
</style>
You can also specify the background image in the <style> element,
Example
Background Repeat
Specify the background image in the <style> element:
If the background image is smaller than the element, the image will
repeat itself, horizontally and vertically, until it reaches the end of the
<style> element:
p {
background-image: url('img_girl.jpg');
} Example
</style>
<style>
body {
background-image: url('example_img_girl.jpg');
Background Image on a Page }
</style>
If you want the entire page to have a background image, you must
specify the background image on the <body> element: To avoid the background image from repeating itself, set
the background-repeat property to no-repeat.
Example
Example
Example
<style>
Background Cover body {
background-image: url('img_girl.jpg');
If you want the background image to cover the entire element, you background-repeat: no-repeat;
can set the background-size property to cover. background-attachment: fixed;
background-size: 100% 100%;
Also, to make sure the entire element is always covered, set }
the background-attachment property to fixed: </style>
This way, the background image will cover the entire element, with no
stretching (the image will keep its original proportions):
Learn More CSS
Example From the examples above you have learned that background images
can be styled by using the CSS background properties.
<style> To learn more about CSS background properties, study our CSS
body { Background Tutorial.
background-image: url('img_girl.jpg');
background-repeat: no-repeat; HTML <picture> Element
background-attachment: fixed;
background-size: cover;
}
</style>
The HTML <picture> element allows you to display different pictures
for different devices or screen sizes.
Background Stretch
When to use the Picture Element
Example
Example
<picture>
<source media="(min-width: 650px)" srcset="img_food.jpg"> <picture>
<source media="(min-width: 465px)" srcset="img_car.jpg"> <source srcset="img_avatar.png">
<img src="img_girl.jpg"> <source srcset="img_girl.jpg">
</picture> <img src="img_beatles.gif" alt="Beatles" style="width:auto;"
>
</picture>
Note: Always specify an <img> element as the last child element of
the <picture> element. The <img> element is used by browsers that do not
support the <picture> element, or if none of the <source> tags match. Note: The browser will use the first <source> element with matching attribute
values, and ignore any following <source> elements.
For a complete list of all available HTML tags, visit our HTML Tag Reference
<!DOCTYPE html>
<html>
<head>
A favicon is a small image displayed next to the page title in the
<title>My Page Title</title>
browser tab.
<link rel="icon" type="image/x-icon" href="/images/favicon.ico
">
</head>
<body>
A favicon image is displayed to the left of the page title in the browser Favicon File Format Support
tab, like this:
The following table shows the file format support for a favicon
image:
HTML Page Title Define an HTML Table
Table Cells
Company Contact Country Everything between <td> and </td> are the content of the table cell.
Example
To avoid having double borders like in the example above, set the
CSS border-collapse property to collapse.
Example If you set a background color of each cell, and give the border a white
color (the same as the document background), you get the impression
of an invisible border
table, th, td {
border: 1px solid black;
}
Example Example
With the border-style property, you can set the appereance of the
Round Table Borders border.
dotted
Example
dashed
solid
double
table, th, td { groove
border: 1px solid black; ridge
border-radius: inset
outset
none
hidden
Skip the border around the table by leaving out table from the css
selector:
Example
th, td { How To Add a Border
border-style: dotted;
} When you add a border to a table, you also add borders around each
table cell:
Border Color
Example
With the border-color property, you can set the color of the border.
table, th, td {
border: 1px solid black;
}
To avoid having double borders like in the example above, set the
th, td { CSS border-collapse property to collapse.
border-color: #96D4D4;
} This will make the borders collapse into a single border:
Example
table, th, td {
border: 1px solid black;
border-collapse: collapse;
Example
Skip the border around the table by leaving out table from the css
selector:
Example
table, th, td {
border: 1px solid white;
border-collapse: collapse;
} Example
th, td {
background-color: #96D4D4;
} th, td {
border: 1px solid black;
border-radius: 10px;
}
Example
th, td {
border-color: #96D4D4;
The following values are allowed:
}
dotted
dashed
solid
double
HTML Table Borders
groove
ridge
inset
outset
none HTML tables can have borders of different styles and shapes.
hidden
Example
How To Add a Border
th, td { When you add a border to a table, you also add borders around each
border-style: dotted; table cell:
}
Border Color
To add a border, use the CSS border property on table, th,
and td elements:
With the border-color property, you can set the color of the border.
Example
table, th, td { If you set a background color of each cell, and give the border a white
border: 1px solid black; color (the same as the document background), you get the impression
} of an invisible border:
Example
Collapsed Table Borders
To avoid having double borders like in the example above, set the table, th, td {
CSS border-collapse property to collapse. border: 1px solid white;
border-collapse: collapse;
This will make the borders collapse into a single border: }
th, td {
background-color: #96D4D4;
}
Example With the border-radius property, the borders get rounded corners:
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
Example
table, th, td {
Style Table Borders
border: 1px solid black;
border-radius: 10px;
}
inset
outset
none
Skip the border around the table by leaving out table from the css hidden
selector:
Example
Example
th, td {
border-style: dotted;
th, td { }
border: 1px solid black;
border-radius: 10px;
}
Border Color
With the border-color property, you can set the color of the border.
Dotted Table Borders
With the border-style property, you can set the appereance of the
border.
Example
Example
With Padding
HTML Table - Cell Padding Cell spacing is the space between each cell.
Cell padding is the space between the cell edges and the cell content. By default the space is set to 2 pixels.
By default the padding is set to 0. To change the space between table cells, use the CSS border-
spacing property on the table element:
To add padding on table cells, use the CSS padding property:
Example
Example
table {
border-spacing: 30px;
}
HTML Table - Colspan
To make a cell span over multiple columns, use the colspan attribute:
<table>
<tr>
HTML tables can have cells that spans over multiple rows and/or <th colspan="2">Name</th>
columns. <th>Age</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
NAME <td>43</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>57</td>
</tr>
</table>
APRIL
Note: The value of the colspan attribute represents the number of columns to
span.
2022
FIESTA
To make a cell span over multiple rows, use the rowspan attribute:
Example 13 14 15 16
17 18 19 20
<table> To style every other table row element, use the :nth-
<tr> child(even) selector like this:
<th>Name</th>
<td>Jill</td>
</tr>
<tr> Example
<th rowspan="2">Phone</th>
<td>555-1234</td>
</tr> tr:nth-child(even) {
<tr> background-color: #D6EEEE;
<td>555-8745</td> }
</tr>
</table>
Note: If you use (odd) instead of (even), the styling will occur on row 1,3,5 etc.
instead of 2,4,6 etc.
Note: The value of the rowspan attribute represents the number of rows
to span.
1 2 3 4
5 6 7 8 Example
9 10 11 12
td:nth-child(even), th:nth-child(even) {
background-color: #D6EEEE;
}
If you specify borders only at the bottom of each table row, you will
Combine Vertical and Horizontal Zebra Stripes have a table with horizontal dividers.
You can combine the styling from the two examples above and you Add the border-bottom property to all tr elements to get horizontal
will have stripes on every other row and every other column. dividers:
tr {
border-
First bottom: 1px
Last Name Savings solid #ddd;
Name
Peter Griffin $100 }
Lois Griffin $150
Joe Swanson $300
Example
Hoverable Table
tr:nth-child(even) { Use the :hover selector on tr to highlight table rows on mouse over:
background-color: rgba(150, 212, 212, 0.4);
}
First Name Last Name
th:nth-child(even),td:nth-child(even) {
background-color: rgba(150, 212, 212, 0.4); Peter Griffin
}
Lois Griffin
Example
Joe Swanson
<table>
Example <colgroup>
<col span="2" style="background-color: #D6EEEE">
</colgroup>
<tr>
tr:hover {background-color: #D6EEEE;} <th>MON</th>
<th>TUE</th>
<th>WED</th>
<th>THU</th>
...
HTML Table Colgroup
Note: The <colgroup> tag must be a child of a <table> element and should be
placed before any other table elements, like <thead>, <tr>, <td> etc., but after
the <caption> element, if present.
The <colgroup> element is used to style specific columns of a table.
If you want to style the two first columns of a table, use There are only a very limited selection of CSS properties that are
the <colgroup> and <col> elements. allowed to be used in the colgroup:
The <colgroup> element should be used as a container for the column width property
specifications.
MON TUE WED THU FRI SAT SUN
Each group are specified with a <col> element. 1 2 3 4 5 6 7
The span attribute specifies how many columns that gets the style. 8 9 10 11 12 13 14
15 16 17 18 19 20 21
The style attribute specifies the style to give the columns.
22 23 24 25 26 27 28
visibility property
background properties
Note: There is a very limited selection of legal CSS properties for border properties
colgroups.
All other CSS properties will have no effect on your tables. <tr>
<th>MON</th>
<th>TUE</th>
<th>WED</th>
Multiple Col Elements
<th>THU</th>
…
If you want to style more columns with different styles, use
more <col> elements inside the <colgroup>:
Example
Hide Columns
<table>
<colgroup> You can hide columns with the visibility: collapse property:
<col span="2" style="background-color: #D6EEEE">
<col span="3" style="background-color: pink">
</colgroup>
<tr> Example
<th>MON</th>
<th>TUE</th>
<th>WED</th> <table>
<th>THU</th> <colgroup>
... <col span="2">
<col span="3" style="visibility: collapse">
</colgroup>
<tr>
<th>MON</th>
Empty Colgroups <th>TUE</th>
<th>WED</th>
<th>THU</th>
If you want to style columns in the middle of a table, insert a ...
"empty" <col> element (with no styles) for the columns before:
HTML Lists
Example
<table> HTML lists allow web developers to group a set of related items in lists.
<colgroup>
<col span="3">
<col span="2" style="background-color: pink">
</colgroup>
Example : An unordered HTML list:Item
Example
1. First item
2. Second item <ol>
<li>Coffee</li>
3. Third item <li>Tea</li>
4. Fourth item <li>Milk</li>
</ol>
The list items will be marked with bullets (small black circles) by A description list is a list of terms, with a description of each term.
default:
The <dl> tag defines the description list, the <dt> tag defines the
term (name), and the <dd> tag describes each term:
Example
Example
<ul>
<li>Coffee</li>
<li>Tea</li> <dl>
<li>Milk</li> <dt>Coffee</dt>
</ul> <dd>- black hot drink</dd>
<dt>Milk</dt>
<dd>- white cold drink</dd>
</dl>
<li> Defines a list item An unordered list starts with the <ul> tag. Each list item starts with
the <li> tag.
<dl> Defines a description list
The list items will be marked with bullets (small black circles) by
default:
<dt> Defines a term in a description list
For a complete list of all available HTML tags, visit our HTML Tag <ul>
Reference. <li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
<li>Milk</li>
</ul>
Example - Circle
<ul style="list-style-type:circle;">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
Example - Square
<ul> li {
<li>Coffee</li> float: left;
<li>Tea }
<ul>
<li>Black tea</li> li a {
<li>Green tea</li> display: block;
</ul> color: white;
</li> text-align: center;
<li>Milk</li> padding: 16px;
</ul> text-decoration: none;
}
li a:hover {
Note: A list item (<li>) can contain a new list, and other HTML elements, background-color: #111111;
like images and links, etc. }
</style>
</head>
<body>
<ul>
Horizontal List with CSS <li><a href="#home">Home</a></li>
<li><a href="#news">News</a></li>
HTML lists can be styled in many different ways with CSS. <li><a href="#contact">Contact</a></li>
<li><a href="#about">About</a></li>
One popular way is to style a list horizontally, to create a navigation </ul>
menu:
</body>
</html>
Example
Tip: You can learn much more about CSS in our CSS Tutorial.
The HTML <ol> tag defines an ordered list. An ordered list can be
numerical or alphabetical.
Chapter Summary
Example
<ol>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
Tag Description
<ul> Defines an unordered list
HTML List Tags
<ol> Defines an ordered list
<li> Defines a list item
<dl> Defines a description list
For a complete list of all available HTML tags, visit our HTML Tag <dt> Defines a term in a description list
Reference.
<dd> Describes the term in a description list
<ol type="i">
<ol type="1"> <li>Coffee</li>
<li>Coffee</li> <li>Tea</li>
<li>Tea</li> <li>Milk</li>
<li>Milk</li> </ol>
</ol>
Uppercase Letters:
Control List Counting
<ol type="A"> By default, an ordered list will start counting from 1. If you want to
<li>Coffee</li> start counting from a specified number, you can use
<li>Tea</li> the start attribute:
<li>Milk</li>
</ol>
Example
Lowercase Letters:
<ol start="50">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
HTML List Tags
Tag Description
<ul> Defines an unordered list
Nested HTML Lists <ol> Defines an ordered list
<li> Defines a list item
Lists can be nested (list inside list): <dl> Defines a description list
<dt> Defines a term in a description list
<dd> Describes the term in a description list
Example
For a complete list of all available HTML tags, visit our HTML Tag
Reference.
<ol>
<li>Coffee</li>
<li>Tea
<ol>
<li>Black tea</li>
<li>Green tea</li>
</ol> Tag Description
</li>
<li>Milk</li> <ul> Defines an unordered list
</ol> <ol> Defines an ordered list
<li> Defines a list item
<dl> Defines a description list
Note: A list item (<li>) can contain a new list, and other HTML
elements, like images and links, etc. <dt> Defines a term in a description list
<dd> Describes the term in a description list
The <dl> tag defines the description list, the <dt> tag defines the
term (name), and the <dd> tag describes each term:
Every HTML element has a default display value, depending on what
type of element it is.
Example
There are two display values: block and inline.
<dl>
<dt>Coffee</dt>
<dd>- black hot drink</dd>
<dt>Milk</dt> Block-level Elements
<dd>- white cold drink</dd>
</dl> A block-level element always starts on a new line, and the browsers
automatically add some space (a margin) before and after the
element.
<address>
<header>
<article>
<hr>
<aside>
<li>
<blockquote>
<main>
<canvas>
<nav>
<dd>
<noscript>
<div>
<ol>
<dl>
<p>
<dt>
<pre>
<fieldset>
<section>
<figcaption>
<table>
<figure>
<tfoot>
<footer>
<ul>
<video> <br>
<button>
<dfn>
This is a <span> element inside a paragraph.
<em>
Example
<i>
<span>Hello World</span>
<img>
Try it Yourself »
<input>
Here are the inline elements in HTML:
<kbd>
<a>
<label>
<abbr>
<map>
<acronym>
<object>
<b>
<output>
<bdo>
<q>
<big>
The <div> element is often used as a container for other HTML
<samp> elements.
<select> When used together with CSS, the <div> element can be used to style
blocks of content:
<small>
Example
<span>
<div style="background-color:black;color:white;padding:20px;">
<strong> <h2>London</h2>
<p>London is the capital city of England. It is the most
populous city in the United Kingdom, with a metropolitan area
<sub> of over 13 million inhabitants.</p>
</div>
<sup>
<textarea>
The <span> Element
<var> When used together with CSS, the <span> element can be used to
style parts of the text:
Chapter Summary
Example
HTML Tags
<!DOCTYPE html>
Tag Description <html>
<head>
<div> Defines a section in a document (block-level) <style>
.city {
background-color: tomato;
<span> Defines a section in a document (inline)
color: white;
border: 2px solid black;
margin: 20px;
padding: 20px;
For a complete list of all available HTML tags, visit our HTML Tag Reference. }
</style>
</head>
<body>
HTML class Attribute
<div class="city">
<h2>London</h2>
<p>London is the capital of England.</p> </body>
</html>
</div>
<div class="city">
<h2>Paris</h2> Tip: The class attribute can be used on any HTML element.
<p>Paris is the capital of France.</p>
</div>
Note: The class name is case sensitive!
<div class="city">
<h2>Tokyo</h2>
<p>Tokyo is the capital of Japan.</p>
</div> Tip: You can learn much more about CSS in our CSS Tutorial.
</body>
</html>
Example
HTML id Attribute
<!DOCTYPE html>
<html>
<head>
<style>
.note { The HTML id attribute is used to specify a unique id for an HTML
font-size: 120%; element.
color: red;
} You cannot have more than one element with the same id in an HTML
</style> document.
</head>
<body>
}
<style>
/* Style the element with the id "myHeader" */
</style> #myHeader {
background-color: lightblue;
color: black;
padding: 40px;
</head> text-align: center;
}
<body>
/* Style all elements with the class name "city" */
.city {
<h1 id="myHeader">My Header</h1> background-color: tomato;
color: white;
padding: 10px; To use a bookmark, you must first create it, and then add a link to it.
}
</style> Then, when the link is clicked, the page will scroll to the location with
the bookmark.
<!-- An element with a unique id -->
<h1 id="myHeader">My Cities</h1> Example
Then, add a link to the bookmark ("Jump to Chapter 4"), from within
<h2 class="city">Paris</h2> the same page:
<p>Paris is the capital of France.</p>
HTML bookmarks are used to allow readers to jump to specific parts of The id attribute can also be used by JavaScript to perform some tasks
a webpage. for that specific element.
Use the id attribute to manipulate text with JavaScript: HTML Iframe Syntax
Tip: Study JavaScript in the HTML JavaScript chapter, or in our JavaScript <iframe src="url" title="description"></iframe>
Tutorial.
Tip: It is a good practice to always include a title attribute for
the <iframe>. This is used by screen readers to read out what the
content of the iframe is.
Chapter Summary
<iframe src="demo_iframe.htm" style="height:200px;width:300px;" The target attribute of the link must refer to the name attribute of the
title="Iframe Example"></iframe> iframe:
Example
To remove the border, add the style attribute and use the <p><a href="https://www.w3schools.com" target="iframe_a">W3Sch
CSS border property: ools.com</a></p>
Example
Chapter Summary
<iframe src="demo_iframe.htm" style="border:none;" title="Ifra
me Example"></iframe> The HTML <iframe> tag specifies an inline frame
The src attribute defines the URL of the page to embed
With CSS, you can also change the size, style and color of the iframe's Always include a title attribute (for screen readers)
border: The height and width attributes specifies the size of the
iframe
Use border:none; to remove the border around the iframe The HTML <script> Tag
HTML iframe Tag The <script> element either contains script statements, or it points to
an external script file through the src attribute.
Tag Description
Common uses for JavaScript are image manipulation, form validation,
<iframe> Defines an inline frame and dynamic changes of content.
Example
Tip: You can learn much more about JavaScript in our JavaScript Tutorial.
Example
Example
JavaScript can change content: File Path Examples
Path Description
document.getElementById("demo").innerHTML = "Hello JavaScript!";
<img src="picture.jpg"> The "picture.jpg" file is located in the
same folder as the current page
JavaScript can change styles: <img The "picture.jpg" file is located in the
src="/images/picture.jpg"> images folder at the root of the current
web
<img src="../picture.jpg"> The "picture.jpg" file is located in the
document.getElementById("demo").style.fontSize = "25px"; folder one level up from the current
document.getElementById("demo").style.color = "red"; folder
document.getElementById("demo").style.backgroundColor = "yellow"
;
Example
Web pages
HTML File Paths Images
Style sheets
JavaScripts
When using relative file paths, your web pages will not be bound to
your current base URL. All links will work on your own computer
Relative File Paths (localhost) as well as on your current public domain and your future
public domains.
A relative file path points to a file relative to the current page.
HTML - The Head Element
In the following example, the file path points to a file in the images
folder located at the root of the current web:
In the following example, the file path points to a file in the images
folder located in the current folder: The HTML <head> Element
The <head> element is a container for metadata (data about data) and
is placed between the <html> tag and the <body> tag.
Example HTML metadata is data about the HTML document. Metadata is not
displayed.
<img src="images/picture.jpg" alt="Mountain"> Metadata typically define the document title, character set, styles,
scripts, and other meta information.
In the following example, the file path points to a file in the images
folder located in the folder one level up from the current folder:
The HTML <title> Element
The <title> element defines the title of the document. The title must
be text-only, and it is shown in the browser's title bar or in the page's The HTML <style> Element
tab.
The <style> element is used to define style information for a single
The <title> element is required in HTML documents! HTML page:
So, try to make the title as accurate and meaningful as possible! The HTML <link> Element
A simple HTML document: The <link> element defines the relationship between the current
document and an external resource.
The <link> tag is most often used to link to external style sheets:
Example
Example
<!DOCTYPE html>
<html>
<head>
<title>A Meaningful Page Title</title> <link rel="stylesheet" href="mystyle.css">
</head>
<body>
Tip: To learn all about CSS, visit our CSS Tutorial.
The content of the document......
</body>
</html>
The HTML <meta> Element
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
The <meta> element is typically used to specify the character set,
page description, keywords, author of the document, and viewport
settings. Example of <meta> tags:
The metadata will not be displayed on the page, but are used by
browsers (how to display content or reload page), by search engines
Example
(keywords), and other web services.
Examples
<meta charset="UTF-8">
<meta name="description" content="Free Web tutorials">
Define the character set used:
<meta name="keywords" content="HTML, CSS, JavaScript">
<meta name="author" content="John Doe">
<meta charset="UTF-8">
You should include the following <meta> element in all your web
<meta name="description" content="Free Web tutorials"> pages:
The initial-scale=1.0 part sets the initial zoom level when the page
Setting the viewport to make your website look good on all is first loaded by the browser.
devices:
Here is an example of a web page without the viewport meta tag, and document.getElementById("demo").innerHTML = "Hello
the same web page with the viewport meta tag: JavaScript!";
}
</script>
Tip: If you are browsing this page with a phone or a tablet, you can click on
the two links below to see the difference.
Tip: To learn all about JavaScript, visit our JavaScript Tutorial.
The <base> element specifies the base URL and/or target for all
relative URLs in a page.
The <base> tag must have either an href or a target attribute present,
or both.
Example
The HTML <script> Element
<body>
<script> <img src="images/stickman.gif" width="24" height="39" alt="Stick
function myFunction() { man">
<a href="tags/tag_base.asp">HTML base Tag</a>
</body>
Chapter Summary
Cities
For a complete list of all available HTML tags, visit our HTML Tag Reference. <title> Defines the title of a document
London
London is the capital city of England. It is the most populous city in the United Kingdom,
with a metropolitan area of over 13 million inhabitants.
Standing on the River Thames, London has been a major settlement for two millennia,
its history going back to its founding by the Romans, who named it Londinium.
Footer
You can read more about semantic elements in our HTML Semantics chapter.
CSS framework
CSS float property London is the capital city of England. It is the most populous city in the United Kingdom,
CSS flexbox with a metropolitan area of over 13 million inhabitants.
CSS grid
CSS Frameworks Standing on the River Thames, London has been a major settlement for two millennia,
its history going back to its founding by the Romans, who named it Londinium.
If you want to create your layout fast, you can use a CSS framework,
like W3.CSS or Bootstrap.
Footer
Ever heard about W3Schools Spaces? Here you can create your website from
scratch or use a template, and host it for free.
Example
Example
Cities
Cities
London
Paris
London Tokyo
Paris
Tokyo
London
London
London is the capital city of England. It is the most populous city in the United Kingdom,
with a metropolitan area of over 13 million inhabitants.
Standing on the River Thames, London has been a major settlement for two millennia,
its history going back to its founding by the Romans, who named it Londinium.
Footer
Try it Yourself »
What is Responsive Web Design?
Responsive Web Design is about using HTML and CSS to automatically resize, hide,
shrink, or enlarge, a website, to make it look good on all devices (desktops, tablets, and
phones):
CSS Grid Layout
The CSS Grid Layout Module offers a grid-based layout system, with
rows and columns, making it easier to design web pages without
having to use floats and positioning.
Learn more about CSS grids in our CSS Grid Intro chapter.
Example
Responsive web design is about creating web pages that look good on all devices!
A responsive web design will automatically adjust for different screen sizes and <meta name="viewport" content="width=device-width, initial-
viewports. scale=1.0">
This will set the viewport of your page, which will give the browser instructions on how
to control the page's dimensions and scaling.
Here is an example of a web page without the viewport meta tag, and the same web
Responsive Images
Responsive images are images that scale nicely to fit any browser size.
If the CSS width property is set to 100%, the image will be responsive and scale up
and down: <img src="img_girl.jpg" style="max-width:100%;height:auto;">
The HTML <picture> element allows you to define different images for different
browser window sizes.
Resize the browser window to see how the image below change depending on the width:
Example
Notice that in the example above, the image can be scaled up to be larger than its
original size. A better solution, in many cases, will be to use the max-width property
instead.
If the max-width property is set to 100%, the image will scale down if it has to, but
never scale up to be larger than its original size:
Example Media Queries
In addition to resize text and images, it is also common to use media queries in
<picture> responsive web pages.
<source srcset="img_smallflower.jpg" media="(max-width:
600px)"> With media queries you can define completely different styles for different browser
<source srcset="img_flowers.jpg" media="(max-width: 1500px)"> sizes.
<source srcset="flowers.jpg">
<img src="img_smallflower.jpg" alt="Flowers"> Example: resize the browser window to see that the three div elements below will
</picture> display horizontally on large screens and stacked vertically on small screens:
Left Menu
The text size can be set with a "vw" unit, which means the "viewport width".
Right Content
That way the text size will follow the size of the browser window:
Hello World
Resize the browser window to see how the text size scales.
Example
Viewport is the browser window size. 1vw = 1% of viewport width. If the viewport is 50cm <style>
wide, 1vw is 0.5cm. .left, .right {
float: left;
width: 20%; /* The width is 20%, by default */
}
.main {
float: left; Example
width: 60%; /* The width is 60%, by default */
}
<code>
/* Use a media query to add a breakpoint at 800px: */
x = 5;
@media screen and (max-width: 800px) {
y = 6;
.left, .main, .right {
z = x + y;
width: 100%; /* The width is 100%, when the viewport is
</code>
800px or smaller */
}
}
</style>
Tip: To learn more about Media Queries and Responsive Web Design, read our RWD Tutorial. The HTML <kbd> element is used to define keyboard input. The
content inside is displayed in the browser's default monospace font.
Example
A responsive web page should look good on large desktop screens and on small mobile
phones. <p>Save the document by pressing <kbd>Ctrl + S</kbd></p>
Result:
HTML Computer Code Elements
HTML contains several elements for defining user input and computer
code.
HTML <samp> For Program Output The HTML <code> element is used to define a piece of computer code.
The content inside is displayed in the browser's default monospace
The HTML <samp> element is used to define sample output from a font.
computer program. The content inside is displayed in the browser's
default monospace font.
Example
Example
Define some text as computer code in a document:
Result:
Result:
File not found. Notice that the <code> element does not preserve extra whitespace
Press F1 to continue and line-breaks.
To fix this, you can put the <code> element inside a <pre> element:
Example
HTML <code> For Computer Code
<pre> The area of a triangle is: 1/2 x b x h, where b is the base, and h is the vertical
<code> height.
x = 5;
y = 6;
z = x + y;
</code>
</pre>
Chapter Summary
The HTML <var> element is used to define a variable in programming Tag Description
or in a mathematical expression. The content inside is typically <code> Defines programming code
displayed in italic.
<kbd> Defines keyboard input
<samp> Defines computer output
Example <var> Defines a variable
<pre> Defines preformatted text
For a complete list of all available HTML tags, visit our HTML Tag Reference.
<p>The area of a triangle is: 1/2 x <var>b</var> x <var>h</var>,
where <var>b</var> is the base, and <var>h</var> is the vertical
height.</p>
HTML Semantic Elements
Result:
Semantic elements = elements with a meaning.
Examples of semantic elements: <form>, <table>, and <article> - HTML <section> Element
Clearly defines its content.
The <section> element defines a section in a document.
<section> <article>
<h1>WWF's Panda symbol</h1> <h2>Mozilla Firefox</h2>
<p>The Panda has become the symbol of WWF. The well-known panda <p>Mozilla Firefox is an open-source web browser developed by
logo of WWF originated from a panda named Chi Chi that was Mozilla. Firefox has been the second most popular web browser
transferred from the Beijing Zoo to the London Zoo in the same since January, 2018.</p>
year of theestablishment of WWF.</p> </article>
</section>
<article>
HTML <article> Element <h2>Microsoft Edge</h2>
<p>Microsoft Edge is a web browser developed by Microsoft,
The <article> element specifies independent, self-contained content. released in 2015. Microsoft Edge replaced Internet
Explorer.</p>
An article should make sense on its own, and it should be possible to </article>
distribute it independently from the rest of the web site.
Forum posts
Blog posts
User comments Use CSS to style the <article> element:
Product cards
Newspaper articles
<html>
<head>
<style>
.all-browsers {
margin: 0;
padding: 5px;
Example
background-color: lightgray;
}
Three articles with independent, self-contained content: .all-browsers > h1, .browser {
margin: 10px;
padding: 5px;
}
<article>
<h2>Google Chrome</h2> .browser {
background: white; The <article> element specifies independent, self-contained content.
}
The <section> element defines section in a document.
.browser > h2, p {
margin: 4px; Can we use the definitions to decide how to nest those elements? No,
font-size: 90%; we cannot!
}
</style>
</head> So, you will find HTML pages with <section> elements
<body> containing <article> elements, and <article> elements
containing <section> elements.
<article class="all-browsers">
<h1>Most Popular Browsers</h1>
<article class="browser">
<h2>Google Chrome</h2>
HTML <header> Element
<p>Google Chrome is a web browser developed by Google,
released in 2008. Chrome is the world's most popular web
browser today!</p> The <header> element represents a container for introductory content
</article> or a set of navigational links.
<article class="browser">
<h2>Mozilla Firefox</h2> A <header> element typically contains:
<p>Mozilla Firefox is an open-source web browser developed
by Mozilla. Firefox has been the second most popular web one or more heading elements (<h1> - <h6>)
browser since January, 2018.</p> logo or icon
</article> authorship information
<article class="browser">
<h2>Microsoft Edge</h2>
<p>Microsoft Edge is a web browser developed by Microsoft, Note: You can have several <header> elements in one HTML
released in 2015. Microsoft Edge replaced Internet document. However, <header> cannot be placed within
Explorer.</p> a <footer>, <address> or another <header> element.
</article>
</article>
Example
</body>
</html>
A header for an <article>:
<article>
<header>
<h1>What Does WWF Do?</h1>
Nesting <article> in <section> or Vice Versa? <p>WWF's mission:</p>
</header> HTML <nav> Element
<p>WWF's mission is to stop the degradation of our planet's
natural environment, The <nav> element defines a set of navigation links.
and build a future in which humans live in harmony with
nature.</p>
</article>
Notice that NOT all links of a document should be inside a <nav> element.
The <nav> element is intended only for major block of navigation links.
HTML <footer> Element Browsers, such as screen readers for disabled users, can use this element
to determine whether to omit the initial rendering of this content.
The <footer> element defines a footer for a document or section.
authorship information
copyright information
contact information A set of navigation links:
sitemap
back to top links
related documents
<nav>
<a href="/html/">HTML</a> |
You can have several <footer> elements in one document. <a href="/css/">CSS</a> |
<a href="/js/">JavaScript</a> |
<a href="/jquery/">jQuery</a>
Example </nav>
<footer> The <aside> element defines some content aside from the content it
<p>Author: Hege Refsnes</p> is placed in (like a sidebar).
<p><a href="mailto:hege@example.com">hege@example.com</a></p
> The <aside> content should be indirectly related to the surrounding
</footer> content.
Example
Display some content aside from the content it is placed in:
<aside>
<p>My family and I visited The Epcot center this summer. The <p>The Epcot center is a theme park at Walt Disney World
weather was nice, and Epcot was amazing! I had a great summer Resort featuring exciting attractions, international
together with my family!</p> pavilions, award-winning fireworks and seasonal special
events.</p>
</aside>
<aside>
<h4>Epcot Center</h4>
<p>Epcot is a theme park at Walt Disney World Resort featuring <p>My family and I visited The Epcot center this summer. The
exciting attractions, international pavilions, award-winning weather was nice, and Epcot was amazing! I had a great summer
fireworks and seasonal special events.</p> together with my family!</p>
</aside> <p>My family and I visited The Epcot center this summer. The
weather was nice, and Epcot was amazing! I had a great summer
together with my family!</p>
Example 2
</body>
</html>
Use CSS to style the <aside> element:
</head>
<body>
<p>My family and I visited The Epcot center this summer. The
weather was nice, and Epcot was amazing! I had a great summer
together with my family!</p>
Example For a complete list of all available HTML tags, visit our HTML Tag Reference.
A consistent, clean, and tidy HTML code makes it easier for others to
read and understand your code.
According to the W3C: "A semantic Web allows data to be shared and
reused across applications, enterprises, and communities."
Always declare the document type as the first line in your document.
Semantic Elements in HTML
The correct document type for HTML is:
Below is a list of some of the semantic elements in HTML.
<!DOCTYPE html>
Tag Description
<article> Defines independent, self-contained content
<aside> Defines content aside from the page content
<details> Defines additional details that the user can view or hide
Use Lowercase Element Names
<figcaption> Defines a caption for a <figure> element
<figure> Specifies self-contained content, like illustrations, diagrams, photos, code listings, etc.
<footer> Defines a footer for a document or section
HTML allows mixing uppercase and lowercase letters in element
<header> Specifies a header for a document or section
names.
<main> Specifies the main content of a document
<mark> Defines marked/highlighted text
However, we recommend using lowercase element names, because:
<nav> Defines navigation links
<section> Defines a section in a document Mixing uppercase and lowercase names looks bad
<summary> Defines a visible heading for a <details> element Developers normally use lowercase names
<time> Defines a date/time Lowercase looks cleaner
Lowercase is easier to write
Good:
Good: Bad:
<table class="striped">
Bad:
Bad:
<img src="html5.gif">
<table class=striped>
Good:
<table class=table striped>
Always specify the alt attribute for images. This attribute is important
if the image for some reason cannot be displayed. <link rel = "stylesheet" href = "styles.css">
Also, always define the width and height of images. This reduces
flickering, because the browser can reserve space for the image
before loading.
When using an HTML editor, it is NOT convenient to scroll right and left
to read the HTML code.
Try to avoid too long code lines. <body>
<h1>Famous Cities</h1>
<h2>Tokyo</h2><p>Tokyo is the capital of Japan, the center of
the Greater Tokyo Area, and the most populous metropolitan area
in the world.</p>
<h2>London</h2><p>London is the capital city of England. It is
Blank Lines and Indentation
the most populous city in the United Kingdom.</p>
<h2>Paris</h2><p>Paris is the capital of France. The Paris area
Do not add blank lines, spaces, or indentations without a reason. is one of the largest population centers in Europe.</p>
</body>
For readability, add blank lines to separate large or logical code
blocks.
Good Table Example:
For readability, add two spaces of indentation. Do not use the tab key.
<table>
Good: <tr>
<th>Name</th>
<th>Description</th>
<body> </tr>
<tr>
<td>A</td>
<h1>Famous Cities</h1> <td>Description of A</td>
</tr>
<h2>Tokyo</h2> <tr>
<p>Tokyo is the capital of Japan, the center of the Greater <td>B</td>
Tokyo Area, and the most populous metropolitan area in the <td>Description of B</td>
world.</p> </tr>
</table>
<h2>London</h2>
<p>London is the capital city of England. It is the most
populous city in the United Kingdom.</p> Good List Example:
<h2>Paris</h2>
<ul>
<p>Paris is the capital of France. The Paris area is one of the
<li>London</li>
largest population centers in Europe.</p>
<li>Paris</li>
<li>Tokyo</li>
</body> </ul>
Bad:
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
defines a title in the browser toolbar The HTML <head> tag can also be omitted.
provides a title for the page when it is added to favorites
displays a title for the page in search-engine results Browsers will add all elements before <body>, to a
default <head> element.
So, try to make the title as accurate and meaningful as possible:
<!DOCTYPE html>
<html>
Omitting <html> and <body>? <title>Page Title</title>
<body>
An HTML page will validate without the <html> and <body> tags:
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
Example
</body>
</html>
<!DOCTYPE html>
<head> However, we recommend using the <head> tag.
<title>Page Title</title>
</head>
Close Empty HTML Elements? <p>This is a paragraph.</p>
Allowed:
You should always include the lang attribute inside the <html> tag, to Setting The Viewport
declare the language of the Web page. This is meant to assist search
engines and browsers. The viewport is the user's visible area of a web page. It varies with the
device - it will be smaller on a mobile phone than on a computer
screen.
Example
You should include the following <meta> element in all your web
pages:
<!DOCTYPE html>
<html lang="en-us">
<meta name="viewport" content="width=device-width, initial-
<head>
scale=1.0">
<title>Page Title</title>
</head>
<body> This gives the browser instructions on how to control the page's
dimensions and scaling.
<h1>This is a heading</h1>
The width=device-width part sets the width of the page to follow the
screen-width of the device (which will vary depending on the device).
The initial-scale=1.0 part sets the initial zoom level when the page
is first loaded by the browser.
Here is an example of a web page without the viewport meta tag, and
the same web page with the viewport meta tag:
Tip: If you are browsing this page with a phone or a tablet, you can click on the
two links below to see the difference.
HTML Comments
Comments that spans more than one line, should be written like this:
<!--
This is a long comment example. This is a long comment
example.
Without the viewport meta tag
This is a long comment example. This is a long comment Loading JavaScript in HTML
example.
--> Use simple syntax for loading external scripts (the type attribute is
not necessary):
Long comments are easier to observe if they are indented with two
spaces. <script src="myscript.js">
Use simple syntax for linking to style sheets (the type attribute is not Using "untidy" HTML code can result in JavaScript errors.
necessary):
These two JavaScript statements will produce different results:
<link rel="stylesheet" href="styles.css">
p.intro {font-family:Verdana;font-size:16em;}
getElementById("Demo").innerHTML = "Hello";
Long CSS rules should be written over multiple lines:
getElementById("demo").innerHTML = "Hello";
body {
background-color: lightgrey;
Visit the JavaScript Style Guide.
font-family: "Arial Black", Helvetica, sans-serif;
font-size: 16em;
color: black;
}
Place the opening bracket on the same line as the selector Use Lower Case File Names
Use one space before the opening bracket
Use two spaces of indentation Some web servers (Apache, Unix) are case sensitive about file names:
Use semicolon after each property-value pair, including the "london.jpg" cannot be accessed as "London.jpg".
last
Only use quotes around values if the value contains spaces Other web servers (Microsoft, IIS) are not case sensitive: "london.jpg"
Place the closing bracket on a new line, without leading can be accessed as "London.jpg".
spaces
If you use a mix of uppercase and lowercase, you have to be aware of
this.
If you move from a case-insensitive to a case-sensitive server, even However, servers can be configured with more than one default
small errors will break your web! filename; usually you can set up as many default filenames as you
want.
To avoid these problems, always use lowercase file names!
File Extensions
HTML files should have a .html extension (.htm is allowed). A consistent, clean, and tidy HTML code makes it easier for others to
read and understand your code.
CSS files should have a .css extension.
Here are some guidelines and tips for creating good HTML code.
JavaScript files should have a .js extension.
Default Filenames
Use Lowercase Element Names
When a URL does not specify a filename at the end (like
"https://www.w3schools.com/"), the server just adds a default HTML allows mixing uppercase and lowercase letters in element
filename, such as "index.html", "index.htm", "default.html", or names.
"default.htm".
However, we recommend using lowercase element names, because:
If your server is configured only with "index.html" as the default
filename, your file must be named "index.html", and not
"default.html". Mixing uppercase and lowercase names looks bad
Developers normally use lowercase names
Lowercase looks cleaner
Lowercase is easier to write
Good: Bad:
<body> <section>
<p>This is a paragraph.</p> <p>This is a paragraph.
</body>
<p>This is a paragraph.
Bad: </section>
<BODY>
<P>This is a paragraph.</P>
</BODY> Use Lowercase Attribute Names
Close All HTML Elements However, we recommend using lowercase attribute names, because:
In HTML, you do not have to close all elements (for example Mixing uppercase and lowercase names looks bad
the <p> element). Developers normally use lowercase names
Lowercase look cleaner
However, we strongly recommend closing all HTML elements, like this: Lowercase are easier to write
Good: Good:
HTML allows attribute values without quotes. Always specify the alt attribute for images. This attribute is important
if the image for some reason cannot be displayed.
However, we recommend quoting attribute values, because:
Also, always define the width and height of images. This reduces
Developers normally quote attribute values flickering, because the browser can reserve space for the image
Quoted values are easier to read before loading.
You MUST use quotes if the value contains spaces
Good:
Good:
Bad: Bad:
Very bad:
Spaces and Equal Signs
This will not work, because the value contains spaces: HTML allows spaces around equal signs. But space-less is easier to
read and groups entities better together.
<h2>Paris</h2>
<p>Paris is the capital of France. The Paris area is one of the
largest population centers in Europe.</p>
Avoid Long Code Lines
</body>
When using an HTML editor, it is NOT convenient to scroll right and left
to read the HTML code.
Bad:
Try to avoid too long code lines.
<body>
<h1>Famous Cities</h1>
<h2>Tokyo</h2><p>Tokyo is the capital of Japan, the center of
Blank Lines and Indentation the Greater Tokyo Area, and the most populous metropolitan
area in the world.</p>
Do not add blank lines, spaces, or indentations without a reason. <h2>London</h2><p>London is the capital city of England. It is
the most populous city in the United Kingdom.</p>
For readability, add blank lines to separate large or logical code <h2>Paris</h2><p>Paris is the capital of France. The Paris
blocks. area is one of the largest population centers in Europe.</p>
</body>
For readability, add two spaces of indentation. Do not use the tab key.
<table>
<body> <tr>
<th>Name</th>
<th>Description</th>
<h1>Famous Cities</h1> </tr>
<tr>
<td>A</td>
<h2>Tokyo</h2>
<td>Description of A</td>
</tr> Omitting <html> and <body>?
<tr>
<td>B</td> An HTML page will validate without the <html> and <body> tags:
<td>Description of B</td>
</tr>
</table>
<ul>
<li>London</li> <!DOCTYPE html>
<li>Paris</li> <head>
<li>Tokyo</li> <title>Page Title</title>
</ul> </head>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
Never Skip the <title> Element However, we strongly recommend to always add
the <html> and <body> tags!
The <title> element is required in HTML.
Omitting <body> can produce errors in older browsers.
The contents of a page title is very important for search engine
optimization (SEO)! The page title is used by search engine algorithms Omitting <html> and <body> can also crash DOM and XML software.
to decide the order when listing pages in search results.
So, try to make the title as accurate and meaningful as possible: Browsers will add all elements before <body>, to a
default <head> element.
<title>HTML Style Guide and Coding Conventions</title>
Example
<!DOCTYPE html> You should always include the lang attribute inside the <html> tag, to
<html> declare the language of the Web page. This is meant to assist search
<title>Page Title</title> engines and browsers.
<body>
<h1>This is a heading</h1>
Close Empty HTML Elements? <p>This is a paragraph.</p>
Allowed:
This gives the browser instructions on how to control the page's Using Style Sheets
dimensions and scaling.
Use simple syntax for linking to style sheets (the type attribute is not
The width=device-width part sets the width of the page to follow the necessary):
screen-width of the device (which will vary depending on the device).
<link rel="stylesheet" href="styles.css">
The initial-scale=1.0 part sets the initial zoom level when the page
is first loaded by the browser. Short CSS rules can be written compressed, like this:
Here is an example of a web page without the viewport meta tag, and p.intro {font-family:Verdana;font-size:16em;}
the same web page with the viewport meta tag:
Long CSS rules should be written over multiple lines:
body {
Tip: If you are browsing this page with a phone or a tablet, you can click on the
background-color: lightgrey;
two links below to see the difference.
font-family: "Arial Black", Helvetica, sans-serif;
font-size: 16em;
color: black;
}
Loading JavaScript in HTML If you move from a case-insensitive to a case-sensitive server, even
small errors will break your web!
Use simple syntax for loading external scripts (the type attribute is
not necessary): To avoid these problems, always use lowercase file names!
<script src="myscript.js">
File Extensions
Accessing HTML Elements with JavaScript HTML files should have a .html extension (.htm is allowed).
Using "untidy" HTML code can result in JavaScript errors. CSS files should have a .css extension.
These two JavaScript statements will produce different results: JavaScript files should have a .js extension.
Example
Default Filenames
Use Lower Case File Names
When a URL does not specify a filename at the end (like
Some web servers (Apache, Unix) are case sensitive about file names: "https://www.w3schools.com/"), the server just adds a default
"london.jpg" cannot be accessed as "London.jpg". filename, such as "index.html", "index.htm", "default.html", or
"default.htm".
Other web servers (Microsoft, IIS) are not case sensitive: "london.jpg"
can be accessed as "London.jpg". If your server is configured only with "index.html" as the default
filename, your file must be named "index.html", and not
"default.html".
However, servers can be configured with more than one default Advantage of using an entity name: An entity name is easy to remember.
filename; usually you can set up as many default filenames as you Disadvantage of using an entity name: Browsers may not support all entity
want. names, but the support for entity numbers is good.
HTML Entities
Non-breaking Space
Reserved characters in HTML must be replaced with character entities.
A commonly used entity in HTML is the non-breaking space:
A non-breaking space is a space that will not break into a new line.
If you use the less than (<) or greater than (>) signs in your text, the § 10
browser might mix them with tags. 10 km/h
10 PM
Character entities are used to display reserved characters in HTML.
Another common use of the non-breaking space is to prevent browsers
A character entity looks like this: from truncating spaces in HTML pages.
&entity_name; If you write 10 spaces in your text, the browser will remove 9 of them.
To add real spaces to your text, you can use the character
entity.
OR
Tip: The non-breaking hyphen (‑) is used to define a hyphen
character (-) that does not break into a new line.
&#entity_number;
To display a less than sign (<) we must write: < or < Some Useful HTML Character Entities
Result Description Entity Name Entity
Number
non-breaking space  
< less than < <
> greater than > >
Note: Entity names are case sensitive. & ampersand & &
" double quotation mark " "
' single quotation mark ' '
(apostrophe)
¢ cent ¢ ¢
£ pound £ £
¥ yen ¥ ¥
Combining Diacritical Marks € euro € €
© copyright © ©
A diacritical mark is a "glyph" added to a letter. ® registered trademark ® ®
Some diacritical marks, like grave ( ̀) and acute ( ́) are called accents.
HTML Symbols
Diacritical marks can appear both above and below a letter, inside a
letter, and between two letters.
You will see more HTML symbols in the next chapter of this tutorial.
Example
Display the euro sign, €, with an entity name, a decimal, and a hexadecimal
value:
I will display €
I will display € Full Greek Reference
I will display €
This is specified in the <meta> tag: The <meta charset="UTF-8"> element defines the character set.
<meta charset="UTF-8"> The characters A, B, and C, are displayed by the numbers 65, 66, and
67.
To let the browser understand that you are displaying a character, you
If not specified, UTF-8 is the default character set in HTML. must start the entity number with &# and end it with ; (semicolon).
Emoji Characters
<body>
<h1>Sized Emojis</h1>
Example
<p style="font-size:48px">
😀 😄 😍 💗
<!DOCTYPE html> </p>
<html>
<head> </body>
<meta charset="UTF-8"> </html>
</head>
<body>
<p>😀</p>
Emoji Value
</body>
🗻
</html>
🗼
Since Emojis are characters, they can be copied, displayed, and sized 🗽
just like any other character in HTML. 🗾
🗿
Example 😀
😁
😂
<!DOCTYPE html> 😃
<html>
<head> 😄
<meta charset="UTF-8"> 😅
For a full list, please go to our HTML Emoji Reference. This is specified in the <meta> tag:
<meta charset="UTF-8">
ISO-8859-1 was the default character set for HTML 4. This character 38 & & & & ampersand
set supported 256 different character codes. HTML 4 also supported 39 ' ' ' ' apostrophe
UTF-8. 40 ( ( ( ( left parenthesis
ANSI (Windows-1252) was the original Windows character set. ANSI is 41 ) ) ) ) right parenthesis
identical to ISO-8859-1, except that ANSI has 32 extra characters.
42 * * * * asterisk
The HTML5 specification encourages web developers to use the UTF-8 43 + + + + plus sign
character set, which covers almost all of the characters and symbols
44 , , , , comma
in the world!
45 - - - - hyphen-minus
46 . . . . full stop
47 / / / / solidus
48 0 0 0 0 digit zero
The HTML charset Attribute
49 1 1 1 1 digit one
50 2 2 2 2 digit two
To display an HTML page correctly, a web browser must know the
character set used in the page. 51 3 3 3 3 digit three
52 4 4 4 4 digit four 72 H H H H Latin capital letter H
53 5 5 5 5 digit five
54 6 6 6 6 digit six
55 7 7 7 7 digit seven 73 I I I I Latin capital letter I
56 8 8 8 8 digit eight 74 J J J J Latin capital letter J
57 9 9 9 9 digit nine 75 K K K K Latin capital letter K
58 : : : : colon 76 L L L L Latin capital letter L
59 ; ; ; ; semicolon 77 M M M M Latin capital letter M
60 < < < < less-than sign 78 N N N N Latin capital letter N
79 O O O O Latin capital letter O
61 = = = = equals sign 80 P P P P Latin capital letter P
62 > > > > greater-than sign 81 Q Q Q Q Latin capital letter Q
82 R R R R Latin capital letter R
63 ? ? ? ? question mark
83 S S S S Latin capital letter S
84 T T T T Latin capital letter T
64 @ @ @ @ commercial at
85 U U U U Latin capital letter U
65 A A A A Latin capital letter A 86 V V V V Latin capital letter V
87 W W W W Latin capital letter W
88 X X X X Latin capital letter X
66 B B B B Latin capital letter B 89 Y Y Y Y Latin capital letter Y
90 Z Z Z Z Latin capital letter Z
91 [ [ [ [ left square bracket
67 C C C C Latin capital letter C 92 \ \ \ \ reverse solidus
93 ] ] ] ] right square bracket
94 ^ ^ ^ ^ circumflex accent
68 D D D D Latin capital letter D 95 _ _ _ _ low line
96 ` ` ` ` grave accent
97 a a a a Latin small letter a
69 E E E E Latin capital letter E
98 b b b b Latin small letter b
99 c c c c Latin small letter c
70 F F F F Latin capital letter F 100 d d d d Latin small letter d
101 e e e e Latin small letter e
102 f f f f Latin small letter f
71 G G G G Latin capital letter G 103 g g g g Latin small letter g
104 h h h h Latin small letter h
105 i i i i Latin small letter i
106 j j j j Latin small letter j
107 k k k k Latin small letter k
108 l l l l Latin small letter l 141 NOT USED
109 m m m m Latin small letter m 142 Ž Latin capital letter Z with
110 n n n n Latin small letter n caron
111 o o o o Latin small letter o 143 NOT USED
112 p p p p Latin small letter p 144 NOT USED
113 q q q q Latin small letter q 145 ‘ left single quotation mark
114 r r r r Latin small letter r 146 ’ right single quotation mark
115 s s s s Latin small letter s 147 “ left double quotation mark
116 t t t t Latin small letter t 148 ” right double quotation
mark
117 u u u u Latin small letter u
149 • bullet
118 v v v v Latin small letter v
150 – en dash
119 w w w w Latin small letter w
151 — em dash
120 x x x x Latin small letter x
152 ˜ small tilde
121 y y y y Latin small letter y
153 ™ trade mark sign
122 z z z z Latin small letter z
154 š Latin small letter s with
123 { { { { left curly bracket
caron
124 | | | | vertical line 155 › single right-pointing angle
125 } } } } right curly bracket quotation mark
126 ~ ~ ~ ~ tilde 156 œ Latin small ligature oe
127 DEL 157 NOT USED
128 € euro sign 158 ž Latin small letter z with
129 NOT USED caron
130 ‚ single low-9 quotation 159 Ÿ Latin capital letter Y with
mark diaeresis
131 ƒ Latin small letter f with 160 no-break space
hook 161 ¡ ¡ ¡ inverted exclamation mark
132 „ double low-9 quotation 162 ¢ ¢ ¢ cent sign
mark 163 £ £ £ pound sign
133 … horizontal ellipsis 164 ¤ ¤ ¤ currency sign
134 † dagger 165 ¥ ¥ ¥ yen sign
135 ‡ double dagger 166 ¦ ¦ ¦ broken bar
136 ˆ modifier letter circumflex 167 § § § section sign
accent
168 ¨ ¨ ¨ diaeresis
137 ‰ per mille sign
169 © © © copyright sign
138 Š Latin capital letter S with
caron 170 ª ª ª feminine ordinal indicator
139 ‹ single left-pointing angle 171 « « « left-pointing double angle
quotation mark quotation mark
140 Œ Latin capital ligature OE 172 ¬ ¬ ¬ not sign
173 soft hyphen circumflex
174 ® ® ® registered sign 203 Ë Ë Ë Latin capital letter E with
175 ¯ ¯ ¯ macron diaeresis
176 ° ° ° degree sign 204 Ì Ì Ì Latin capital letter I with
grave
177 ± ± ± plus-minus sign
205 Í Í Í Latin capital letter I with
178 ² ² ² superscript two acute
179 ³ ³ ³ superscript three 206 Î Î Î Latin capital letter I with
180 ´ ´ ´ acute accent circumflex
181 µ µ µ micro sign 207 Ï Ï Ï Latin capital letter I with
182 ¶ ¶ ¶ pilcrow sign diaeresis
183 · · · middle dot 208 Ð Ð Ð Latin capital letter Eth
184 ¸ ¸ ¸ cedilla 209 Ñ Ñ Ñ Latin capital letter N with
tilde
185 ¹ ¹ ¹ superscript one
210 Ò Ò Ò Latin capital letter O with
186 º º º masculine ordinal indicator grave
187 » » » right-pointing double angle 211 Ó Ó Ó Latin capital letter O with
quotation mark acute
188 ¼ ¼ ¼ vulgar fraction one quarter 212 Ô Ô Ô Latin capital letter O with
189 ½ ½ ½ vulgar fraction one half circumflex
190 ¾ ¾ ¾ vulgar fraction three 213 Õ Õ Õ Latin capital letter O with
quarters tilde
191 ¿ ¿ ¿ inverted question mark 214 Ö Ö Ö Latin capital letter O with
192 À À À Latin capital letter A with diaeresis
grave 215 × × × multiplication sign
193 Á Á Á Latin capital letter A with 216 Ø Ø Ø Latin capital letter O with
acute stroke
194 Â Â Â Latin capital letter A with 217 Ù Ù Ù Latin capital letter U with
circumflex grave
195 Ã Ã Ã Latin capital letter A with 218 Ú Ú Ú Latin capital letter U with
tilde acute
196 Ä Ä Ä Latin capital letter A with 219 Û Û Û Latin capital letter U with
diaeresis circumflex
197 Å Å Å Latin capital letter A with 220 Ü Ü Ü Latin capital letter U with
ring above diaeresis
198 Æ Æ Æ Latin capital letter AE 221 Ý Ý Ý Latin capital letter Y with
199 Ç Ç Ç Latin capital letter C with acute
cedilla 222 Þ Þ Þ Latin capital letter Thorn
200 È È È Latin capital letter E with 223 ß ß ß Latin small letter sharp s
grave 224 à à à Latin small letter a with
201 É É É Latin capital letter E with grave
acute 225 á á á Latin small letter a with
202 Ê Ê Ê Latin capital letter E with
acute stroke
226 â â â Latin small letter a with 249 ù ù ù Latin small letter u with
circumflex grave
227 ã ã ã Latin small letter a with 250 ú ú ú Latin small letter u with
tilde acute
228 ä ä ä Latin small letter a with 251 û û û Latin small letter with
diaeresis circumflex
229 å å å Latin small letter a with 252 ü ü ü Latin small letter u with
ring above diaeresis
230 æ æ æ Latin small letter ae 253 ý ý ý Latin small letter y with
231 ç ç ç Latin small letter c with acute
cedilla 254 þ þ þ Latin small letter thorn
232 è è è Latin small letter e with 255 ÿ ÿ ÿ Latin small letter y with
grave diaeresis
233 é é é Latin small letter e with
acute
234 ê ê ê Latin small letter e with
circumflex
235 ë ë ë Latin small letter e with
diaeresis
236 ì ì ì Latin small letter i with
The ASCII Character Set
grave
237 í í í Latin small letter i with
acute ASCII uses the values from 0 to 31 (and 127) for control characters.
238 î î î Latin small letter i with
circumflex ASCII uses the values from 32 to 126 for letters, digits, and symbols.
239 ï ï ï Latin small letter i with
diaeresis ASCII does not use the values from 128 to 255.
240 ð ð ð Latin small letter eth
241 ñ ñ ñ Latin small letter n with
tilde
242 ò ò ò Latin small letter o with
grave The ANSI Character Set (Windows-1252)
243 ó ó ó Latin small letter o with
acute ANSI is identical to ASCII for the values from 0 to 127.
244 ô ô ô Latin small letter o with
circumflex
ANSI has a proprietary set of characters for the values from 128 to
245 õ õ õ Latin small letter o with
159.
tilde
246 ö ö ö Latin small letter o with
diaeresis ANSI is identical to UTF-8 for the values from 160 to 255.
247 ÷ ÷ ÷ division sign
248 ø ø ø Latin small letter o with
Most people enter the name when surfing, because names are easier
to remember than numbers.
A web address
The UTF-8 Character Set like https://www.w3schools.com/html/default.asp follows these syntax
rules:
UTF-8 is identical to ASCII for the values from 0 to 127.
scheme://prefix.domain:port/path/filename
UTF-8 does not use the values from 128 to 159.
Explanation:
UTF-8 is identical to both ANSI and 8859-1 for the values from 160 to
255. scheme - defines the type of Internet service (most common
is http or https)
UTF-8 continues from the value 256 with more than 10 000 different prefix - defines a domain prefix (default for http is www)
characters. domain - defines the Internet domain name (like
w3schools.com)
For a closer look, study our Complete HTML Character Set Reference. port - defines the port number at the host (default for http
is 80)
path - defines a path at the server (If omitted: the root
directory of the site)
filename - defines the name of a document or resource
HTML Uniform Resource Locators
If you click "Submit", the browser will URL encode the input before it is
sent to the server.
HTML Versus XHTML
A page at the server will display the received input.
XHTML is a stricter, more XML-based version of HTML.
Try some other input and click Submit again.
What is XHTML?
XHTML stands for EXtensible HyperText Markup Language An XHTML document must have an XHTML <!DOCTYPE> declaration.
XHTML is a stricter, more XML-based version of HTML
XHTML is HTML defined as an XML application The <html>, <head>, <title>, and <body> elements must also be
XHTML is supported by all major browsers present, and the xmlns attribute in <html> must specify the xml
namespace for the document.
Example
Why XHTML?
Wrong:
<b><i>Some text</b></i>
A break: <br>
A horizontal rule: <hr>
XHTML Elements Must Always be Closed An image: <img src="happy.gif" alt="Happy face">
Wrong:
<body>
<p>This is a paragraph</p>
<p>This is a paragraph </body>
<p>This is another paragraph
<BODY>
Correct:
<P>This is a paragraph</P>
</BODY>
Wrong:
Correct:
XHTML Attribute Minimization is Forbidden
Correct:
Wrong:
Wrong:
Correct: