for main headings,
for paragraphs, for links, for paragraphs, for links, HTML Headings HTML Headings <h1> defines the most important heading. <h6> defines the least important heading HTML Paragraphs <p>This is a paragraph.</p> HTML Links HTML Images The source file (src), alternative text (alt), width, and height are provided as HTML Buttons <button>Click me</button> HTML Lists <ul> <br> is an empty element without a closing tag (the <br> tag defines a line break): HTML links are defined with the <a> tag. The link address is specified in <img src="img_girl.jpg"> Images in HTML have a set of size attributes, which specifies the width and height The alt attribute specifies an alternative text to be used, when an image cannot be The value of the attribute can be read by screen readers. This way, someone The style attribute is used to specify the styling of an element, like color, font, size <!DOCTYPE html> ... </body> Here, a title attribute is added to the <p> element. The value of the title attribute Bigger Headings Each HTML heading has a default size. However, you can specify the size for any The <hr> tag defines a thematic break in an HTML page, and is most often displayed The <hr> element is used to separate content (or define a change) in an HTML The <head> element is a container for metadata. HTML metadata is data about the The <head> element is placed between the <html> tag and the <body> tag: <!DOCTYPE html> <head> <body> HTML Paragraphs <p>This is a paragraph.</p> Use <br> if you want a line break (a new line) without starting a new paragraph: The text inside a <pre> element is displayed in a fixed-width font (usually Courier), <pre> Setting the style of an HTML element, can be done with the style attribute. <tagname style="property:value;"> The background-color property defines the background color for an HTML element. <body style="background-color:powderblue;"> <h1>This is a heading</h1> </body> The color property defines the text color for an HTML element: HTML Fonts The font-family property defines the font to be used for an HTML element: The font-size property defines the text size for an HTML element: The text-align property defines the horizontal text alignment for an HTML In the previous chapter, you learned about the HTML style attribute. 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 italictext. The HTML <b> element defines bold text, without any extra importance. The HTML <strong> element defines strong text, with added semantic "strong" The HTML <i> element defines italic text, without any extra importance. The HTML <em> element defines emphasized text, with added semantic importance. The HTML <blockquote> element defines a section that is quoted from another The <address> element is usually displayed in italic. Most browsers will add a line <address> You can add comments to your HTML source by using the following syntax: HTML colors are specified using predefined color names, or RGB, HEX, HSL, RGBA, Color Names Tomato Orange <h1 style="background-color:Tomato;">Tomato</h1> Background Color Example Text Color Border Color Color Values In HTML, colors can also be specified using RGB values, HEX values, HSL values, Example HEX Value Where rr (red), gg (green) and bb (blue) are hexadecimal values between 00 and ff For example, #ff0000 is displayed as red, because red is set to its highest value (ff) <h1 style="background-color:#ff0000;">#ff0000</h1> HSL Value In HTML, a color can be specified using hue, saturation, and lightness (HSL) in the Hue is a degree on the color wheel from 0 to 360. 0 is red, 120 is green, and 240 is Saturation is a percentage value, 0% means a shade of gray, and 100% is the full Saturation 50% is 50% gray, but you can still see the color. Lightness The lightness of a color can be described as how much light you want to give the Shades of gray are often defined by setting the hue and saturation to 0, and adjust RGBA color values are an extension of RGB color values with an alpha channel - The alpha parameter is a number between 0.0 (fully transparent) and 1.0 (not HSLA Value HSLA color values are an extension of HSL color values with an alpha channel - The alpha parameter is a number between 0.0 (fully transparent) and 1.0 (not CSS saves a lot of work. It can control the layout of multiple web pages all at Inline CSS This example sets the text color of the <h1> element to blue: Internal CSS <!DOCTYPE html> <h1>This is a heading</h1> External CSS An external style sheet is used to define the style for many HTML pages. With an external style sheet, you can change the look of an entire web site, To use an external style sheet, add a link to it in the <head> section of the HTML <!DOCTYPE html> <h1>This is a heading</h1> </body> An external style sheet can be written in any text editor. The file must not contain body { CSS Fonts <h1>This is a heading</h1> </body> CSS Border p { CSS Padding The CSS padding property defines a padding (space) between the text and the p { CSS Margin The CSS margin property defines a margin (space) outside the border: The id Attribute To define a specific style for one special element, add an id attribute to the then define a style for the element with the specific id: #p01 { To define a style for special types of elements, add a class attribute to the then define a style for the elements with the specific class: p.error { External References External style sheets can be referenced with a full URL or with a path relative to the <link rel="stylesheet"href="https://www.w3schools.com/html/styles.css"> This example links to a style sheet located in the html folder on the current web This example links to a style sheet located in the same folder as the current page: Links are found in nearly all web pages. Links allow users to click their way from When you move the mouse over a link, the mouse arrow will turn into a little hand. The link text is the visible part (Visit our HTML tutorial). Clicking on the link text will send you to the specified address. Local Links A local link (link to the same web site) is specified with a relative URL (without a:visited { a:hover { a:active { This example will open the linked document in a new browser window/tab: Tip: If your webpage is locked in a frame, you can use target="_top" to break out <a href="default.asp"> Link Titles The title attribute specifies extra information about an element. The information is Example HTML bookmarks are used to allow readers to jump to specific parts of a Web page. To make a bookmark, you must first create the bookmark, and then add a link to it. When the link is clicked, the page will scroll to the location with the bookmark. Example Then, add a link to the bookmark ("Jump to Chapter 4"), from within the same Or, add a link to the bookmark ("Jump to Chapter 4"), from another page: External Paths External pages can be referenced with a full URL or with a path relative to the This example links to a page located in the html folder on the current web site: This example links to a page located in the same folder as the current page: HTML Images Example Example 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 provides an alternate text for an image, if the user for some If a browser cannot find an image, it will display the value of the alt attribute: You can use the style attribute to specify the width and height of an image. However, we suggest using the style attribute. It prevents styles sheets from <!DOCTYPE html> </body> If not specified, the browser expects to find the image in the same folder as the However, it is common to store images in a sub-folder. You must then include the Actually, you can access images from any web address in the world: Animated Images Image as a Link To use an image as a link, put the <img> tag inside the <a> tag: <a href="default.asp"> Image Floating Use the CSS float property to let the image float to the right or to the left of a Image Maps In the image below, click on the computer, the phone, or the cup of coffee: <map name="workmap"> The name attribute of the <map> tag is associated with the <img>'s usemap attribute The <map> element contains a number of <area> tags, that define the clickable areas Background Image To add a background image on a web page, specify the background-image property on the BODY <body style="background-image:url('clouds.jpg');"> <h2>Background Image</h2> </body> Example <body> <p style="background-image:url('clouds.jpg');"> </body> HTML5 introduced the <picture> element to add more flexibility when specifying Each <source> element have attributes describing when their image is the most The browser will use the first <source> element with matching attribute values, and Example Show one picture if the browser window (viewport) is a minimum of 650 pixels, and another image if <picture> HTML Tables td, th { <h2>HTML Table</h2> <table> </body> Each table row is defined with the <tr> tag. A table header is defined with <table style="width:100%"> If you do not specify a border for the table, it will be displayed without borders. table, th, td { If you want the borders to collapse into one border, add the CSS border- table, th, td { Cell padding specifies the space between the cell content and its borders. If you do not specify a padding, the table cells will be displayed without padding. th, td { To set the border spacing for a table, use the CSS border-spacing property: table { To make a cell span more than one column, use the colspan attribute: <!DOCTYPE html> </body> To make a cell span more than one row, use the rowspan attribute: <!DOCTYPE html> <table style="width:100%"> </body> <table style="width:100%"> To define a special style for a special table, add an id attribute to the table: <table id="t01"> <h2>Styling Tables</h2> <table style="width:100%"> <table id="t01"> </body> <!DOCTYPE html> <html> <head> <style> table { width:100%; table, th, td { border-collapse: collapse; th, td { padding: 15px; text-align: left; table#t01 tr:nth-child(even) { background-color: #eee; table#t01 tr:nth-child(odd) { background-color: #fff; table#t01 th { background-color: black; color: white; </style> </head> <body> <h2>Styling Tables</h2> <table> <tr> <th>Firstname</th> <th>Lastname</th> <th>Age</th> </tr> <tr> <td>Jill</td> <td>Smith</td> <td>50</td> </tr> <tr> <td>Eve</td> <td>Jackson</td> <td>94</td> </tr> <tr> <td>John</td> <td>Doe</td> <td>80</td> </tr> </table> <table id="t01"> <tr> <th>Firstname</th> <th>Lastname</th> <th>Age</th> </tr> <tr> <td>Jill</td> <td>Smith</td> <td>50</td> </tr> <tr> <td>Eve</td> <td>Jackson</td> <td>94</td> </tr> <tr> <td>John</td> <td>Doe</td> <td>80</td> </tr> </table> </body> </html> for images,
and
for unordered and ordered lists, and
for line breaks. Styles can be applied using the style attribute or internal CSS to control text formatting, colors, sizes, and other properties."> for main headings, for images,
and
for unordered and ordered lists, and
for line breaks. Styles can be applied using the style attribute or internal CSS to control text formatting, colors, sizes, and other properties.">
Uploaded by
Venice Aira MontañezUploaded by
Venice Aira MontañezHTML Headings
HTML headings are defined with the <h1> to <h6> tags.
<h1>This is heading 1</h1>
<h2>This is heading 2</h2>
<h3>This is heading 3</h3>HTML paragraphs are defined with the <p> tag
<p>This is another paragraph.</p>HTML links are defined with the <a> tag:
<a href="https://www.w3schools.com">This is a link</a>
HTML images are defined with the <img> tag.
attributes.<img src="w3schools.jpg" alt="W3Schools.com" width="104"height="142">
HTML buttons are defined with the <button> tag
HTML lists are defined with the <ul> (unordered/bullet list) or
the <ol>(ordered/numbered list) tag, followed by <li> tags (list items):
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
Empty HTML ElementsHTML elements with no content are called empty elements.
<p>This is a <br> paragraph with a line break.</p>
The href Attribute
the href attribute:<a href="https://www.w3schools.com">This is a link</a>
The src Attribute
HTML images are defined with the <img> tag.
The filename of the image source is specified in the src attribute:
The width and height Attributes
of the image:<img src="img_girl.jpg" width="500" height="600">
The alt Attribute
displayed.
"listening" to the webpage, e.g. a vision impaired person, can "hear" the element.<img src="img_girl.jpg" alt="Girl with a jacket">
The style Attribute
etc.<p style="color:red">I am a paragraph</p>
The lang AttributeThe language of the document can be declared in the <html> tag.
The language is declared with the lang attribute.
Declaring a language is important for accessibility applications (screen readers) and
search engines:
<html lang="en-US">
<body>
</html>The title Attribute
will be displayed as a tooltip when you mouse over the paragraph:<p title="I'm a tooltip">
This is a paragraph.
</p>
heading with the style attribute, using the CSS font-size property<h1 style="font-size:60px;">Heading 1</h1>
HTML Horizontal Rules
as a horizontal rule.
page:<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>
The HTML <head> ElementThe HTML <head> element has nothing to do with HTML headings.
HTML document. Metadata is not displayed.
<html>
<title>My First HTML</title>
<meta charset="UTF-8">
</head>
.
.
.The HTML <p> element defines a paragraph
<p>This is another paragraph.</p>HTML Line Breaks
The HTML <br> element defines a line break.
<p>This is<br>a paragraph<br>with line breaks.</p>
The HTML <pre> Element
The HTML <pre> element defines preformatted text.
and it preserves both spaces and line breaks:
My Bonnie lies over the ocean.
My Bonnie lies over the sea. My Bonnie lies over the ocean.
Oh, bring back my Bonnie to me.
</pre>The HTML Style Attribute
The HTML style attribute has the following syntax:
The property is a CSS property. The value is a CSS value.
TML Background Color
This example sets the background color for a page to powderblue:
<p>This is a paragraph.</p>HTML Text Color
<h1 style="color:blue;">This is a heading</h1>
<p style="color:red;">This is a paragraph.</p><h1 style="font-family:verdana;">This is a heading</h1>
<p style="font-family:courier;">This is a paragraph.</p>HTML Text Size
<h1 style="font-size:300%;">This is a heading</h1>
<p style="font-size:160%;">This is a paragraph.</p>HTML Text Alignment
element:<h1 style="text-align:center;">Centered Heading</h1>
<p style="text-align:center;">Centered paragraph.</p>HTML Formatting Elements
Formatting elements were designed to display special types of text:
<b> - Bold text
<strong> - Important text
<i> - Italic text
<em> - Emphasized text
<mark> - Marked text
<small> - Small text
<del> - Deleted text
<ins> - Inserted text
<sub> - Subscript text
<sup> - Superscript textHTML <b> and <strong> Elements
<b>This text is bold</b>
importance.<strong>This text is strong</strong>
HTML <i> and <em> Elements
<i>This text is italic</i><em>This text is emphasized</em>
HTML <small> Element
The HTML <small> element defines smaller text:
<h2>HTML <small>Small</small> Formatting</h2>
HTML <mark> Element
The HTML <mark> element defines marked or highlighted text:
<h2>HTML <mark>Marked</mark> Formatting</h2>
HTML <del> Element
The HTML <del> element defines deleted (removed) text.
<p>My favorite color is <del>blue</del> red.</p>
HTML <ins> Element
The HTML <ins> element defines inserted (added) text.
<p>My favorite <ins>color</ins> is red.</p>
HTML <sub> Element
The HTML <sub> element defines subscripted text.
<p>This is <sub>subscripted</sub> text.</p>
HTML <sup> Element
The HTML <sup> element defines superscripted
text.<p>This is <sup>superscripted</sup> text.</p>
HTML <q> for Short Quotations
The HTML <q> element defines a short quotation.
Browsers usually insert quotation marks around the <q> element.
<p>WWF's goal is to: <q>Build a future where people live in harmony with
nature.</q></p>HTML <blockquote> for Quotations
source.Browsers usually indent <blockquote> elements.
<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.
The world's leading conservation organization,
WWF works in 100 countries and is supported by
1.2 million members in the United States and
close to 5 million globally.
</blockquote>HTML <abbr> for Abbreviations
The HTML <abbr> element defines an abbreviation or an acronym.
Marking abbreviations can give useful information to browsers, translation systems
and search-engines.<p>The <abbr title="World Health Organization">WHO</abbr> was founded in
1948.</p>HTML <address> for Contact Information
The HTML <address> element defines contact information (author/owner) of a
document or an article.
break before and after the element.
Written by John Doe.<br>
Visit us at:<br>
Example.com<br>
Box 564, Disneyland<br>
USA
</address>HTML <cite> for Work Title
The HTML <cite> element defines the title of a work.
Browsers usually display <cite> elements in italic.<p><cite>The Scream</cite> by Edvard Munch. Painted in 1893.</p>
HTML <bdo> for Bi-Directional Override
The HTML <bdo> element defines bi-directional override.
The <bdo> element is used to override the current text direction:
<bdo dir="rtl">This text will be written from right to left</bdo>
HTML Comment Tags
<!-- Write your comments here -->
HSLA values.In HTML, a color can be specified by using a color name:
DodgerBlue MediumSeaGreen
Gray SlateBlue
Violent LightGray
<body>
<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>You can set the background color for HTML elements:
<h1 style="background-color:DodgerBlue;">Hello World</h1>
<p style="background-color:Tomato;">Lorem ipsum...</p>You can set the color of text:
<h1 style="color:Tomato;">Hello World</h1>
<p style="color:DodgerBlue;">Lorem ipsum...</p>
<p style="color:MediumSeaGreen;">Ut wisi enim...</p>You can set the color of borders:
<h1 style="border:2px solid Tomato;">Hello World</h1>
<h1 style="border:2px solid DodgerBlue;">Hello World</h1>
<h1 style="border:2px solid Violet;">Hello World</h1>
RGBA values, and HSLA values:Same as color name "Tomato":
<h1 style="background-color:rgb(255, 99, 71);">...</h1>
<h1 style="background-color:#ff6347;">...</h1>
<h1 style="background-color:hsl(9, 100%, 64%);">...</h1><h1 style="background-color:rgba(255, 99, 71, 0.5);">...</h1>
<h1 style="background-color:hsla(9, 100%, 64%, 0.5);">...</h1>In HTML, a color can be specified using a hexadecimal value in the form:
#rrggbb
(same as decimal 0-255).
and the others are set to the lowest value (00).
<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>
form:hsl(hue, saturation, lightness)
blue.
color.Lightness is also a percentage, 0% is black, 50% is neither light or dark, 100% is
white<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>Saturation can be described as the intensity of a color.
100% is pure color, no shades of gray0% is completely gray, you can no longer see the color.
<h1 style="background-color:hsl(0, 100%, 50%);">hsl(0, 100%, 50%)</h1>
<h1 style="background-color:hsl(0, 80%, 50%);">hsl(0, 80%, 50%)</h1>
<h1 style="background-color:hsl(0, 60%, 50%);">hsl(0, 60%, 50%)</h1>
<h1 style="background-color:hsl(0, 40%, 50%);">hsl(0, 40%, 50%)</h1>
<h1 style="background-color:hsl(0, 20%, 50%);">hsl(0, 20%, 50%)</h1>
<h1 style="background-color:hsl(0, 0%, 50%);">hsl(0, 0%, 50%)</h1>
color, where 0% means no light (black), 50% means 50% light (neither dark nor
light) 100% means full lightness (white).<h1 style="background-color:hsl(0, 100%, 0%);">hsl(0, 100%, 0%)</h1>
<h1 style="background-color:hsl(0, 100%, 25%);">hsl(0, 100%, 25%)</h1>
<h1 style="background-color:hsl(0, 100%, 50%);">hsl(0, 100%, 50%)</h1>
<h1 style="background-color:hsl(0, 100%, 75%);">hsl(0, 100%, 75%)</h1>
<h1 style="background-color:hsl(0, 100%, 90%);">hsl(0, 100%, 90%)</h1>
<h1 style="background-color:hsl(0, 100%, 100%);">hsl(0, 100%, 100%)</h1>
the lightness from 0% to 100% to get darker/lighter shades:
<h1 style="background-color:hsl(0, 0%, 0%);">hsl(0, 0%, 0%)</h1><h1 style="background-color:hsl(0, 0%, 24%);">hsl(0, 0%, 24%)</h1>
<h1 style="background-color:hsl(0, 0%, 47%);">hsl(0, 0%, 47%)</h1>
<h1 style="background-color:hsl(0, 0%, 71%);">hsl(0, 0%, 71%)</h1>
<h1 style="background-color:hsl(0, 0%, 94%);">hsl(0, 0%, 94%)</h1>
<h1 style="background-color:hsl(0, 0%, 100%);">hsl(0, 0%, 100%)</h1>
RGBA Value
which specifies the opacity for a color.An RGBA color value is specified with:
rgba(red, green, blue, alpha)
transparent at all):<h1 style="background-color:rgba(255, 99, 71, 0);">rgba(255, 99, 71, 0)</h1>
<h1 style="background-color:rgba(255, 99, 71, 0.2);">rgba(255, 99, 71, 0.2)</h1>
<h1 style="background-color:rgba(255, 99, 71, 0.4);">rgba(255, 99, 71, 0.4)</h1>
<h1 style="background-color:rgba(255, 99, 71, 0.6);">rgba(255, 99, 71, 0.6)</h1>
<h1 style="background-color:rgba(255, 99, 71, 0.8);">rgba(255, 99, 71, 0.8)</h1>
<h1 style="background-color:rgba(255, 99, 71, 1);">rgba(255, 99, 71, 1)</h1>
which specifies the opacity for a color.An HSLA color value is specified with:
hsla(hue, saturation, lightness, alpha)
transparent at all):<h1 style="background-color:hsla(9, 100%, 64%, 0);">hsla(9, 100%, 64%, 0)</h1>
<h1 style="background-color:hsla(9, 100%, 64%, 0.2);">hsla(9, 100%, 64%, 0.2)</h1>
<h1 style="background-color:hsla(9, 100%, 64%, 0.4);">hsla(9, 100%, 64%, 0.4)</h1>
<h1 style="background-color:hsla(9, 100%, 64%, 0.6);">hsla(9, 100%, 64%, 0.6)</h1>
<h1 style="background-color:hsla(9, 100%, 64%, 0.8);">hsla(9, 100%, 64%, 0.8)</h1>
<h1 style="background-color:hsla(9, 100%, 64%, 1);">hsla(9, 100%, 64%, 1)</h1>
Styling HTML with CSSCSS stands for Cascading Style Sheets.
CSS describes how HTML elements are to be displayed on screen, paper, or
in other media.
once.CSS can be added to HTML elements in 3 ways:
Inline - by using the style attribute in HTML elements
Internal - by using a <style> element in the <head> section
External - by using an external CSS fileAn inline CSS is used to apply a unique style to a single HTML element.
An inline CSS uses the style attribute of an HTML element.
<h1 style="color:blue;">This is a Blue Heading</h1>
An internal CSS is used to define a style for a single HTML page.
An internal CSS is defined in the <head> section of an HTML page, within
a <style> element:
<html>
<head>
<style>
body {background-color: powderblue;}
h1 {color: blue;}
p {color: red;}
</style>
</head>
<body>
<p>This is a paragraph.</p>
</body>
</html>
by changing one file!
page:
<html>
<head>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<p>This is a paragraph.</p>
</html>
any HTML code, and must be saved with a .css extension.Here is how the "styles.css" looks:
background-color: powderblue;
}
h1 {
color: blue;
}
p {
color: red;
}The CSS color property defines the text color to be used.
The CSS font-family property defines the font to be used.
The CSS font-size property defines the text size to be used.
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
color: blue;
font-family: verdana;
font-size: 300%;
}
p {
color: red;
font-family: courier;
font-size: 160%;
}
</style>
</head>
<body>
<p>This is a paragraph.</p>
</html>The CSS border property defines a border around an HTML element:
border: 1px solid powderblue;
}
border:
border: 1px solid powderblue;
padding: 30px;
}
p {
border: 1px solid powderblue;
margin: 50px;
}
element:<p id="p01">I am different</p>
color: blue;
}The class Attribute
element:<p class="error">I am different</p>
color: red;
}
current web page.This example uses a full URL to link to a style sheet:
site:<link rel="stylesheet" href="/html/styles.css">
<link rel="stylesheet" href="styles.css">
HTML Links
page to page.HTML Links - Hyperlinks
HTML links are hyperlinks.
You can click on a link and jump to another document.
HTML Links - Syntax
In HTML, links are defined with the <a> tag:
<a href="url">link text</a>
<a href="https://www.w3schools.com/html/">Visit our HTML tutorial</a>The href attribute specifies the destination address
(https://www.w3schools.com/html/) of the link.The example above used an absolute URL (a full web address).
https://www....).<a href="html_images.asp">HTML Images</a>
HTML Link Colors
By default, a link will appear like this (in all browsers):
An unvisited link is underlined and blue
A visited link is underlined and purple
An active link is underlined and redYou can change the default colors, by using CSS:
<style>
a:link {
color: green;
background-color: transparent;
text-decoration: none;
}
color: pink;
background-color: transparent;
text-decoration: none;
}
color: red;
background-color: transparent;
text-decoration: underline;
}
color: yellow;
background-color: transparent;
text-decoration: underline;
}
</style>HTML Links - The target Attribute
The target attribute specifies where to open the linked document.
The target attribute can have one of the following values:
_blank - Opens the linked document in a new window or tab
_self - Opens the linked document in the same window/tab as it was clicked
(this is default)
_parent - Opens the linked document in the parent frame
_top - Opens the linked document in the full body of the window
framename - Opens the linked document in a named frame<a href="https://www.w3schools.com/" target="_blank">Visit W3Schools!</a>
of the frame:<a href="https://www.w3schools.com/html/" target="_top">HTML5 tutorial!</a>
HTML Links - Image as LinkIt is common to use images as links:
<img src="smiley.gif" alt="HTML
tutorial"style="width:42px;height:42px;border:0;">
</a>
most often shown as a tooltip text when the mouse moves over the element.
<a href="https://www.w3schools.com/html/" title="Go to W3Schools HTML
section">Visit our HTML Tutorial</a>HTML Links - Create a Bookmark
Bookmarks can be useful if your webpage is very long.
First, create a bookmark with the id attribute:
<h2 id="C4">Chapter 4</h2>
page:<a href="#C4">Jump to Chapter 4</a>
<a href="html_demo.html#C4">Jump to Chapter 4</a>
current web page.
This example uses a full URL to link to a web page:<a href="https://www.w3schools.com/html/default.asp">HTML tutorial</a>
<a href="/html/default.asp">HTML tutorial</a>
<a href="default.asp">HTML tutorial</a>
<img src="pic_trulli.jpg" alt="Italian Trulli">
<img src="img_girl.jpg" alt="Girl in a jacket">HTML Images Syntax
In HTML, images are defined with the <img> tag.
The alt Attribute
reason cannot view it (because of slow connection, an error in the src attribute, or
if the user uses a screen reader).The value of the alt attribute should describe the image:
<img src="img_chania.jpg" alt="Flowers in Chania">
<img src="wrongname.gif" alt="Flowers in Chania">
Image Size - Width and Height
<img src="img_girl.jpg" alt="Girl in a
jacket"style="width:500px;height:600px;">Alternatively, you can use the width and height attributes:
<img src="img_girl.jpg" alt="Girl in a jacket" width="500"height="600">
Width and Height, or Style?
The width, height, and style attributes are valid in HTML5.
changing the size of images:
<html>
<head>
<style>
img {
width: 100%;
}
</style>
</head>
<body><img src="html5.gif" alt="HTML5 Icon" width="128" height="128">
<img src="html5.gif" alt="HTML5 Icon"style="width:128px;height:128px;">
</html>Images in Another Folder
web page.
folder name in the src attribute:<img src="/images/html5.gif" alt="HTML5
Icon"style="width:128px;height:128px;">Images on Another Server
Some web sites store their images on image servers.
<img src="https://www.w3schools.com/images/w3schools_green.jpg"alt="W3Schools
.com">HTML allows animated GIFs:
<img src="programming.gif" alt="Computer Man"style="width:48px;height:48px;">
<img src="smiley.gif" alt="HTML
tutorial"style="width:42px;height:42px;border:0;">
</a>
text:<p><img src="smiley.gif" alt="Smiley
face"style="float:right;width:42px;height:42px;">
The image will float to the right of the text.</p><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>The <map> tag defines an image-map. An image-map is an image with clickable
areas.
<img src="workplace.jpg" alt="Workplace" usemap="#workmap">
<area shape="rect" coords="34,44,270,350" alt="Computer"href="computer.htm"
>
<area shape="rect" coords="290,172,333,250" alt="Phone"href="phone.htm">
<area shape="circle" coords="337,300,44" alt="Coffee"href="coffee.htm">
</map>
and creates a relationship between the image and the map.
in the image-map.To add a background image on an HTML element, use the CSS propertybackground-
image:
element:To add a background image on a paragraph, specify the background-image
property on the P element:
...
</p>The <picture> Element
image resources.
The <picture> element contains a number of <source> elements, each referring to
different image sources. This way the browser can choose the image that best fits
the current view and/or device.
suitable.
ignore any following <source> elements.
not, but larger than 465 pixels.
<source media="(min-width: 650px)"srcset="img_pink_flowers.jpg">
<source media="(min-width: 465px)"srcset="img_white_flower.jpg">
<img src="img_orange_flowers.jpg" alt="Flowers"style="width:auto;">
</picture>
<!DOCTYPE html>
<html>
<head>
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
</style>
</head>
<body>
<tr>
<th>Company</th>
<th>Contact</th>
<th>Country</th>
</tr>
<tr>
<td>Alfreds Futterkiste</td>
<td>Maria Anders</td>
<td>Germany</td>
</tr>
<tr>
<td>Centro comercial Moctezuma</td>
<td>Francisco Chang</td>
<td>Mexico</td>
</tr>
<tr>
<td>Ernst Handel</td>
<td>Roland Mendel</td>
<td>Austria</td>
</tr>
<tr>
<td>Island Trading</td>
<td>Helen Bennett</td>
<td>UK</td>
</tr>
<tr>
<td>Laughing Bacchus Winecellars</td>
<td>Yoshi Tannamuri</td>
<td>Canada</td>
</tr>
<tr>
<td>Magazzini Alimentari Riuniti</td>
<td>Giovanni Rovelli</td>
<td>Italy</td>
</tr>
</table>
</html>Defining an HTML Table
An HTML table is defined with the <table> tag.
the <th> tag. By default, table headings are bold and centered. A table data/cell is
defined with the <td> tag
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
</table>HTML Table - Adding a Border
A border is set using the CSS border property:
border: 1px solid black;
}HTML Table - Collapsed Borders
collapse property:
border: 1px solid black;
border-collapse: collapse;
}HTML Table - Adding Cell Padding
To set the padding, use the CSS padding property:
padding: 15px;
}HTML Table - Left-align Headings
By default, table headings are bold and centered.
To left-align the table headings, use the CSS text-align property:
th {
text-align: left;
}HTML Table - Adding Border Spacing
Border spacing specifies the space between the cells.
border-spacing: 5px;
}HTML Table - Cells that Span Many Columns
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 5px;
text-align: left;
}
</style>
</head>
<body><h2>Cell that spans two columns</h2>
<p>To make a cell span more than one column, use the colspan attribute.</p>
<table style="width:100%">
<tr>
<th>Name</th>
<th colspan="2">Telephone</th>
</tr>
<tr>
<td>Bill Gates</td>
<td>55577854</td>
<td>55577855</td>
</tr>
</table>
</html>HTML Table - Cells that Span Many Rows
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 5px;
text-align: left;
}
</style>
</head>
<body><h2>Cell that spans two rows</h2>
<p>To make a cell span more than one row, use the rowspan attribute.</p>
<tr>
<th>Name:</th>
<td>Bill Gates</td>
</tr>
<tr>
<th rowspan="2">Telephone:</th>
<td>55577854</td>
</tr>
<tr>
<td>55577855</td>
</tr>
</table>
</html>HTML Table - Adding a Caption
To add a caption to a table, use the <caption> tag:
<caption>Monthly savings</caption>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$50</td>
</tr>
</table>A Special Style for One Table
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
</table>
Example
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 15px;
text-align: left;
}
table#t01 {
width: 100%;
background-color: #f1f1c1;
}
</style>
</head>
<body>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td>
</tr>
</table>
<br>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td>
</tr>
</table>
</html>
Now you can define a special style for this table:
table#t01 {
width: 100%;
background-color: #f1f1c1;
}
Add more style border: 1px solid black;
}
<br>You might also like