Pages

Monday, 9 November 2020

HTML NOTES

HTML Headings

HTML headings are defined with the <h1> to <h6> tags.

<h1> defines the most important heading. <h6> defines the least important heading: 

Example

<h1>This is heading 1</h1>

<h2>This is heading 2</h2>

<h3>This is heading 3</h3> 

Note: Use HTML headings for headings only. Don't use headings to make text BIG or bold.

HTML Paragraphs

HTML paragraphs are defined with the <p> tag:

Example

<p>This is a paragraph.</p>

<p>This is another paragraph.</p> 

HTML Links

HTML links are defined with the <a> tag:

Example

<a href="http://www.google.com">This is a link</a> 

The link's destination is specified in the href attribute. 

Attributes are used to provide additional information about HTML elements.


HTML Images

HTML images are defined with the <img> tag.

The source file (src), alternative text (alt), and size (width and height) are provided as attributes:

Example

<img src=”raju.jpg"  width="104" height="142"> 


HTML Elements

An HTML element usually consists of a start tag and end tag, with the content inserted in between:

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

The HTML element is everything from the start tag to the end tag:

<p>My first paragraph.</p> 

Start tag Element content End tag

<h1> My First Heading </h1>

<p> My first paragraph. </p>

<br>

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:

Example

<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> Element

The HTML <head> element has nothing to do with HTML headings.

The <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:

Example

<!DOCTYPE html>

<html>


<head>

  <title>My First HTML</title>

  <meta charset="UTF-8">

</head>


<body>

 .....

 </body>

 </html>

Note: Metadata typically define the document title, character set, styles, links, scripts, and other meta information.


HTML Tip - How to View HTML Source

Have you ever seen a Web page and wondered "Hey! How did they do that?"

To find out, right-click in the page and select "View Page Source" (in Chrome) or "View Source" (in IE), or similar in another browser. This will open a window containing the HTML code of the page.

      

HTML Tag Reference

W3Schools' tag reference contains additional information about these tags and their attributes.

You will learn more about HTML tags and attributes in the next chapters of this tutorial.

Tag Description

<html>

Defines the root of an HTML document

<body>

Defines the document's body

<head>

A container for all the head elements (title, scripts, styles, meta information, and more)

<h1> to <h6>

Defines HTML headings

<hr>

Defines a thematic change in the content


HTML Paragraphs

The HTML <p> element defines a paragraph:

Example

<p>This is a paragraph.</p>

<p>This is another paragraph.</p> 

Note: Browsers automatically add some white space (a margin) before and after a paragraph.


HTML Display

You cannot be sure how HTML will be displayed.

Large or small screens, and resized windows will create different results. 

With HTML, you cannot change the output by adding extra spaces or extra lines in your HTML code.

The browser will remove any extra spaces and extra lines when the page is displayed:

Example

<p>

This paragraph

contains a lot of lines

in the source code,

but the browser 

ignores it.

</p>

<p>

This paragraph

contains         a lot of spaces

in the source         code,

but the        browser 

ignores it.

</p>


Don't Forget the End Tag

Most browsers will display HTML correctly even if you forget the end tag:

Example

<p>This is a paragraph.

<p>This is another paragraph.

The example above will work in most browsers, but do not rely on it.

Note: 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:

Example

<p>This is<br>a paragraph<br>with line breaks.</p>

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


The Poem Problem

This poem will display as one line:

Example

<p>

  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.

</p>

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:

Example

<pre>

  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>

HTML Tag Reference

Tag Description

<p>

Defines a paragraph

<br>

Inserts a single line break

<pre>

Defines pre-formatted text

The HTML Style Attribute

Setting the style of an HTML element, can be done with the style attribute.

The HTML style attribute has the following syntax:

<tagname style="property:value;"> 

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


HTML Background Color

The background-color property defines the background color for an HTML element.

This example sets the background color for a page to powderblue:

Example

<body style="background-color:powderblue;">

<h1>This is a heading</h1>

<p>This is a paragraph.</p>

</body>


HTML Text Color

The color property defines the text color for an HTML element:

Example

<h1 style="color:blue;">This is a heading</h1>

<p style="color:red;">This is a paragraph.</p>


HTML Fonts

The font-family property defines the font to be used for an HTML element:

Example

<h1 style="font-family:verdana;">This is a heading</h1>

<p style="font-family:courier;">This is a paragraph.</p>


HTML Text Size

The font-size property defines the text size for an HTML element:

Example

<h1 style="font-size:300%;">This is a heading</h1>

