Web designWD-unit1+2
Web designWD-unit1+2
Having a simple clear intention on all pages will help the user interact with what
you have to offer.
There are many different purposes that websites may have but there are core
purposes common to all websites;
1. Describing Expertise
2. Building Your Reputation
3. Generating Leads
4. Sales and After Care
2. SIMPLICITY
Simplicity is the best way to go when considering the user experience and the
usability of your website.
All imagery should be expressive and capture the spirit of the company and act as
the embodiment of their brand personality.
Navigation is the way finding system used on websites where visitors interact and
find what they are looking for.
If the websites navigation is confusing visitors will give up and find what they
need elsewhere.
The F- based pattern is the most common way visitors scan text on a website.
Eye tracking studies have found that most of what people see is in the top and
left area of the screen.
The F’ shaped layout mimics our natural pattern of reading in the West (left to
right and top to bottom).
6. CONTENT
An effective web design has both great design and great content.
Using compelling language great content can attract and influence visitors by
converting them into customers.
7. GRID BASED LAYOUT
Grids help to structure your design and keep your content organized.
The grid helps to align elements on the page and keep it clean.
The grid based layout arranges content into a clean rigid grid structure with
columns, sections that line up and feel balanced and impose order and results in
an aesthetically pleasing website.
8. LOAD TIME
Waiting for a website to load will lose visitors.
Nearly half of web visitors expect a site to load in 2 seconds or less and they will
potentially leave a site that isn’t loaded within 3 seconds.
Optimising image sizes will help load your site faster.
9. MOBILE FRIENDLY
More people are using their phones or other devices to browse the web.
Static Website:
The web pages are prebuilt and the Content of pages is same for all visitors.
For static web pages when a server receives a request for a web page, then
the server sends the response to the client without doing any additional
process hence static Websites are fast.
Also, they are less costly as the host does not need to support
server-side processing with different languages.
Note: Static does not mean that it will not respond to user
actions, These Websites are called static because these cannot
be manipulated on the server or interaction with databases
(which is the case in Dynamic Websites).
Dynamic Website:
It means they are not prebuilt web pages but they are built
according to the user’s demand with the help of server-side
scripting languages such as PHP, Node.js, ASP.NET and many
more supported by the server.
So, they are slower than static websites but updates and
interaction with databases are possible.
Dynamic Websites are used over Static Websites as updates can be
done very easily as compared to static websites (Where altering in
every page is required) but in Dynamic Websites, it is possible to do a
common change once and it will reflect in all the web pages.
Same content is delivered everytime the page is Content may change everytime the page is loaded.
2.
loaded.
3. Static Web Pages are simple in terms of complexity. Dynamic web pages are complicated.
Static web pages are written in languages such as: Dynamic web pages are written in languages such
9.
HTML, JavaScript, CSS, etc. as: CGI, AJAX, ASP, ASP.NET, etc.
What is a Domain Name?
Domain name is the address of your website that people type in the browser’s URL
bar to visit your website.
In other words, if your website was a house, then your domain name will be its
address. That’s really hard to memorize and type. Which is why a unique domain
name will be easier for users to remember and type.
It’s basically a string of recognizable words that, when typed in the browser, redirects
the user to your server IP.
You see, when a website is created, it often comes with a unique address known as a
Domain Name Servers (DNS) which often looks like this:
Yahoo.co.in
Xyz.org
Internet is basically a giant network of computers connected to each
other through cables and other medium.
To own your own domain, you will need to register your domain with a domain
registrar.
Web hosting refers to the company that rent out their computer/servers to
store your website and provide Internet connectivity so that other users can
access to the files on your website.
For most cases, these hosting companies will handle server maintenance
work, such as backup, root configuration, maintenance, disaster recoveries,
and so on.
All websites on the internet, need web hosting.
You can buy domain name and web hosting from two different
companies. However, in that case you will have to point your
domain name to your web hosting company by editing its DNS
settings.
How does Web Hosting Work?
Think of it as a house where you store all your stuffs; but instead of storing your
clothes and furniture, you store digital files (HTML, documents, images, videos,
etc) in a web host.
Usually, a web hosting company do more than just storing your website. Here
are some value-added services and features to expect from your hosting
provider:
• Domain registration – So you can buy and manage domain and hosting from
the same provider
• Website builder – Drag-and-drop web editing tool to create a website
• Email hosting – To send and receive emails from [email protected]
• Basic hardware (server setup) and software (CMS, server OS, etc) support.
Different Types of Web Host
While all types of servers will act as a storage center for your website, they differ
in the amount of storage capacity, control, technical knowledge requirement,
server speed, and reliability.
Shared Hosting: In shared hosting, one’s web site is placed on the same server as
many other sites, ranging from a few to hundreds or thousands.
Virtual Private Server (VPS) Hosting:A virtual private server hosting divides a
server into virtual servers, where each websites is like hosted on their own
dedicated server, but they’re actually sharing a server with a few different other
users.
Different Types of Web Host
Dedicated Server Hosting:A dedicated server offers the maximum control over
the web server your website is stored on – You exclusively rent an entire server.
Your website(s) is the only website stored on the server.
Cloud Hosting: Cloud hosting offers unlimited ability to handle high traffic or
traffic spikes. Here’s how it works: A team of servers (called a cloud) work
together to host a group of websites. This allows multiple computers to work
together to handle high traffic levels or spikes for any particular website.
Responsive Web Designing
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):
Setting The Viewport
When making responsive web pages, add the following <meta> element in all
your web pages:
This will set the viewport of your page, which will give the browser instructions
on how to control the page's dimensions and scaling.
Responsive Image
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:
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.
Using the max-width Property
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:
Resize the browser window to see how the image below change depending on the width:
<picture>
<source srcset="img_smallflower.jpg" media="(max-width: 600px)">
<source srcset="img_flowers.jpg" media="(max-width: 1500px)">
<source srcset="flowers.jpg">
<img src="img_smallflower.jpg" alt="Flowers">
</picture>
Responsive Text Size
• The text size can be set with a "vw" unit, which means the "viewport width".
• That way the text size will follow the size of the browser window:
Now, HTML is being widely used to format web pages with the
help of different tags available in HTML language.
• HTML is the standard markup language for creating Web pages.
• HTML tags label pieces of content such as "heading", "paragraph", "table", and so on
• Browsers do not display the HTML tags, but use them to render the content of the page
Basic HTML Document
<!DOCTYPE html>
<html>
<head>
<title>This is document title</title>
</head>
<body>
<h1>This is a heading</h1>
<p>Document content goes here.....</p>
</body>
</html>
let's save it in an HTML file test.htm using your favorite text editor.
Finally open it using a web browser like Internet Explorer or Google Chrome, or
Firefox etc.
HTML is a markup language and makes use of various tags to format the content.
The first tag in a pair is the start tag, the second tag is the end tag
The end tag is written like the start tag, but with a forward slash inserted before the tag name
Except few tags, most of the tags have their corresponding closing tags.
For example, <html> has its closing tag</html> and <body> tag has its closing tag </body> tag etc.
• We need to study various tags and understand how they behave, while
formatting a textual document.
• Learning HTML is simple as users have to learn the usage of different tags in
order to format the text or images to make a beautiful webpage.
• The purpose of a web browser (Chrome, Edge, Firefox, Safari) is to read HTML
documents and display them.
• The browser does not display the HTML tags, but uses them to determine how
to display the document:
HTML Document Structure
*Only the content inside the <body> section (the white area above) is displayed in a browser .
The <!DOCTYPE> Declaration
The <!DOCTYPE> declaration represents the document type, and helps
browsers to display web pages correctly.
It must only appear once, at the top of the page (before any HTML tags).
<!DOCTYPE html>
HTML Versions
Since the early days of the web, there have been many versions of
HTML:
Write HTML Using Notepad or
TextEdit
• Web pages can be created and modified by using professional HTML
editors.
• However, for learning HTML a simple text editor like Notepad (PC) or
TextEdit (Mac) is sufficient.
HTML Documents
All HTML documents must start with a document type declaration: <!DOCTYPE html>.
The HTML document itself begins with <html> and ends with </html>.
The visible part of the HTML document is between <body> and </body>.
<!DOCTYPE html>
<html>
<body>
</body>
</html>
HTML Headings
HTML headings are defined with the <h1> to <h6> tags.
<!DOCTYPE html>
<html>
<body>
<h1>This is heading 1</h1>
<h2>This is heading 2</h2>
<h3>This is heading 3</h3>
<h4>This is heading 4</h4>
<h5>This is heading 5</h5>
<h6>This is heading 6</h6>
</body>
</html>
HTML Paragraphs
HTML paragraphs are defined with the <p> tag:
<!DOCTYPE html>
<html>
<body>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
</body>
• </html> HTML Comment Tags
You can add comments to your HTML source by using the following syntax:
• <!-- Write your comments here -->
HTML Links
<!DOCTYPE html>
<html>
<body>
<h2>HTML Links</h2>
<p>HTML links are defined with the a tag:</p>
</body>
</html>
The source file (src), alternative text (alt), width, and height are provided as attributes:
<!DOCTYPE html>
<html>
<body>
<h2>HTML Images</h2>
<p>HTML images are defined with the img tag:</p>
</body>
</html>
HTML Buttons
HTML buttons are defined with the <button> tag:
<!DOCTYPE html>
<html>
<body>
<h2>HTML Buttons</h2>
<p>HTML buttons are defined with the button tag:</p>
<button>Click me</button>
</body>
</html>
HTML Lists
HTML lists are defined with the <ul> (unordered/bullet list) or the <ol> (ordered/numbered list) tag, followed by <li> tags
(list items):
<!DOCTYPE html>
<html>
<body>
<h2>An Unordered HTML List</h2>
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
<h2>An Ordered HTML List</h2>
<ol>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
</body>
HTML Elements
An HTML element usually consists of a start tag and an end tag, with
the content inserted in between:
<!DOCTYPE html>
<html>
<body>
</body>
</html>
The <html> element defines the whole document.
Inside the <body> element is two other HTML elements: <h1> and <p>.
The element content is: My First Heading. The <p> element defines a paragraph.
Some HTML elements will display correctly, even if you forget the end tag:
<!DOCTYPE html>
<html>
<body>
<p>This is a paragraph.
<p>This is a paragraph.
</body>
</html>
The example above works in all browsers, because the closing tag is considered optional.
Never rely on this. It might produce unexpected results and/or errors if you forget the end tag.
Empty HTML Elements
HTML elements with no content are called empty elements.
<br> is an empty element without a closing tag (the <br> tag defines a line break):
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Empty elements can be "closed" in the opening tag like this: <br />.
HTML5 does not require empty elements to be closed.
The HTML5 standard does not require lowercase tags, but W3C
recommends lowercase in HTML, and demands lowercase for stricter
document types like XHTML.
• HTML Attributes
• All HTML elements can have attributes
• Attributes provide additional information about an element
• Attributes are always specified in the start tag
• Attributes usually come in name/value pairs like: name="value"
The href Attribute
HTML links are defined with the <a> tag. The link address is specified in the href attribute:
<!DOCTYPE html>
<html>
<body>
</body>
</html>
You will learn more about links and the <a> tag later in this tutorial.
<!DOCTYPE html>
<html>
<body>
</body>
</html>
The width and height Attributes
HTML images also have width and height attributes, which specifies the width and height of the image:
<!DOCTYPE html>
<html>
<body>
<h2>Size Attributes</h2>
<p>Images in HTML have a set of size attributes, which specifies the width and height of the image:</p>
</body>
</html>
The width and height are specified in pixels by default; so width="500" means 500 pixels wide.
The alt Attribute
This way, someone "listening" to the webpage, e.g. a vision impaired person,
can "hear" the element.
<!DOCTYPE html>
<html>
<body>
</body>
</html>
The alt attribute is also useful if the image cannot be displayed (e.g. if it does
not exist):
<!DOCTYPE html>
<html>
<body>
<p>If we try to display an image that does not exist, the value of the alt attribute
will be displayed instead. </p>
</body>
</html>
The style Attribute
The style attribute is used to specify the styling of an element, like color, font, size etc.
<!DOCTYPE html>
<html>
<body>
</body>
</html>
The lang Attribute
Declaring a language is important for accessibility applications (screen readers) and search engines:
<!DOCTYPE html>
<html lang="en-US">
<body>
...
</body>
</html>
The title Attribute
The value of the title attribute will be displayed as a tooltip when you mouse
over the paragraph:
In some situations, when the attribute value itself contains double quotes, it is
necessary to use single quotes:
Search engines use the headings to index the structure and content of your
web pages.
<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
<!DOCTYPE html>
<html>
<body>
<h1 style="font-size:60px;">Heading 1</h1>
<p>You can change the size of a heading with the style attribute, using the font-size
property.</p>
</body>
</html>
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:
<!DOCTYPE html><html><body>
<h1>This is heading 1</h1>
<p>This is some text.</p>
<hr>
<h2>This is heading 2</h2>
<p>This is some other text.</p>
<hr>
<h2>This is heading 2</h2>
<p>This is some other text</p>
</body>
</html>
The HTML <head> Element
The HTML <head> element is a container for metadata.
HTML metadata is data about the HTML document.
Metadata is not displayed.
The <head> element is placed between the <html> tag and the <body> tag:
<!DOCTYPE html><html>
<head>
<title>My First HTML</title>
<meta charset="UTF-8">
</head>
<body>
<p>The HTML head element contains meta data.</p>
<p>Meta data is data about the HTML document.</p>
</body>
</html>
HTML Paragraphs
<!DOCTYPE html>
<html><body>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
</body></html>
Browsers automatically add some white space (a margin) before and after a
paragraph.
Most browsers will display HTML correctly even if you forget the end tag:
<!DOCTYPE html>
<html>
<body>
<p>This is a paragraph.
<p>This is a paragraph.
<p>This is a paragraph.
<p>Don't forget to close your HTML tags!</p>
</body>
</html>
The example above will work in most browsers, but do not rely on it. Dropping the end
tag can produce unexpected results or errors.
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:
<!DOCTYPE html>
<html>
<body>
<p>This is<br>a paragraph<br>with line breaks</p>
</body>
</html>
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:
<!DOCTYPE html><html><body><p>The pre tag preserves both spaces and line breaks:</p>
<pre>
My Bonnie lies over the ocean.
<tagname style="property:value;">
The CSS background-color property defines the background color for an HTML
element.
This example sets the background color for a page to powderblue:
<!DOCTYPE html>
<html>
<body style="background-color:powderblue;">
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
The CSS color property defines the text color for an HTML element:
<!DOCTYPE html><html><body>
<h1 style="font-family:verdana;">This is a heading</h1>
<p style="font-family:courier;">This is a paragraph.</p>
</body></html>
The CSS font-size property defines the text size for an HTML element:
The CSS text-align property defines the horizontal text alignment for an HTML element:
HTML also defines special elements for defining text with a special meaning.
HTML uses elements like <b> and <i> for formatting output, like bold or italic text.
The HTML <strong> element defines strong text, with added semantic "strong"
importance.
<strong>This text is strong</strong>
The HTML <i> element defines italic text, without any extra importance.
The HTML <em> element defines emphasized text, with added semantic importance.
<em>This text is emphasized</em>
<p>WWF's goal is to: <q>Build a future where people live in harmony with
nature.</q></p>
The HTML <abbr> element defines an abbreviation or an acronym.
The <address> element is usually displayed in italic. Most browsers will add a line
break before and after the element.
<address>
Written by John Doe.<br>
Visit us at:<br>
Example.com<br>
Box 564, Disneyland<br>
USA
</address>
Notice that there is an exclamation point (!) in the opening tag, but not in the closing tag.
Comments are not displayed by the browser, but they can help document your HTML source code.
With comments you can place notifications and reminders in your HTML:
<!-- This is a comment --><p>This is a paragraph.</p>
<!-- Remember to add more information here -->
Comments are also great for debugging HTML, because you can comment out HTML lines of code, one
at a time, to search for errors:
<!-- Do not display this image at the moment <img border="0" src="pic_trulli.jpg" alt="Trulli">
-->
HTML Colors
HTML colors are specified using predefined color names, or RGB, HEX, HSL, RGBA, HSLA values.
<!DOCTYPE html><html><body>
<h1 style="background-color:Tomato;">Tomato</h1>
<h1 style="background-color:Orange;">Orange</h1>
<h1 style="background-color:DodgerBlue;">DodgerBlue</h1>
<h1 style="background-color:MediumSeaGreen;">MediumSeaGreen</h1>
<h1 style="background-color:Gray;">Gray</h1>
<h1 style="background-color:SlateBlue;">SlateBlue</h1>
<h1 style="background-color:Violet;">Violet</h1>
<h1 style="background-color:LightGray;">LightGray</h1>
</body></html>
You can set the color of borders:
In HTML, colors can also be specified using RGB values, HEX values, HSL values, RGBA values, and
HSLA values:
Each parameter (red, green, and blue) defines the intensity of the color between 0 and 255.
For example, rgb(255, 0, 0) is displayed as red, because red is set to its highest value (255) and
the others are set to 0.
To display black, set all color parameters to 0, like this: rgb(0, 0, 0).
To display white, set all color parameters to 255, like this: rgb(255, 255, 255).
<p>By using equal values for red, green, and blue, you will get different shades of gray.</p>
</body>
</html>
RGBA Value
RGBA color values are an extension of RGB color values with an alpha channel - which specifies the opacity for a color.
The alpha parameter is a number between 0.0 (fully transparent) and 1.0 (not transparent at all):
<!DOCTYPE html><html><body>
<p>You can make transparent colors by using the RGBA color value.</p></body></html>
HTML HEX Colors
In HTML, a color can be specified using a hexadecimal value in the form: #rrggbb
Where rr (red), gg (green) and bb (blue) are hexadecimal values between 00 and ff (same as decimal 0-255).
For example, #ff0000 is displayed as red, because red is set to its highest value (ff) and the others are set to the lowest value (00).
<h1 style="background-color:#ff0000;">#ff0000</h1>
<h1 style="background-color:#0000ff;">#0000ff</h1>
<h1 style="background-color:#3cb371;">#3cb371</h1>
<h1 style="background-color:#ee82ee;">#ee82ee</h1>
<h1 style="background-color:#ffa500;">#ffa500</h1>
<h1 style="background-color:#6a5acd;">#6a5acd</h1>
<!DOCTYPE html><html><body>
<h1 style="background-color:hsl(0, 100%, 50%);">hsl(0, 100%, 50%)</h1>
<h1 style="background-color:hsl(240, 100%, 50%);">hsl(240, 100%, 50%)</h1>
<h1 style="background-color:hsl(147, 50%, 47%);">hsl(147, 50%, 47%)</h1>
<h1 style="background-color:hsl(300, 76%, 72%);">hsl(300, 76%, 72%)</h1>
<h1 style="background-color:hsl(39, 100%, 50%);">hsl(39, 100%, 50%)</h1>
<h1 style="background-color:hsl(248, 53%, 58%);">hsl(248, 53%, 58%)</h1>
<p>In HTML, you can specify colors using HSL values.</p></body></html>
Saturation
Saturation can be described as the intensity of a color.
<!DOCTYPE html><html><body>
The lightness of a color can be described as how much light you want to give the color, where 0%
means no light (black), 50% means 50% light (neither dark nor light) 100% means full lightness (white).
<!DOCTYPE html><html><body>
<p>With HSL colors, 0% lightness means black, and 100 lightness means white.</p>
</body>
</html>
Shades of gray are often defined by setting the hue and saturation to 0, and adjust the lightness from 0% to 100%
to get darker/lighter shades:
<!DOCTYPE html>
<html>
<body>
<p>With HSL colors, shades of gray are made by setting the saturation to 0%, and adjusting the lightness
according to how dark/light the gray color should be.</p>
</body>
</html>
HSLA Value
HSLA color values are an extension of HSL color values with an alpha channel - which specifies the opacity for a
color.
The alpha parameter is a number between 0.0 (fully transparent) and 1.0 (not transparent at all):
When you move the mouse over a link, the mouse arrow will turn into a little
hand.
A link does not have to be text. It can be an image or any other HTML element.
HTML Links - Syntax
Hyperlinks are defined with the HTML <a> tag:
<!DOCTYPE html><html><body>
<h2>HTML Links</h2>
<p><a href="https://www.xyz.com/html/">Visit our HTML</a></p>
</body></html>
The href attribute specifies the destination address (https://www.xyz.com/html/) of the link.
Clicking on the link text will send you to the specified destination address.
Local Links
The example above used an absolute URL (a full web address).
A local link (link to the same web site) is specified with a relative URL (without https://www....).
<!DOCTYPE html><html><body>
<h2>Local Links</h2>
</body>
</html>
HTML Links - The target Attribute
The target attribute specifies where to open the linked document.
_self - Opens the linked document in the same window/tab as it was clicked (this is default)
_parent - Will open the in the linked document next level up of a frame if they were nested to inside
one another
_top - This breaks outside of all the frames it is nested in and opens the link as top document in the
browser window.
<p>If you set the target attribute to "_blank", the link will open in a new
browser window or tab.</p>
</body>
</html>
HTML Links - Image as Link
<!DOCTYPE html><html><body>
<h2>Image Links</h2>
<p>The image is a link. You can click on it.</p>
<a href="default.asp">
<img src="smiley.gif" alt="HTML visit"
style="width:42px;height:42px;border:0">
</a>
<p>We have added "border:0" to prevent IE9 (and earlier) from displaying a
border around the image.</p>
</body></html>
Link Titles
The title attribute specifies extra information about an element. The information
is most often shown as a tooltip text when the mouse moves over the element.
<!DOCTYPE html><html><body>
<h2>Link Titles</h2>
<p>The title attribute specifies extra information about an element. The
information is most often shown as a tooltip text when the mouse moves over
the element.</p>
<a href="https://www.xyz.com/html/" title="Go to xyz HTML section">Visit our
HTML</a>
</body>
</html>
External Paths
External pages can be referenced with a full URL or with a path relative to the
current web page.
<!DOCTYPE html><html><body>
<h2>External Paths</h2>
<p>This example uses a full URL to link to a web page:</p>
<p><a href="https://www.w3schools.com/html/default.asp">HTML
tutorial</a></p>
</body></html>
This example links to a page located in the html folder on the current web site:
<!DOCTYPE html>
<html>
<body>
<h2>External Paths</h2>
<p>This example links to a page located in the html folder on the current web site:</p>
</body>
</html>
This example links to a page located in the same folder as the current page:
<!DOCTYPE html>
<html>
<body>
<h2>External Paths</h2>
<p>This example links to a page located in the same folder as the current page:</p>
</body>
</html>
In this example, the file path points to a file in the images folder located in the
folder one level above the current folder:
<!DOCTYPE html>
<html>
<body>
</body>
</html>
HTML Link Colors
<!DOCTYPE html><html><head>
<style>
a:link, a:visited {
background-color: #f44336;
color: white;
padding: 15px 25px;
text-align: center;
text-decoration: none;
display: inline-block;
}
a:hover, a:active {
background-color: red;
}
</style></head><body>
<h2>Link Button</h2>
<p>A link styled as a button:</p>
<a href="default.asp" target="_blank">This is a link</a>
</body></html>
HTML Links - Create a Bookmark
HTML bookmarks are used to allow readers to jump to specific parts of a Web page.
To create a bookmark - first create the bookmark, then add a link to it.
When the link is clicked, the page will scroll down or up to the location with the
bookmark.
Example
First, create a bookmark with the id attribute:
<h2 id="C4">Chapter 4</h2>
Then, add a link to the bookmark ("Jump to Chapter 4"), from within the same page:
<!DOCTYPE html><html><body>
<p><a href="#C4">Jump to Chapter 4</a></p><p><a href="#C10">Jump to Chapter
10</a></p>
<h2>Chapter 1</h2>
<p>This chapter explains ba bla bla</p>
<h2>Chapter 2</h2>
<p>This chapter explains ba bla bla</p>
<h2>Chapter 3</h2>
<p>This chapter explains ba bla bla</p>
<h2 id="C4">Chapter 4</h2>
<p>This chapter explains ba bla bla</p>
<h2>Chapter 5</h2>
<p>This chapter explains ba bla bla</p>
<h2>Chapter 6</h2>
<p>This chapter explains ba bla bla</p>
<h2>Chapter 7</h2>
<p>This chapter explains ba bla bla</p>
<h2>Chapter 8</h2>
<p>This chapter explains ba bla bla</p>
<h2>Chapter 9</h2>
<p>This chapter explains ba bla bla</p>
<h2 id="C10">Chapter 10</h2>
<p>This chapter explains ba bla bla</p>
<h2>Chapter 11</h2>
<p>This chapter explains ba bla bla</p>
<h2>Chapter 12</h2>
<p>This chapter explains ba bla bla</p>
<h2>Chapter 13</h2>
<p>This chapter explains ba bla bla</p>
<h2>Chapter 14</h2>
<p>This chapter explains ba bla bla</p>
<h2>Chapter 15</h2>
<p>This chapter explains ba bla bla</p>
<h2>Chapter 16</h2>
<p>This chapter explains ba bla bla</p>
<h2>Chapter 17</h2>
<p>This chapter explains ba bla bla</p>
<h2>Chapter 18</h2>
<p>This chapter explains ba bla bla</p>
<h2>Chapter 19</h2>
<p>This chapter explains ba bla bla</p>
<h2>Chapter 20</h2>
<p>This chapter explains ba bla bla</p>
<h2>Chapter 21</h2>
<p>This chapter explains ba bla bla</p>
<h2>Chapter 22</h2>
<p>This chapter explains ba bla bla</p>
<h2>Chapter 23</h2>
<p>This chapter explains ba bla bla</p>
</body>
</html>
You can also add a link to a bookmark on another page:
<a href="html_demo.html#C4">Jump to Chapter 4</a>
HTML Images
Images can improve the design and the appearance of a web page.
<!DOCTYPE html>
<html>
<body>
<h2>HTML Image</h2>
<img src="pic_trulli.jpg" alt="Trulli" width="500" height="333">
</body>
</html>
HTML Images Syntax
The <img> tag is empty, it contains attributes only, and does not have a closing
tag.
The src attribute specifies the URL (web address) of the image:
<img src="url">
The alt Attribute
The alt attribute provides an alternate text for an image, if the user for some reason
cannot view it (because of slow connection, an error in the src attribute).
If a browser cannot find an image, it will display the value of the alt attribute:
Image Size - Width and Height
You can use the style attribute to specify the width and height of an image.
<!DOCTYPE html><html><body>
<h2>Image Size</h2>
<p>Use the style attribute to specify the width and height of an image:</p>
<img src=“myimg.jpg" alt=“boy in a jacket" style="width:500px;height:600px;">
</body></html>
The width and height attributes always defines the width and height of the image
in pixels.
However, it is common to store images in a sub-folder. You must then include the
folder name in the src attribute:
<!DOCTYPE html><html><body>
<h2>Images in Another Folder</h2>
<p>It is common to store images in a sub-folder. You must then include the folder
name in the src attribute:</p>
<img src="/images/html5.gif" alt="HTML5 Icon" style="width:128px;height:128px;">
</body></html>
Images on Another Server
Some web sites store their images on image servers.
Actually, you can access images from any web address in the world:
<!DOCTYPE html><html><body>
</body></html>
Animated Images
HTML allows animated GIFs:
<!DOCTYPE html><html><body>
</body></html>
<!DOCTYPE html><html><body>
<h2>Image as a Link</h2>
<p>The image is a link. You can click on it.</p>
<a href="default.asp">
<img src="smiley.gif" alt="HTML tutorial"
style="width:42px;height:42px;border:0;">
</a>
<p>Add "border:0;" to prevent IE9 (and earlier) from displaying a border around
the image.</p>
</body></html>
Note: border:0; is added to prevent IE9 (and earlier) from displaying a border
around the image (when the image is a link).
Image Floating
<!DOCTYPE html><html><body>
<h2>Floating Images</h2>
<p>
A paragraph with a floating image. A paragraph with a floating image. A paragraph with a
floating image.</p>
</body></html>
HTML Image Maps
</body></html>
The usemap value starts with a hash tag # followed by the name of the image
map, and is used to create a relationship between the image and the image map.
The <map> element is used to create an image map, and is linked to the image
by using the name attribute:
The name attribute must have the same value as the usemap attribute.
Coordinates
You must define some coordinates to be able to place the clickable area onto the image.
The coordinates come in pairs, one for the x-axis and one for the y-axis.
The coordinates 34, 44 is located 34 pixels from the left margin and 44 pixels from the top:
The coordinates 270, 350 is located 270 pixels from the left margin and 350 pixels from the
top:
To add a circle area, first locate the coordinates of the center of the circle:
337, 300
44 pixels
A clickable area does not have to be a link to another page, it can also trigger a
JavaScript function.
To add a background image on an HTML element, you can use the style attribute:
<h2>Background Image</h2>
</body></html>
You can also specify the background image in the <style> element:
<!DOCTYPE html><html><style>
div {
background-image: url('img_girl.jpg');
}
</style>
<body>
<h2>Background Image</h2>
<div>
You can specify background images<br>
for any visible HTML element.<br>
In this example, the background image<br>
is specified for a div element.<br>
By default, the background-image<br>
will repeat itself in the direction(s)<br>
where it is smaller than the element<br>
where it is specified. (Try resizing the<br>
browser window to see how the<br>
background image behaves.
</div>
If the background image is smaller than the element, the image will repeat itself, horizontally and vertically, until it
has reach the end of the element.
To avoid the background image from repeating itself, use the background-repeat property.
To avoid the background image from repeating itself, use the background-repeat property.
<html>
<style>
body {
background-image: url('example_img_girl.jpg');
background-repeat: no-repeat;
}
</style>
<body><h2>Background No Repeat</h2>
<p>You can avoid the image from being repeated by setting the background-repeat property to "no-repeat".</p>
</body></html>
Background Cover
If you want the background image cover the entire element, you can set the background-size property to cover.
Also, to make sure the entire element is always covered, set the background-attachment property to fixed:
<!DOCTYPE html>
<html>
<style>
body {
background-image: url('img_girl.jpg');
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;
}
</style>
<body>
<h2>Background Cover</h2>
<p>Set the background-size property to "cover" and the background image will cover the entire element, in this case the
BODY element.</p>
</body></html>
Background Stretch
If you want the background image stretch to fit the entire image in the element, you can set the
background-size property to 100% 100%:
<!DOCTYPE html><html>
<style>
body {
background-image: url('img_girl.jpg');
background-repeat: no-repeat;
background-attachment: fixed;
background-size: 100% 100%;
}
</style><body>
<h2>Background Stretch</h2>
<p>Set the background-size property to "100% 100%r" and the background image will be stretched to
cover the entire element, in this case the BODY element.</p>
</body></html>
The HTML <picture> Element
Each <source> element have attributes describing when their image is the
most suitable.
<!DOCTYPE html><html><head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<h2>The picture Element</h2>
<picture>
<source media="(min-width: 650px)" srcset="img_food.jpg">
<source media="(min-width: 465px)" srcset="img_car.jpg">
<img src="img_girl.jpg" style="width:auto;">
</picture>
<p>Resize the browser to see different versions of the picture loading at different viewport sizes.
The browser looks for the first source element where the media query matches the user's current viewport width,and
fetches the image specified in the srcset attribute.</p>
<p>The img element is required as the last child tag of the picture declaration block.The img element is used to provide
backward compatibility for browsers that do not support the picture element, or if none of the source tags matched.
</p>
<p><strong>Note:</strong> The picture element is not supported in IE12 and earlier or Safari 9.0 and earlier.</p>
</body></html>
There are two main purposes for the <picture> element:
1. Bandwidth
If you have a small screen or device, it is not necessary to load a large
image file. The browser will use the first <source> element with
matching attribute values, and ignore any of the following elements.
2. Format Support
Some browsers or devices may not support all image formats. By using
the <picture> element, you can add images of all formats, and the
browser will use the first format it recognizes and ignore any of the
following.
<!DOCTYPE html>
<html><head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head><body>
<h2>The picture Element</h2>
<picture>
<source srcset="img_avatar.png">
<source srcset="img_girl.jpg">
<img src="img_beatles.gif" alt="Beatles" style="width:auto;">
</picture>
<p>The picture element can be used when the image format is not supported by all
devices.</p>
<p>The device will use the first image format it supports, and ignore the rest of the images.</p>
</body></html>
The browser will use the first <source> element with matching attribute values, and ignore any
following <source> elements.
A reference within an html document always begins with an
ampersand(&) and ends with a semicolon(;).The form of the data
between these characters determines the type of reference.
One other html entity reference that is frequently used is &nbps; the
non breaking space character.
<p>
keep together keep together keep together
keep&nbps;together
</p>
Not all characters have entity references associated with them but many do; some examples of entity references are contained
in table 2.1,as shown below:
<p>
Hey, you.&nbps; Yes,&nbps; You are learning to create web pages.
</p>
TABLES:
• Define an HTML Table
• The <table> tag defines an HTML table.
• Each table row is defined with a <tr> tag. Each table header is defined
with a <th> tag. Each table data/cell is defined with a <td> tag.
• By default, the text in <th> elements are bold and centered.
• By default, the text in <td> elements are regular and left-aligned.
FRAMES:
A frame is a rectangular region within a browser window that displays a web page, alongside
other pages in other frames.
Frames are like tables in that they allow you to arrange text and graphics into rows and
columns.
Unlike a table cell, any frame can contain links that change the contents of other frames.
It only tells the browser which other pages to load and how to arrange then in the browser
window.
A frame set document is an HTML page that instructs the web browser to split its window into
multiple frames and specifies which web page should be displayed in each frame.
An example of frameset is given below which divides the browser window into two frames as
rows.
firstpage.html
<html><head><title>top page</title></head>
<body><br/><br/><br/><br/><center><h1>first page</h1>
</body>
</html>
secondpage.html
<html><head><title>top page</title></head>
<body><br/><br/><br/><br/><center><h1>second page</h1>
</body>
</html>
myframe.html
<html><head><title>frame preview</title></head>
<frameset rows=”50%,50%”>
<frame src=”firstpage.html” name=”first”/>
<frame src=”secondpage.html” name=”second”/>
</frameset>
</html>
we can also size the fames using pixels.such a example is shown below.
<html><head><title>frame preview</title></head>
<frameset rows=”150,*,150”>
<frame src=”firstpage.html name=”first”/>
<frame src=”secondpage.html” name=”second”/>
</frameset>
</html>
the example divide the browser window into three rows, first row’s height is of 150 pixels,
third row’s height is also of 150 pixels and the second row’s height is of the rest of the pixels
of browser window size, means second row’s height is [(browser window size in pixels)-
(150+150).
Whenever you specify any frame size in pixels there must also be at least one
frame in the same frameset with the variable(*) width so that the document
can be displayed in a window of n size.
Because you can not predict the size of the window in which someone will view
your web page, it is often convenient to use percentages rather than the exact
pixel values to dictate the size of the rows and the columns.
For example to make a left frame 20% of the width of the browser window with the right
frame taking up the remaining 80% you would type the following:
<frameset cols=”20%,80%”>
To divide the browser window into four parts consider the following example
thirdpage.html
<html><head><title>top page</title></head>
<body><br/><br/><br/><br/><center><h1>third page</h1>
</body>
</html>
<html><head><title>top page</title></head>
<body><br/><br/><br/><br/><center><h1>fourth page</h1>
</body>
</html>
fourframe.html
<html><head><title>frame preview</title></head>
<frameset rows 50%,50% col=”50%,50%”>
<frame src=”firstpage.html name=”first”/>
<frame src=”secondpage.html” name=”second”/>
<frame src=”thirdpage.html name=”third”/>
<frame src=”fourth.html” name=”fourth”/>
</frameset>
</html>
<FRAME /> Tag
Within the <frameset> and </frameset> tags you should have a <frame/> tag indicating
which html document to display in each frame.
Include a src attribute in each <frame> tag with the address of the web page to load in that
frame.
When you give a name to a frame with the name attribute in the <frame/> tag, you can
make any link on the page change the contents of that frame by using the target attribute
in an <a> tag.
For example:
when the user clicks the link “push here” mypage.html is displayed in the frame named
“main” as the target attribute is set to the frame name “main”. If the target=”main” attribute
had not been included in the anchor tag the mypage.html page could have been displayed in
the current frame instead.
Nested frames:
By nesting one <frameset> within an other, you can create rather complex frame layout. For example the document shown in figure 2.9 the
nestframe.html document has a total of 9 frames. A cols frame set is used to split each row of the rows frameset into three pieces.
Figure 2.9
fifthpage.html
<html><head><title>top page</title></head>
<body><br/><br/><br/><br/><center><h1>fourth page</h1>
</body>
</html>
sixthpage.html
<html><head><title>top page</title></head>
<body><br/><br/><br/><br/><center><h1>fourth page</h1>
</body>
</html>
seventhpage.html
<
<html><head><title>top page</title></head>
<body><br/><br/><br/><br/><center><h1>fourth page</h1>
</body>
</html>
eighthpage.html
<html><head><title>top page</title></head>
<body><br/><br/><br/><br/><center><h1>fourth page</h1>
</body>
</html>
ninthpage.html
<html><head><title>top page</title></head>
<body><br/><br/><br/><br/><center><h1>fourth page</h1>
</body>
</html>
nestframe.html
<html><head><title>nesting of frame</title></head>
<frameset rows=”33%,*,33%”>
<frameset cols=”33%,*,33%”>
<frame src=”firstpage.html” name=”first”/>
<frame src=”secondpage.html” name=”second”/>
<frame src=”thirdpage.html” name=”third”/>
</frameset>
<frameset cols=”33%,*,33%”>
<frame src=”fourthpage.html” name=”fourth”/>
<frame src=”fifthpage.html” name=”fifth”/>
<frame src=”sixthpage.html” name=”sixth”/>
</frameset>
<frameset cols=”33%,*,33%”>
<frame src=”seventhpage.html” name=”seventh”/>
<frame src=”eighthpage.html” name=”eighth”/>
<frame src=”ninthpage.html” name=”ninth”/>
</frameset>
</frameset>
</html>
“nestframe.html”
HTML Forms
Forms allow you to receive feedback, orders, or other information from your web page
readers.an html form is a web page that includes areas where readers can enter information
to be sent back to you, the publisher of the web page.
Every form must include a button for the user to submit the form. When someone clicks that
button, all the information he or she has filled in is sent (in a standard format) to an internet
address that you specify in the form itself. You have to put a special forms-processing
program at that address in order for that information to get to you.
CREATING A FORM:
Every form must begin with a <form> tag, which can be located anywhere in the body of the html document.
The form tag normally has two attributes, method and action
<form method=”post” action=”myprocess.jsp”>
The method is almost always post which means to send the form entry results as a document. Another method
is get which submits the results as part of the url header instead.
The action attribute specifies the address to which to send the form data. The form in figure 2.12 includes every
type of input you can currently use on html forms.
<html><head><title> my resume </title></head>
<body bgcolor="pink">
<h1> My details </h1>
<center><b>I want you to know about me</b></center>
<form method=”post” action=”resumeprocess.jsp”>
<input type=hidden name=”mail-to” [email protected]/>
Name <input type=”text” name=”myname” size=”30”/>
Father’s name <input type= ”text” name=”myfather” size=”30”/>
Age <select name=”myage”>
<option selected>0-10</option>
<option>11-20</option><option>21-30</option>
<option>31-40</option></select>
Gender <input type=radio name=”mygen” value=”male”
checked/>male
<input type=radio name=”mygen” value=”female”
/>female
Address <textarea name=”myaddress” rows=”5” cols=”70”></textarea>
Skills <input type=checkbox name=”myc” value="c/c++" checked=”checked”/>C/C++
<input type=checkbox name=”myj2ee” value="j2ee"/ >J2EE
<input type=checkbox name=”mynet” value=".net"/>.NET
Location <select size=”5” name=”mylocation”>
<option selected> new delhi </option>
<option> mumbai </option>
<option> kolkatta </option>
<option> orissa </option>
<option> bhopal </option>
<option> chennai </option>
<option> gujrat </option>
<option> bangalore </option>
</select>
<input type="submit" size="50" value="Click here to submit"/>
<input type=reset size="50" value="Clear"/>
</form>
</body></html>
Text input
To ask the user for a specific piece of information within a form, use the <input/> tag.
This tag must fall between the <form> and </form> tag but can be anywhere on the
page in relation to text, images, and other html tags for example, to ask for someone
names you can type the following :
The type attribute indicates what type of form elements to display a simple one line
text entry box in this case.
The size attribute indicates approximately how many characters wide the text input
box should be.
The maxlength determines the number of characters the user is allowed to ty[pe into
the textbox.
HIDDEN DATA:
When you want to send certain data items to the server that
processes a form but don’t want the user to see that, use
input type=hidden attribute. This attribute has no effect on
the browser display at all. It just adds any name and value you
specify to the form results when they are submitted.
For example the following makes the name value pair mail to,
[email protected]:
<input type=”hidden” name=”mail-to” xyz=
[email protected]/>
CHECK BOX:
The simplest input type is a check box, which appears as a small square the user can
select or deselect by clicking. You must give each check box a name. If you want a check
box to be checked by default when the forms comes up, include the checked attribute.
the one labeled C/C++ would be checked. The one marked J2EE would be unchecked to
begins with, so the user would have to click it to turn it on.
Radio buttons
Radio buttons ,where only one choice can be selected at a time, are almost as simple
to implement as check boxes. Use the same name for all of the radio buttons in a
group:
Gender<input type=radio name=”mysex” value=”male” checked/>male
<input type=radio name=”mysex” value=”female” />female
if you include the checked attribute, that button is selected by default when the form
is displayed on the browser.
Selection Lists
Both scrolling list and pull-down pick lists are created with the
<select> tag. You use this tag together with the<option>tag:
<select name=”extras” size=”3” multiple>
<option selectd>electric window</option>
<option>AM/FM</option>
<option>turbo</option>
<option>J2ME</option> </select>
If size=”3” were used in the preceding code only the first two items would
be visible, and a scrollbar would appear next to the list so the user could
scroll down to see the fourth option.
Including the multiple attribute allows users to select more than one option
at a time, and the selected attribute makes an option selected by default.
If the user selects first two options the result returned by the selection list
are:
Extras=electric window
Extras=AM/FM
Text Area:
When you want to allow multiple lines of text in a single input item, use the
<textarea> and</textarea> tags instead.
any text you include between these two tags is displayed as the default entry. for
example
Address
<textarea name=”myaddress” rows=”5” cols=”70”>my address is:</textarea>
rows and cols attributes control the number of rows and columns of text that fit in the
input box.
Textarea boxes do have a scrollbar, however ,so the user can enter more text than fits
in the display area.
Submit:
Every form must include a button that submits the form data to the server. You can put
any label you like on this button with the value attribute:
CSS describes how HTML elements are to be displayed on screen, paper, or in other media
CSS saves a lot of work.
External stylesheets are stored in CSS files CSS is a language that describes the style of an
HTML document.
CSS is used to define styles for your web pages, including the design, layout and variations
in display for different devices and screen sizes.
<!DOCTYPE html><html><head>
<style>
body {
background-color: lightblue;
}
h1 {
color: white;
text-align: center;
}
p{
font-family: verdana;
font-size: 20px;
}
</style>
</head><body><h1>My First CSS Example</h1><p>This is a paragraph.</p>
</body></html>
CSS Syntax
A CSS rule-set consists of a selector and a declaration
block:
The selector points to the HTML element you want to style.
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
• External styles are defined within the <link> element, inside the
<head> section of an HTML page:
• Mystyle.css
• body {
background-color: lightblue;
}
h1 {
color: navy;
margin-left: 20px;
}
Internal CSS
• An internal style sheet may be used if one single HTML page has a
unique style.
• The internal style is defined inside the <style> element, inside the
head section.
• Internal styles are defined within the <style> element, inside the <head> section of an HTML
page:
• <!DOCTYPE html>
<html>
<head>
<style>
body {
background-color: linen;
}
h1 {
color: maroon;
margin-left: 40px;
}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
Inline CSS
• An inline style may be used to apply a unique style for a single element.
• To use inline styles, add the style attribute to the relevant element. The
style attribute can contain any CSS property.
• Inline styles are defined within the "style" attribute of the relevant
element:
• <!DOCTYPE html>
<html>
<body>
</body>
</html>
Multiple Style Sheets
• If some properties have been defined for the same selector (element)
in different style sheets, the value from the last read style sheet will
be used.
• If some properties have been defined for the same selector (element) in
different style sheets, the value from the last read style sheet will be used.
• Assume that an external style sheet has the following style for the <h1>
element:
• h1 {
color: navy;
}
• Then, assume that an internal style sheet also has the following style for
the <h1> element:
• h1 {
color: orange;
}
Example
• If the internal style is defined after the link to the external style sheet,
the <h1> elements will be "orange":
• <head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
<style>
h1 {
color: orange;
}
</style>
</head>
Example
• However, if the internal style is defined before the link to the external
style sheet, the <h1> elements will be "navy":
• <head>
<style>
h1 {
color: orange;
}
</style>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>
What style will be used when there is more than one style specified for
an HTML element?
• All the styles in a page will "cascade" into a new "virtual" style sheet
by the following rules, where number one has the highest priority:
• Inline style (inside an HTML element)
• External and internal style sheets (in the head section)
• Browser default
So, an inline style has the highest priority, and will override external
and internal styles and browser defaults.
Block-level Elements
• A block-level element always starts on a new line, and the browsers
automatically add some space (a margin) before and after the
element.
• A block-level element always takes up the full width available
(stretches out to the left and right as far as it can).
• Two commonly used block elements are: <p> and <div>.
• The <p> element defines a paragraph in an HTML document.
• The <div> element defines a division or a section in an HTML
document.
• <!DOCTYPE html>
• <html>
• <body>
• <p>The P and the DIV elements are both block elements, and they will
always start on a new line and take up the full width available (stretches
out to the left and right as far as it can).</p>
• </body>
• </html>
• Here are the block-level elements in HTML:
• <address> <article> <aside> <blockquote> <canvas> <dd> <div> <
dl> <dt> <fieldset> <figcaption> <figure> <footer> <form> <
h1>-<h6> <header> <hr> <li> <main> <nav> <noscript> <ol> <p> <
pre> <section> <table> <tfoot> <ul> <video>
Inline Elements
• An inline element does not start on a new line.
• An inline element only takes up as much width as necessary.
• This is a <span> element inside a paragraph.
• <!DOCTYPE html>
• <html>
• <body>
• <p>The SPAN element is an inline element, and will not start on a new
line and only takes up as much width as necessary.</p>
• </body>
• </html>
• Here are the inline elements in HTML:
• <a> <abbr> <acronym> <b> <bdo> <big> <br> <button> <cite> <
code> <dfn> <em> <i> <img> <input> <kbd> <label> <map> <
object> <output> <q> <samp> <script> <select> <small> <span> <
strong> <sub> <sup> <textarea> <time> <tt> <var>
• An inline element cannot contain a block-level element!
The <div> Element
• The <div> element is often used as a container for other HTML
elements.
• The <div> element has no required attributes,
but style, class and id are common.
• When used together with CSS, the <div> element can be used to style
blocks of content:
• !DOCTYPE html>
• <html>
• <body>
• <div style="background-color:black;color:white;padding:20px;">
• <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 of over 13 million inhabitants.</p>
• <p>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.</p>
• </div>
• </body>
• </html>
• The <span> Element
• The <span> element is an inline container used to mark up a part of a
text, or a part of a document.
• The <span> element has no required attributes,
but style, class and id are common.
• When used together with CSS, the <span> element can be used to
style parts of the text:
• <!DOCTYPE html>
• <html>
• <body>
• </body>
• </html>
• The HTML class attribute is used to specify a class for an HTML
element.
• Multiple HTML elements can share the same class.
• Using The class Attribute
• The class attribute is often used to point to a class name in a style
sheet. It can also be used by a JavaScript to access and manipulate
elements with the specific class name.
• In the following example we have three <div> elements with
a class attribute with the value of "city". All of the
three <div> elements will be styled equally according to the .city style
definition in the head section:
• <!DOCTYPE html>
• <html>
• <head>
• <style>
• .city {
• background-color: tomato;
• color: white;
• border: 2px solid black;
• margin: 20px;
• padding: 20px;
• }
• </style>
• </head>
• <body>
• <div class="city">
• <h2>London</h2>
• <p>London is the capital of England.</p>
• </div> </body>
• </html>
HTML id Attribute
• </body>
• </html>
Difference Between Class and ID
A class name can be used by multiple HTML elements, while an
id name must only be used by one HTML element within the
page:
• <!DOCTYPE html>
• <html>
• <head>
• <style>
• /* Style the element with the id "myHeader" */
• #myHeader {
• background-color: lightblue;
• color: black;
• padding: 40px;
• text-align: center;
• }
• <h2 class="city">Paris</h2>
• <p>Paris is the capital of France.</p>
• <h2 class="city">Tokyo</h2>
• <p>Tokyo is the capital of Japan.</p>
• </body>
• </html>