<p style="font-size:160%;">This is a paragraph.</p>


HTML Text Alignment

The text-align property defines the horizontal text alignment for an HTML element:

Example

<h1 style="text-align:center;">Centered Heading</h1>

<p style="text-align:center;">Centered paragraph.</p>

HTML Formatting Elements

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 italic text.

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 text

________________________________________

HTML <b> and <strong> Elements

The HTML <b> element defines bold text, without any extra importance.

Example

<b>This text is bold</b>

The HTML <strong> element defines strong text, with added semantic "strong" importance.

Example

<strong>This text is strong</strong>

________________________________________

HTML <i> and <em> Elements

The HTML <i> element defines italic text, without any extra importance.

Example

<i>This text is italic</i>

The HTML <em> element defines emphasized text, with added semantic importance.

Example

<em>This text is emphasized</em>

Note: Browsers display <strong> as <b>, and <em> as <i>. However, there is a difference in the meaning of these tags: <b> and <i> defines bold and italic text, but <strong> and <em> means that the text is "important".

________________________________________

HTML <small> Element

The HTML <small> element defines smaller text:

Example

<h2>HTML <small>Small</small> Formatting</h2>

________________________________________

HTML <mark> Element

The HTML <mark> element defines marked or highlighted text:

Example

<h2>HTML <mark>Marked</mark> Formatting</h2>

________________________________________

HTML <del> Element

The HTML <del> element defines deleted (removed) text.

Example

<p>My favorite color is <del>blue</del> red.</p>

________________________________________

HTML <ins> Element

The HTML <ins> element defines inserted (added) text.

Example

<p>My favorite <ins>color</ins> is red.</p>

________________________________________

HTML <sub> Element

The HTML <sub> element defines subscripted text.

Example

<p>This is <sub>subscripted</sub> text.</p>

________________________________________

HTML <sup> Element

The HTML <sup> element defines superscripted text.

Example

<p>This is <sup>superscripted</sup> text.</p>

________________________________________

Test Yourself with Exercises!

            

________________________________________

Color Names

In HTML, a color can be specified by using a color name:

Example

Color

Name

 

Red

 

Orange

 

Yellow

 

Cyan

 

Blue

HTML supports 140 standard color names.

________________________________________

RGB Value

In HTML, a color can also be specified as an RGB value, using this formula: rgb(red, green, blue)

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 the color black, all color parameters must be set to 0, like this: rgb(0,0,0).

To display the color white, all color parameters must be set to 255, like this: rgb(255,255,255). 

Red

Green

Blue

255

0

0

Experiment by mixing the RGB values below:

Red      Green   Blue

255     0            0

rgb(255, 0, 0)

Example

Color

RGB

 

rgb(255,0,0)

 

rgb(255,255,0)

 

rgb(0,255,0)

 

rgb(0,255,255)

 

rgb(0,0,255)

Shades of gray are often defined using equal values for all the 3 light sources:

Example

Color

RGB

 

rgb(0,0,0)

 

rgb(90,90,90)

 

rgb(128,128,128)

 

rgb(200,200,200)

 

rgb(255,255,255)


HEX Value

In HTML, a color can also 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).

Example


Color

HEX

 

#FF0000

 

#FFFF00

 

#00FF00

 

#00FFFF

 

#0000FF

Shades of gray are often defined using equal values for all the 3 light sources:

Example

Color

HEX

 

#000000

 

#404040

 

#808080

 

#CCCCCC

 

#FFFFFF

HTML Links - Colors

When you move the mouse over a link, two things will normally happen:

The mouse arrow will turn into a little hand

The color of the link element will change

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 red

You can change the default colors, by using styles:

Example

<style>

a:link    {color:green; background-color:transparent; text-decoration:none}

a:visited {color:pink; background-color:transparent; text-decoration:none}

a:hover   {color:red; background-color:transparent; text-decoration:underline}

a:active  {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

This example will open the linked document in a new browser window/tab:

Example

<a href="http://www.w3schools.com/" target="_blank">Visit W3Schools!</a> 

Tip: If your webpage is locked in a frame, you can use target="_top" to break out of the frame:

Example

<a href="http://www.w3schools.com/html/" target="_top">HTML5 tutorial!</a> 

________________________________________

HTML Links - Image as Link

It is common to use images as links:

Example

<a href="default.asp">

  <img src="smiley.gif" alt="HTML tutorial" style="width:42px;height:42px;border:0;">

</a> 

Note: border:0; is added to prevent IE9 (and earlier) from displaying a border around the image (when the image is a link).

________________________________________

HTML Links - Create a Bookmark

HTML bookmarks are used to allow readers to jump to specific parts of a Web page.

Bookmarks can be useful if your webpage is very long.

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

First, create a bookmark with the id attribute:

<h2 id="tips">Useful Tips Section</h2>

Then, add a link to the bookmark ("Useful Tips Section"), from within the same page:

<a href="#tips">Visit the Useful Tips Section</a> 

Or, add a link to the bookmark ("Useful Tips Section"), from another page:

Example

<a href="html_tips.html#tips">Visit the Useful Tips Section</a> 

________________________________________

Chapter Summary

Use the <a> element to define a link

Use the href attribute to define the link address

Use the target attribute to define where to open the linked document

Use the <img> element (inside <a>) to use an image as a link

Use the id attribute (id="value") to define bookmarks in a page

Use the href attribute (href="#value") to link to the bookmark

HTML Images Syntax

In HTML, images are defined with the <img> tag.

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" alt="some_text" style="width:width;height:height;"> 

________________________________________

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, or if the user uses a screen reader).

If a browser cannot find an image, it will display the value of the alt attribute:

Example

<img src="wrongname.gif" alt="HTML5 Icon" style="width:128px;height:128px;"> 

The alt attribute is required. A web page will not validate correctly without it. 

________________________________________

HTML Screen Readers

A screen reader is a software program that reads the HTML code, converts the text, and allows the user to "listen" to the content. Screen readers are useful for people who are blind, visually impaired, or learning disabled.

________________________________________

Image Size - Width and Height

You can use the style attribute to specify the width and height of an image.

The values are specified in pixels (use px after the value):

Example

<img src="html5.gif" alt="HTML5 Icon" style="width:128px;height:128px;"> 

Alternatively, you can use the width and height attributes. Here, the values are specified in pixels by default:

Example

<img src="html5.gif" alt="HTML5 Icon" width="128" height="128"> 

Note: Always specify the width and height of an image. If width and height are not specified, the page will flicker while the image loads.

________________________________________

Width and Height, or Style?

Both the width, height, and style attributes are valid in HTML5.

However, we suggest using the style attribute. It prevents internal or external styles sheets from changing the original size of images:

Example

<!DOCTYPE html>

<html>

<head>

<style>

img { 

    width:100%; 

}

</style>

</head>

<body>


<img src="html5.gif" alt="HTML5 Icon" style="width:128px;height:128px;">

<img src="html5.gif" alt="HTML5 Icon" width="128" height="128">


</body>

</html>

________________________________________

Images in Another Folder

If not specified, the browser expects to find the image in the same folder as the web page.

However, it is common to store images in a sub-folder. You must then include the folder name in the src attribute:

Example

<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.

Actually, you can access images from any web address in the world:

Example

<img src="http://www.w3schools.com/images/w3schools_green.jpg" alt="W3Schools.com"> 

________________________________________

Animated Images

The GIF standard allows animated images:

Example

<img src="programming.gif" alt="Computer Man" style="width:48px;height:48px;"> 

Note that the syntax of inserting animated images is no different from non-animated images.

________________________________________

Using an Image as a Link

 To use an image as a link, simply nest the <img> tag inside the <a> tag:

Example

<a href="default.asp">

  <img src="smiley.gif" alt="HTML tutorial" style="width:42px;height:42px;border:0;">

</a> 

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

Use the CSS float property to let the image float to the right or to the left of a text:

Example

<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>

________________________________________

Image Maps

Use the <map> tag to define an image-map. An image-map is an image with clickable areas.

The name attribute of the <map> tag is associated with the <img>'s usemap attribute and creates a relationship between the image and the map.

The <map> tag contains a number of <area> tags, that defines the clickable areas in the image-map:

Example

<img src="planets.gif" alt="Planets" usemap="#planetmap" style="width:145px;height:126px;">


<map name="planetmap">

  <area shape="rect" coords="0,0,82,126" alt="Sun" href="sun.htm">

  <area shape="circle" coords="90,58,3" alt="Mercury" href="mercur.htm">

  <area shape="circle" coords="124,58,8" alt="Venus" href="venus.htm">

</map>

________________________________________

Chapter Summary

Use the HTML <img> element to define an image

Use the HTML src attribute to define the URL of the image

Use the HTML alt attribute to define an alternate text for an image, if it cannot be displayed

Use the HTML width and height attributes to define the size of the image

Use the CSS width and height properties to define the size of the image (alternatively)

Use the CSS float property to let the image float

Use the HTML <map> element to define an image-map

Use the HTML <area> element to define the clickable areas in the image-map

Use the HTML <img>'s element usemap attribute to point to an image-map


Defining an HTML Table

An HTML table is defined with the <table> tag.

Each table row is defined with the <tr> tag. A table header is defined with the <th> tag. By default, table headings are bold and centered. A table data/cell is defined with the <td> tag.

Example

<table style="width:100%">

  <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> 

Note: The <td> elements are the data containers of the table.

They can contain all sorts of HTML elements; text, images, lists, other tables, etc.

________________________________________

HTML Table - Adding a Border

If you do not specify a border for the table, it will be displayed without borders.

A border is set using the CSS border property:

Example

table, th, td {

    border: 1px solid black;

}

Remember to define borders for both the table and the table cells.

________________________________________

HTML Table - Collapsed Borders

If you want the borders to collapse into one border, add the CSS border-collapse property:

Example

table, th, td {

    border: 1px solid black;

    border-collapse: collapse;

}

________________________________________

HTML Table - Adding Cell Padding

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.

To set the padding, use the CSS padding property:

Example

th, td {

    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:

Example

th {

    text-align: left;

________________________________________

HTML Table - Adding Border Spacing

Border spacing specifies the space between the cells.

To set the border spacing for a table, use the CSS border-spacing property:

Example

table {

    border-spacing: 5px;

}

Note: If the table has collapsed borders, border-spacing has no effect.

________________________________________

HTML Table - Cells that Span Many Columns

To make a cell span more than one column, use the colspan attribute:

Example

<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 Table - Cells that Span Many Rows

To make a cell span more than one row, use the rowspan attribute:

Example

<table style="width:100%">

  <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 Table - Adding a Caption

To add a caption to a table, use the <caption> tag:

Example

<table style="width:100%">

  <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>

Note: The <caption> tag must be inserted immediately after the <table> tag.

________________________________________

A Special Style for One Table

To define a special style for a special table, add an id attribute to the table:

Example

<table id="t01">

  <tr>

    <th>Firstname</th>

    <th>Lastname</th> 

    <th>Age</th>

  </tr>

  <tr>

    <td>Eve</td>

    <td>Jackson</td> 

    <td>94</td>

  </tr>

</table> 

Now you can define a special style for this table:

table#t01 {

    width: 100%; 

    background-color: #f1f1c1;

And add more styles:

table#t01 tr:nth-child(even) {

    background-color: #eee;

}

table#t01 tr:nth-child(odd) {

    background-color: #fff;

}

table#t01 th {

    color: white;

    background-color: black;

________________________________________

Chapter Summary

Use the HTML <table> element to define a table

Use the HTML <tr> element to define a table row

Use the HTML <td> element to define a table data

Use the HTML <th> element to define a table heading

Use the HTML <caption> element to define a table caption

Use the CSS border property to define a border

Use the CSS border-collapse property to collapse cell borders

Use the CSS padding property to add padding to cells

Use the CSS text-align property to align cell text

Use the CSS border-spacing property to set the spacing between cells

Use the colspan attribute to make a cell span many columns

Use the rowspan attribute to make a cell span many rows

Use the id attribute to uniquely define one table

________________________________________

Test Yourself with Exercises!

          

________________________________________

HTML Table Tags

Tag Description

<table>

Defines a table

<th>

Defines a header cell in a table

<tr>

Defines a row in a table

<td>

Defines a cell in a table

<caption>

Defines a table caption

<colgroup>

Specifies a group of one or more columns in a table for formatting

<col>

Specifies column properties for each column within a <colgroup> element

<thead>

Groups the header content in a table

<tbody>

Groups the body content in a table

<tfoot>

Groups the footer content in a table /td> 

HTML Lists

« Previous

Next Chapter »

 HTML List Example

An Unordered List:

Item

Item

Item

Item

An Ordered List:

1. First item

2. Second item

3. Third item

4. Fourth item


________________________________________

Unordered HTML List

An unordered list starts with the <ul> tag. Each list item starts with the <li> tag.

The list items will be marked with bullets (small black circles) by default:

Example

<ul>

  <li>Coffee</li>

  <li>Tea</li>

  <li>Milk</li>

</ul> 

________________________________________

Unordered HTML List - Choose List Item Marker

The CSS list-style-type property is used to define the style of the list item marker:

Value Description

disc Sets the list item marker to a bullet (default)

circle Sets the list item marker to a circle

square Sets the list item marker to a square

none The list items will not be marked

Example - Disc

<ul style="list-style-type:disc">

  <li>Coffee</li>

  <li>Tea</li>

  <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 style="list-style-type:square">

  <li>Coffee</li>

  <li>Tea</li>

  <li>Milk</li>

</ul> 

Example - None

<ul style="list-style-type:none">

  <li>Coffee</li>

  <li>Tea</li>

  <li>Milk</li>

</ul> 

________________________________________

Ordered HTML List

An ordered list starts with the <ol> tag. Each list item starts with the <li> tag.

The list items will be marked with numbers by default:

Example

<ol>

  <li>Coffee</li>

  <li>Tea</li>

  <li>Milk</li>

</ol> 

________________________________________

Ordered HTML List - The Type Attribute

The type attribute of the <ol> tag, defines the type of the list item marker:

Type Description

type="1" The list items will be numbered with numbers (default)

type="A" The list items will be numbered with uppercase letters

type="a" The list items will be numbered with lowercase letters

type="I" The list items will be numbered with uppercase roman numbers

type="i" The list items will be numbered with lowercase roman numbers

Numbers:

<ol type="1">

  <li>Coffee</li>

  <li>Tea</li>

  <li>Milk</li>

</ol> 

Uppercase Letters:

<ol type="A">

  <li>Coffee</li>

  <li>Tea</li>

  <li>Milk</li>

</ol> 

Lowercase Letters:

<ol type="a">

  <li>Coffee</li>

  <li>Tea</li>

  <li>Milk</li>

</ol> 

Uppercase Roman Numbers:

<ol type="I">

  <li>Coffee</li>

  <li>Tea</li>

  <li>Milk</li>

</ol> 

Lowercase Roman Numbers:

<ol type="i">

  <li>Coffee</li>

  <li>Tea</li>

  <li>Milk</li>

</ol> 

________________________________________

HTML Description Lists

HTML also supports description lists.

A description list is a list of terms, with a description of each term.

The <dl> tag defines the description list, the <dt> tag defines the term (name), and the <dd> tag describes each term: 

Example

<dl>

  <dt>Coffee</dt>

  <dd>- black hot drink</dd>

  <dt>Milk</dt>

  <dd>- white cold drink</dd>

</dl> 

________________________________________

Nested HTML Lists

List can be nested (lists inside lists):

Example

<ul>

  <li>Coffee</li>

  <li>Tea

    <ul>

      <li>Black tea</li>

      <li>Green tea</li>

    </ul>

  </li>

  <li>Milk</li>

</ul> 

Note: List items can contain new list, and other HTML elements, like images and links, etc.

________________________________________

Horizontal Lists

HTML lists can be styled in many different ways with CSS.

One popular way is to style a list horizontally, to create a menu:

Example

<!DOCTYPE html>

<html>

<head>

<style>

ul {

    list-style-type: none;

    margin: 0;

    padding: 0;

    overflow: hidden;

    background-color: #333333;

}


li {

    float: left;

}


li a {

    display: block;

    color: white;

    text-align: center;

    padding: 16px;

    text-decoration: none;

}


li a:hover {

    background-color: #111111;

}

</style>

</head>

<body>


<ul>

  <li><a class="active" href="#home">Home</a></li>

  <li><a href="#news">News</a></li>

  <li><a href="#contact">Contact</a></li>

  <li><a href="#about">About</a></li>

</ul>


</body>

</html> 

________________________________________

Chapter Summary

Use the HTML <ul> element to define an unordered list

Use the CSS list-style-type property to define the list item marker

Use the HTML <ol> element to define an ordered list

Use the HTML type attribute to define the numbering type

Use the HTML <li> element to define a list item

Use the HTML <dl> element to define a description list

Use the HTML <dt> element to define the description term

Use the HTML <dd> element to define the description data 

Lists can be nested inside lists

List items can contain other HTML elements 

Use the CSS property float:left or display:inline to display a list horizontally

________________________________________

Test Yourself with Exercises!

     

HTML List Tags

Tag Description

<ul>

Defines an unordered list

<ol>

Defines an ordered list

<li>

Defines a list item

<dl>

Defines a description list

<dt>

Defines the term in a description list

<dd>

Defines the description in a description list


No comments:

Post a Comment

Different Types of CSS

There are three ways of adding CSS style rules to HTML elements:        1. Inline — using the style attribute in HTML element 2. Internal — ...